コードビハインドごとに添付プロパティのDataBindingを追加
-
03-07-2019 - |
質問
添付プロパティの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);
他のヒント
はい、キャンバスにはleftプロパティがありません。 Canvas ContentのFrameworkItemの添付プロパティです。
<Canvas Width="100" Height="100">
<TextBox Name="top" Canvas.Left="12"></TextBox>
</Canvas>
所属していません StackOverflow