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

  • 相关阅读:
    ResourceBundleViewResolver类简介说明
    嵌入式养成计划-49----ARM--计算机相关理论--ARM相关内容
    【数据仓库-零】数据仓库知识体系 ing
    QT:MainWIndow的使用
    鲲鹏920(ARM64)移植javacpp续
    借助 Aspose.Words,在 C# 中将 Word 转换为 JPG
    网络安全(黑客)自学
    linux之管道符详解
    js---es5和es6实现面对对象继承
    猴子也能学会的jQuery第十二期——jQuery遍历(上)
  • 原文地址:https://blog.csdn.net/songhuangong123/article/details/126223899