당신은 바인딩을보고 당신이 객체 CMIconText에 정적으로 값을 전달하는 개체에 연결된 종속성 속성을 사용할 수 있습니다. OneWay Y 인딩을 사용하면 더 잘 작동하지만 양방향 Y 인딩을 수행 할 수 있습니다.
public class TextBoxExtension
{
public static readonly DependencyProperty AttachedTextProperty;
static TextBoxExtension()
{
AttachedTextProperty = DependencyProperty.RegisterAttached("AttachedText", typeof (string), typeof (TextBoxExtension), new PropertyMetadata(default(string), TextAttachedChanged));
}
public static string GetAttachedText(TextBox sender)
{
return (string) sender.GetValue(AttachedTextProperty);
}
public static void SetAttachedText(TextBox sender, string value)
{
sender.SetValue(AttachedTextProperty, value);
}
private static void TextAttachedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
((TextBox) sender).Text = e.NewValue as string;
}
}
이것은 당신이 XAML에서 그렇게 할 수 있습니다 :이 전체 클래스를 재 구현보다 훨씬 간단
<TextBox Grid.Row="0" Grid.Column="1" controls:TextBoxExtension.AttachedText="{Binding Name}" />
. 물론 TextBox
의 참조를 자신의 개체로 변경해야합니다. 그러나 나는 그것을 가지지 않았기 때문에 당신에게 모범을 줄 수있는 가장 가까운 곳이었습니다.