在 Silverlight 中绑定到relativesource self
我试图将滑块控件的值绑定到同一控件中的属性:
<Slider
Value="{Binding Path=ValueProperty, RelativeSource={RelativeSource Self}}"
Name="slider1" />
但它不绑定到“ValuePropery”... 我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定相同的控件是什么意思。
如果您正在创建用户控件并且它包含您定义的名为 ValueProperty 的属性(即在控件后面的代码中),您可以尝试以下代码:
此解决方案要求您在用户控件中拥有根控件名为
LayoutRoot
(这是默认值)。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:
This solution requires you to have your root control in your user control to be named
LayoutRoot
(it's the default).据我了解,您正在尝试将 Slider Value 属性绑定到自身,如果是这种情况,那么您错误地确定了绑定路径,更改了您的 XAML,如下所示:
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:
如果您指的是当前页面的属性,请检查此讨论:
WP7 绑定到局部变量
如果您指的是滑块的属性,那么您可以使用 TemplateBinding:
希望这会对您有所帮助。
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:
Hope this will help you.