当前位置:网站首页>【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();
边栏推荐
猜你喜欢
随机推荐
从2022投影行业最新报告,读懂2022年家用智能投影仪该怎么选!
openGauss社区七月运作报告
The difference between rv and sv
在启牛学堂股票开户安全吗?
2 prerequisites for the success of "digital transformation" of enterprises!
JVM内存模型和结构详解(五大模型图解)
【目标检测】YOLOv5:标签中文显示/自定义颜色
The new version of squirrel as source change operation
dp, dpi, px knowledge supplement
socket concept
TCP协议详解
医疗机构漏诊,该不该赔?--一起交通事故多处骨折,又遇到医疗机构漏诊
比较器是否可以当做运放使用?
开源一夏 | 疫情期间闲来无事,我自制了一个按钮展示框特效来展示我的博客
智文最终版本
手机ETF基金开户哪家证券公司好?哪个更安全
Vscode LeetCode 教程
CF696C(计数推公式+欧拉降幂)
咸阳广发证券股票开户安全吗,需要准备什么证件
How big is 1dp!









