希望来自新手的一个简单的入门问题......
我有一个 TextBox,其 Text 属性绑定到 ViewModel 和 DependencyProperty。
当我单击文本框时,我希望为第二个文本框(“编辑器”文本框)分配与第一个相同的绑定。结果是编辑第二个“编辑器”文本框将更新第一个。
最终,我希望能够单击任何文本框并在同一个“编辑器”文本框中进行编辑。
我使用选项 2 的解决方案...谢谢!!:
private void m_sourceTextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
TextBox sourceTextBox = sender as TextBox;
if (null != sourceTextBox)
{
BindingExpression sourceBindExpression = sourceTextBox.GetBindingExpression(TextBox.TextProperty);
if (sourceBindExpression != null && sourceBindExpression.ParentBinding != null && sourceBindExpression.ParentBinding.Path != null)
m_editorTextBox.SetBinding(TextBox.TextProperty, sourceBindExpression.ParentBinding);
}
}