[英]Add DataBinding for attached Property per Code Behind
我想为每个Codebehind添加一个DataBinding作为附加属性,并希望在TextBox中显示Canvas.Left
属性。 如何添加此属性?
您的问题尚不清楚,但我想您是在问如何将其绑定到附加属性Canvas.Left
并将其显示在TextBox中。 我假设您希望将其用于TextBox之外的其他控件。
<Canvas>
<TextBox x:Name="textBox" Text="{Binding ElementName=button, Path=(Canvas.Left)}" />
<Button x:Name="button" Content="Press me" />
</Canvas>
请注意附加属性周围的括号。
编辑:要执行等效的代码,请使用以下命令:
Binding binding = new Binding();
binding.Source = button;
binding.Path = new PropertyPath(Canvas.LeftProperty);
textBox.SetBinding(TextBlock.TextProperty, binding);
是的,画布没有左属性。 它是Canvas内容中FrameworkItem的附加属性。
<Canvas Width="100" Height="100">
<TextBox Name="top" Canvas.Left="12"></TextBox>
</Canvas>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.