Dra*_*ake 8 .net c# wpf custom-controls
我在WPF中创建一个数字TextBox ,有两个按钮来增加和减少值.
我创建了两个RoutedCommand来管理behia,它们运行良好.我只想解决一个问题.我希望控件在执行增加或减少命令时通知绑定到其TextProperty的所有对象.
目前,只有当我将焦点更改为另一个控件时,它才会发送通知
非常感谢任何帮助,谢谢
小智 29
有一个简单的方法:
Text="{Binding Path=MyProperty, UpdateSourceTrigger=PropertyChanged}"
Run Code Online (Sandbox Code Playgroud)
(我在TextBox上测试过它).祝好运
vik*_*iky 12
使用UpdateSourceTrigger="Explicit"在绑定和TextChanged事件更新BindingSource.所以你写的是这样的:
<NumericTextBox x:Name="control" Text={Binding Path=MyProperty}/>
Run Code Online (Sandbox Code Playgroud)
而是这样做
<NumericTextBox x:Name="control" Text={Binding Path=MyProperty, UpdateSourceTrigger=Explicit}/>
Run Code Online (Sandbox Code Playgroud)
并在TextChanged事件处理程序中更新绑定.
control.GetBindingExpression(NumericTextBox.TextProperty).UpdateSource();
Run Code Online (Sandbox Code Playgroud)
那就完成了.希望能帮助到你!!