Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding to a RelativeSource Self in Silverlight

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?

like image 721
Boris Avatar asked Jan 23 '23 05:01

Boris


2 Answers

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).

like image 56
Lukasz M Avatar answered Jan 24 '23 18:01

Lukasz M


As I understand you are trying to bind Slider Value property to itself, if that is the case then you inccorectly determining Path of Binding change your XAML as follow:

<Slider Value="{Binding Path=Value, RelativeSource={RelativeSource Self}}"
        Name="slider1"  />
like image 20
Xusan Avatar answered Jan 24 '23 20:01

Xusan