当前位置:网站首页>【wpf】Bingding的方向和触发的时机
【wpf】Bingding的方向和触发的时机
2022-08-08 17:52:00 【code bean】
<!--两个方向都可行-->
<TextBox Text="{Binding DM1.Value,UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay}" Name="textBox"/>
<!--只允许从源到目标-->
<TextBox Text="{Binding DM1.Value,Mode=OneWay}" Name="tb2"/>
<!--史允许从目标到源-->
<TextBox Text="{Binding DM1.Value,UpdateSourceTrigger=PropertyChanged,
Mode=OneWayToSource}" />
<!--只允许初始化一次-->
<TextBox Text="{Binding DM1.Value,
Mode=OneTime}"/>
Mode
首先源是指后台数据,目标指,前台显示。
TwoWay:"双向奔赴"。
OneWay 后台数据 -> 前台显示,
OneWayToSource 与OneWay 相反。
OneTime 就只有初始化的时候起作用了。
UpdateSourceTrigger
UpdateSourceTrigger ,表示当前台数据(目标)发送变化时,更新源(后台数据)的时机。(注意:UpdateSourceTrigger 关心的方向是:前台显示->后台数据,所以当Mode为OneWay时,设置这个属性是没有意义的)
//
// 摘要:
// Describes the timing of binding source updates.
public enum UpdateSourceTrigger
{
//
// 摘要:
// The default System.Windows.Data.UpdateSourceTrigger value of the binding target
// property. The default value for most dependency properties is System.Windows.Data.UpdateSourceTrigger.PropertyChanged,
// while the System.Windows.Controls.TextBox.Text property has a default value of
// System.Windows.Data.UpdateSourceTrigger.LostFocus.
Default = 0,
//
// 摘要:
// Updates the binding source immediately whenever the binding target property changes.
PropertyChanged = 1,
//
// 摘要:
// Updates the binding source whenever the binding target element loses focus.
LostFocus = 2,
//
// 摘要:
// Updates the binding source only when you call the System.Windows.Data.BindingExpression.UpdateSource
// method.
Explicit = 3
}
PropertyChanged
表示,只要前台发送变化,立马通知源(也就是调用属性的set方法)
LostFocus
表示控件失去焦点时触发。
Explicit
通过绑定表达式调用UpdateSource调用后触发。
//获取绑定表达式
BindingExpression bindingExpression = textBox.GetBindingExpression(TextBox.TextProperty);
//调用后触发
bindingExpression.UpdateSource();
边栏推荐
猜你喜欢
随机推荐
套接字的概念
数据库分析与优化
在启牛学堂股票开户安全吗?
what‘s the meaning of build-essential
CF696C(计数推公式+欧拉降幂)
Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素用于缩短包封周期
右上角按钮圆形扩散导航菜单js特效
what‘s the meaning of xenial
博客主页rrs代码
【NodeJs篇】fs文件系统模块
【Promise.allSettled】手写Promise.allSettled方法
js切换新闻列表样式
高维前缀和和子集dp(状压dp的一种)
基于simulink的风力机房温度控制系统仿真
无需精子卵子子宫体外培育胚胎,Cell论文作者这番话让网友们炸了
poj1363 Rails(栈模拟)
CS231n:11 生成模型
CS231n: 11 Generative Models
一甲子,正青春,CCF创建六十周年庆典在苏州举行
文件传输-FTP使用简介