c# - "UpdateSourceTrigger=PropertyChanged"相当于 Windows Phone 7 文本框

标签 c# silverlight windows-phone-7

有没有办法让 Windows Phone 7 中的 TextBox 在用户键入每个字母时而不是在失去焦点后更新绑定(bind)?

就像下面的 WPF TextBox 一样:

<TextBox Text="{Binding Path=TextProperty, UpdateSourceTrigger=PropertyChanged}"/>

最佳答案

Silverlight for WP7 不支持您列出的语法。请改为执行以下操作:

<TextBox TextChanged="OnTextBoxTextChanged"
         Text="{Binding MyText, Mode=TwoWay,
                UpdateSourceTrigger=Explicit}" />

UpdateSourceTrigger = Explicit is a smart bonus here. What is it? Explicit: Updates the binding source only when you call the UpdateSource method. It saves you one extra binding set when the user leaves the TextBox.

在 C# 中:

private void OnTextBoxTextChanged( object sender, TextChangedEventArgs e )
{
  TextBox textBox = sender as TextBox;
  // Update the binding source
  BindingExpression bindingExpr = textBox.GetBindingExpression( TextBox.TextProperty );
  bindingExpr.UpdateSource();
}

关于c# - "UpdateSourceTrigger=PropertyChanged"相当于 Windows Phone 7 文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4833100/

相关文章:

c# - If/Else OR "? :"(条件)不工作

silverlight - Silverlight 中的 Google map

c# - 使用 MVVM 模式时如何处理 MessageBox 对话框(MVVM Light ToolKit)

c# - 动态磁贴更新

c# - WP7无法加载关卡数据

c# - 调整图像大小以适合边界框

c# - 进程 WaitForExit 不等待

c# - 网络连接仅在设备通过电缆连接时有效

c# - Ranorex 测试自动化问题 : Unable to reliably click a button on silverlight web app

javascript - HTML 会被任何新技术取代吗?