Question

I have property defined in MainWindow "ZoomSlider" , that is databound to Slider.

On a UserControl I have a Ellipse such that its height is bounded to Slider value.

MainWindow Code

<Slider 
   Grid.Column="4"  
   Value="{Binding ElementName=MainWindow,Path=ZoomSlider,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}"
   Maximum="46" 
   Minimum=".1" 
   LargeChange=".1" 
   Ticks="0,1,5" 
   TickPlacement="BottomRight" 
   SmallChange=".1" 
   Height="22"  
   Width="75" 
   Margin="0" 
   HorizontalAlignment="Right" 
   VerticalAlignment="Bottom">
</Slider>

<!--Content Control is the Host of a userControl which iam Setting dynamically at runtime-->

<ContentControl Name="content" BorderThickness="1"  

Content="{Binding CurrentViewModel,Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}">     

</ContentControl>

UserControl Code

<Ellipse  Stroke="Black">
   <Ellipse.Height>
      <MultiBinding Converter="{StaticResource zoomConverter}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnSourceUpdated="True">

           <Binding Path="Dia" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnSourceUpdated="True"/>

           <Binding RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type Window}}" Path="ZoomSlider" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" 
         NotifyOnSourceUpdated="True" PresentationTraceSources.TraceLevel="High"/>

      </MultiBinding> 

MainWindow c# code

private double zoomSlider = 2;

public double ZoomSlider
{
    get { return zoomSlider; }
    set
    {
        zoomSlider = value;
        NotifyPropertyChanged("ZoomSlider");
    }
}

I successfully getting the default slider value in the UserControl, but when Slider's value property is changed its is not getting reflected in the UserControl.

So,bottom line how to get the updated slider value to UserControl Ellipse

Note:

UserControl is bound to a UserControl Viewmodel and so is MainWindow to Window ViewModel

Any help is appreciated!!!!

Was it helpful?

Solution

ZoomSlider should have a DependencyProperty as a backing field to enable binding

public double ZoomSlider
{
   get { return (double)GetValue(ZoomSliderProperty); }
   set { SetValue(ZoomSliderProperty, value); }
}

// Using a DependencyProperty as the backing store for ZoomSlider.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty ZoomSliderProperty =
            DependencyProperty.Register("ZoomSlider", typeof(double), typeof(MainWindow), new PropertyMetadata(2d));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top