How to add a binding to a xaml binding within a behavior?

208 views Asked by At

I have a behavior with a xaml interface of:

<i:Interaction.Behaviors>
      <b:ChartCanvasItemBehavior
               Source="{Binding MovieUri}"                                    
              Timeline="{Binding Path=Timeline, ElementName=ChartCanvasRightPanel, Mode=OneWayToSource}" 
                                                             
       />
</i:Interaction.Behaviors>

The behavior creates an adorner that does:

public double Timeline
        {
            get { return (double)GetValue(TimelineProperty); }
            set { SetValue(TimelineProperty, value); }
        }

    // Using a DependencyProperty as the backing store for Timeline.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TimelineProperty =
        DependencyProperty.Register("Timeline", typeof(double), typeof(MovieControlForChartCanvas), new UIPropertyMetadata(0.0));

To link the two in the behavior, I have:

var bindingMovieTime = new Binding
            {
                Source = mc,                                         
                Path = new PropertyPath(MovieControlForChartCanvas.TimelineProperty) 
            };
            BindingOperations.SetBinding(this, iTimelineProperty, bindingMovieTime);


#region [Dependency Properties used to bind to the MovieControlForChartCanvas]
        // These dependecy properties have to be DIFFERENT then the dependency properties used for the ChartCanvasItemBehavior xaml interface. 
        // Using the same dependecy property for both bindings to the MovieControl and the Xaml interface results in losing one of the first bindings (i.e., the xaml binding).
        public double iTimeline
        {
            get { return (double)GetValue(iTimelineProperty); }
            set { SetValue(iTimelineProperty, value); }
        }

        // Using a DependencyProperty as the backing store for iTimeline.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty iTimelineProperty =
            DependencyProperty.Register("iTimeline", typeof(double), typeof(ChartCanvasItemBehavior), new PropertyMetadata(0.0,
                (s, e) =>
                {
                    ChartCanvasItemBehavior d = s as ChartCanvasItemBehavior;
                    d.Timeline = (double)e.NewValue;
                }
                ));



        #endregion


        public double Timeline
        {
            get { return (double)GetValue(TimelineProperty); }
            set { SetValue(TimelineProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Timeline.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TimelineProperty =
            DependencyProperty.Register("Timeline", typeof(double), typeof(ChartCanvasItemBehavior  ), new PropertyMetadata(0.0));

This seems to require a second property between the behavior and the adorner. If I use one property for both the behavior interface and the behavior-to-adorner interface, the first assignment to that behavior, i.e, from the xaml, gets overwritten by the binding to the adorner.

Can this be done using only one dependency property in the behavior with multibinding? If so, how?

To rephrase, is it possible to use one dependency property in the behavior to serve as an interface in both the xaml and to the adorner? (multibinding?)

Thanks for any suggestions.

0

There are 0 answers