Binding to a RelativeSource Self in Silverlight

Boris picture Boris · Apr 21, 2010 · Viewed 9.4k times · Source

I am trying to bind a value of a slider control to a property that is in the same control:

 <Slider 
        Value="{Binding Path=ValueProperty, RelativeSource={RelativeSource Self}}"
        Name="slider1"  />

but it doesn't bind to a "ValuePropery"... What am I doing wrong?

Answer

Lukasz M picture Lukasz M · Feb 20, 2012

I'm not sure what you mean by the same control. If you are creating your user control and it contains a property named ValueProperty that you've defined (i.e. in code behind of the control), you can try the code:

<Slider 
    Value="{Binding ElementName=LayoutRoot Path=Parent.ValueProperty}"
    Name="slider1"  />

This solution requires you to have your root control in your user control to be named LayoutRoot (it's the default).