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 "ValuePrope开发者_开发知识库ry"... What am I doing wrong?
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).
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" />
If you mean a property of the current page then check this discussion: WP7 Binding to Local Variable
If you mean a property of the Slider then you can use TemplateBinding:
<Slider Value="{TemplateBinding ValueProperty}" Name="slider1" />
Hope this will help you.
精彩评论