• 【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();

  • 相关阅读:
    怎么给自己的网站主页配置SSL证书?
    浅谈React中的ref和useRef
    如何公网远程访问本地群晖NAS File Station文件夹
    布客深度学习译文集 2024.2 更新
    【AD9361】设置带宽
    死磕GMSSL通信-java/Netty系列(三)
    数据结构 专项练习
    图解 LeetCode 算法汇总——二分查找
    短视频脚本如何创作?了解构成部分很关键,按顺序做不会错
    @Autowired和@Resource注解的区别和联系
  • 原文地址:https://blog.csdn.net/songhuangong123/article/details/126223899