【WPF系列】-TextBox常用知识点
2024-10-15 23:41:30
DataBinding中更新数据源的时机
TextBox .Text 属性的默认 UpdateSourceTrigger 值为 LostFocus。这意味着如果应用程序的 TextBox 包含数据绑定 TextBox.Text 属性,则直到 TextBox 失去焦点(例如,将鼠标移到TextBox 外单击时),键入到 TextBox 中的文本才能更新源。
如果希望在键入过程中更新源,请将该绑定的 UpdateSourceTrigger 设置为 PropertyChanged。 在下面的示例中,TextBox 和 TextBlock 的 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>
最新文章
- 从分布式一致性谈到CAP理论、BASE理论
- Android.mk相关知识
- CPU的高速缓存存储器知识整理
- 20145215《Java程序设计》第3周学习总结
- 剑指Offer:面试题11——数值的整数次方(java实现)
- Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~
- Android开发之点击两次Back键退出App
- [Mime] MimeReader--读取Mime的帮助类 (转载)
- C# DateTime
- FLEX中Tree默认展开全部节点
- JAVA GUI学习 - JInternalFrame浮动窗口:可拖拽窗口(依赖于父窗口)
- jquery on()动态绑定元素的的点击事件无反应的问题记录
- HashMap? ConcurrentHashMap? 相信看完这篇没人能难住你!
- Linux命令收集
- 电子产品使用感受之——为什么我那么喜欢2015年的11.6寸MacBook Air?
- java中==和equals的区别(转)
- vue 用huilder打包APP时,安卓按返回键就退出App改为按两次再退出App
- 归并排序(递归排序and外排排序)
- Python 学习 第六篇:迭代和解析
- k8s相关端口表-以及周边工具
热门文章
- CocosStudio文件解析工具CsdAnalysis
- CClayer ignoreAnchorPointForPosition 参数的作用
- ASP.NET MVC 之自定义HtmlHelper
- [Access] C# 通过 COM 组件访问 Access 文件
- ";System.Security.Cryptography.CryptographicException: 拒绝访问"; 问题的解决方法
- php中的登陆login
- C#模拟Http请求时出现 基础连接已经关闭 未能为 SSLTLS 安全通道建立信任关系
- Java 批量插入数据(Oracle)
- JDK源码分析:hashCode()方法
- Netty(一)引题