DataBinding中更新数据源的时机

 

TextBox .Text 属性的默认 UpdateSourceTrigger 值为 LostFocus。这意味着如果应用程序的 TextBox 包含数据绑定 TextBox.Text 属性,则直到 TextBox 失去焦点(例如,将鼠标移到TextBox 外单击时),键入到 TextBox 中的文本才能更新源。

 

如果希望在键入过程中更新源,请将该绑定的 UpdateSourceTrigger 设置为 PropertyChanged。 在下面的示例中,TextBoxTextBlock 的 Text 属性都绑定到同一源属性。 将 TextBox绑定的 UpdateSourceTrigger 属性设置为 PropertyChanged

<Label>Enter a Name:</Label>
<TextBox>
<TextBox.Text>
<Binding Source="{StaticResource myDataSource}" Path="Name"
UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
</TextBox> <Label>The name you entered:</Label>
<TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=Name}"/>

源自:如何:控制文本框文本更新源的时间

 

 

 

高级实例:

通过dataTriger来给TextBox焦点

Using XAML to Set Focus on a Textbox in WPF Desktop Applications

<Style x:Key="LayoutRoot" TargetType="Grid">
<Style.Triggers>
<!--these are the triggers that make the code cursor jump from box 1 to box 2 to box 3.-->
<DataTrigger Binding="{Binding ElementName=CodeDigit1, Path=Text.Length}" Value="1">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=CodeDigit2}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=CodeDigit2, Path=Text.Length}" Value="1">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=CodeDigit3}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=CodeDigit3, Path=Text.Length}" Value="1">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=CodeDigit4}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=CodeDigit4, Path=Text.Length}" Value="1">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=ConnectButton}"/>
</DataTrigger>
</Style.Triggers>
</Style>

最新文章

  1. 从分布式一致性谈到CAP理论、BASE理论
  2. Android.mk相关知识
  3. CPU的高速缓存存储器知识整理
  4. 20145215《Java程序设计》第3周学习总结
  5. 剑指Offer:面试题11——数值的整数次方(java实现)
  6. Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~
  7. Android开发之点击两次Back键退出App
  8. [Mime] MimeReader--读取Mime的帮助类 (转载)
  9. C# DateTime
  10. FLEX中Tree默认展开全部节点
  11. JAVA GUI学习 - JInternalFrame浮动窗口:可拖拽窗口(依赖于父窗口)
  12. jquery on()动态绑定元素的的点击事件无反应的问题记录
  13. HashMap? ConcurrentHashMap? 相信看完这篇没人能难住你!
  14. Linux命令收集
  15. 电子产品使用感受之——为什么我那么喜欢2015年的11.6寸MacBook Air?
  16. java中==和equals的区别(转)
  17. vue 用huilder打包APP时,安卓按返回键就退出App改为按两次再退出App
  18. 归并排序(递归排序and外排排序)
  19. Python 学习 第六篇:迭代和解析
  20. k8s相关端口表-以及周边工具

热门文章

  1. CocosStudio文件解析工具CsdAnalysis
  2. CClayer ignoreAnchorPointForPosition 参数的作用
  3. ASP.NET MVC 之自定义HtmlHelper
  4. [Access] C# 通过 COM 组件访问 Access 文件
  5. &quot;System.Security.Cryptography.CryptographicException: 拒绝访问&quot; 问题的解决方法
  6. php中的登陆login
  7. C#模拟Http请求时出现 基础连接已经关闭 未能为 SSLTLS 安全通道建立信任关系
  8. Java 批量插入数据(Oracle)
  9. JDK源码分析:hashCode()方法
  10. Netty(一)引题