我有一个包含 DependencyProperty (MyProperty) 的 WPF UserControl。
DependencyProperty 绑定(bind)到 DataContext 中的属性。
现在我想在 UserControl 中更改绑定(bind)属性的值。但是,如果我分配 MyProperty = NewValue
,则 Binding 会丢失并被 NewValue 取代。
我想要实现的是更改 DependencyProperty 绑定(bind)到的 DataContext 属性。
我如何实现这一点而不是更改绑定(bind)?
澄清一下:使用类似 MyTextBox.Text = "0";
的东西,我将释放绑定(bind)。我将如何设置 Text,保持绑定(bind)不变,以便 Text 绑定(bind)到的属性也会发生变化。
最佳答案
您可以使用 SetCurrentValue .
The SetCurrentValue method changes the effective value of the property, but existing triggers, data bindings, and styles will continue to work.
关于c# - 改变绑定(bind)值,而不是绑定(bind)自己,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2921926/