• 【wpf】Bingding的方向和触发的时机


    1. <TextBox Text="{Binding DM1.Value,UpdateSourceTrigger=PropertyChanged,
    2. Mode=TwoWay}" Name="textBox"/>
    3. <TextBox Text="{Binding DM1.Value,Mode=OneWay}" Name="tb2"/>
    4. <TextBox Text="{Binding DM1.Value,UpdateSourceTrigger=PropertyChanged,
    5. Mode=OneWayToSource}" />
    6. <TextBox Text="{Binding DM1.Value,
    7. Mode=OneTime}"/>

    Mode

    首先源是指后台数据,目标指,前台显示。

    TwoWay:"双向奔赴"。

    OneWay 后台数据 -> 前台显示,

    OneWayToSource 与OneWay 相反。

    OneTime 就只有初始化的时候起作用了。

    UpdateSourceTrigger

    UpdateSourceTrigger ,表示当前台数据(目标)发送变化时,更新源(后台数据)的时机。(注意:UpdateSourceTrigger 关心的方向是:前台显示->后台数据,所以当Mode为OneWay时,设置这个属性是没有意义的

    1. //
    2. // 摘要:
    3. // Describes the timing of binding source updates.
    4. public enum UpdateSourceTrigger
    5. {
    6. //
    7. // 摘要:
    8. // The default System.Windows.Data.UpdateSourceTrigger value of the binding target
    9. // property. The default value for most dependency properties is System.Windows.Data.UpdateSourceTrigger.PropertyChanged,
    10. // while the System.Windows.Controls.TextBox.Text property has a default value of
    11. // System.Windows.Data.UpdateSourceTrigger.LostFocus.
    12. Default = 0,
    13. //
    14. // 摘要:
    15. // Updates the binding source immediately whenever the binding target property changes.
    16. PropertyChanged = 1,
    17. //
    18. // 摘要:
    19. // Updates the binding source whenever the binding target element loses focus.
    20. LostFocus = 2,
    21. //
    22. // 摘要:
    23. // Updates the binding source only when you call the System.Windows.Data.BindingExpression.UpdateSource
    24. // method.
    25. Explicit = 3
    26. }

    PropertyChanged 

    表示,只要前台发送变化,立马通知源(也就是调用属性的set方法)

    LostFocus 

    表示控件失去焦点时触发。

    Explicit 

    通过绑定表达式调用UpdateSource调用后触发。

    1. //获取绑定表达式
    2. BindingExpression bindingExpression = textBox.GetBindingExpression(TextBox.TextProperty);
    3. //调用后触发
    4. bindingExpression.UpdateSource();

  • 相关阅读:
    Docker启动SpringBoot简单例子
    [数据结构初阶]一文轻松学链表
    设计模式Java实战
    JAVA【设计模式】模板模式
    python 网络编程和http协议--网络编程,HTTP协议,Web服务器
    力扣 -- 1745. 分割回文串 IV
    文件输入和输入出处理(六)-序列化和反序列化
    如何做系统架构设计
    深入理解 Swift 新并发模型中 Actor 的重入(Reentrancy)问题
    win10虚机扩容C盘
  • 原文地址:https://blog.csdn.net/songhuangong123/article/details/126223899