Linking to RelativeSource Self in Silverlight

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

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

but it's not tied to "ValuePropery" ... What am I doing wrong?

+4
source share
3 answers

I'm not sure what you mean by the same control. If you create your own custom control and contain a property called ValueProperty that you defined (i.e., in the code behind the control), you can try the code:

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

This solution requires that your root control in your user element be named LayoutRoot (it is the default).

+4
source

As I understand it, you are trying to bind the Slider Value property to yourself, if so, then you, in turn, define the Path of Binding, change your XAML as follows:

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

If you mean the property of the current page, then check out this discussion: WP7 binding to a local variable

If you mean the Slider property, you can use TemplateBinding:

 <Slider Value="{TemplateBinding ValueProperty}" Name="slider1" /> 

Hope this helps you.

+1
source

Source: https://habr.com/ru/post/1307522/


All Articles