Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有文本框的 wpf 窗口和视图模型中名为 Val 的属性
<Textbox Binding={Path=Val, Mode=TwoWay, NotifyOnSourceUpdated=true, NotifyOnTargetUpdated=true}>
问题是 val 仅在控件失去焦点时才更新,而不是针对我输入的每个字符。
任何人都知道如何为文本框中的每个输入更新 Val?
只需使用以下
<Textbox Binding={Path=Val, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}>
TextBox的默认UpdateSourceTrigger值为LostFocus. 如果您将其设置为PropertyChanged,它将在您更改的每个 Char 上触发。
UpdateSourceTrigger
LostFocus
PropertyChanged