Per*_*ine 2 data-binding wpf mvvm windows-store-apps
有没有办法在每次击键后更新文本绑定?
我的WPF自定义TextBox使用KeyUp事件
private void MyTextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
BindingExpression BE = GetBindingExpression(TextBox.TextProperty);
if (BE != null)
BE.UpdateSource();
}
Run Code Online (Sandbox Code Playgroud)
但BindingExpression在Windows 8/RT/Store中不存在.
我知道这个问题有点老了,但我今天遇到了这个问题并找到了一个非常简单的解决方案.也许它有助于某人:
<TextBox Text="{Binding BindingSource, UpdateSourceTrigger=PropertyChanged}"/>
Run Code Online (Sandbox Code Playgroud)
将UpdateSourceTrigger-Property设置为"PropertyChanged"时,每次文本更改时都会调用UpdateSource()方法(即使焦点没有丢失).
| 归档时间: |
|
| 查看次数: |
2054 次 |
| 最近记录: |