【问题标题】:DependencyProperty.UnsetValue and DataContextChanged eventDependencyProperty.UnsetValue 和 DataContextChanged 事件
【发布时间】:2023-03-14 18:14:01
【问题描述】:

我想知道 DependencyProperty.UnsetValue 在 DataContext 属性上设置时是否会触发 DataContextChanged 事件?

MSDN 对此的说法有点令人困惑:

指定 WPF 属性系统使用的静态值,而不是 null 以指示属性存在,但属性系统没有设置其值。

“没有设置它的值”所以在 DataContext 上设置时,DataContextChanged 事件不会触发,对吧?

我希望我现在能以某种方式进行测试,但我正在打电话。

提前谢谢大家,如果重复,请告诉我,以便我在您投反对票之前删除该帖子:)

【问题讨论】:

    标签: wpf dependency-properties


    【解决方案1】:

    DataContext 显式设置为DependencyProperty.UnsetValue 会触发DataContextChanged 事件。 DependancyObject.SetValue 在设置 DependancyProperty 值时运行检查和逻辑次数,当我们尝试将 DataContext 设置为 DependencyProperty.UnsetValue 时,它会将其设置为 null 并引发事件。

    【讨论】:

    • yup.. 也检查了 DependancyObject 的实现,如果要设置的值是 DependencyProperty.UnsetValue,它会设置默认值为 null
    • 哦,谢谢。是否有反映 .net 代码的新工具?我只知道一个来自红门。但它的昂贵。 :) :) :)
    • 是的,我曾经在我的许可证到期之前使用它.. :) 现在我依赖 JetBrains “dotpeek”
    • 太棒了,我不知道。已经很兴奋地去看看了。谢谢尼特
    猜你喜欢
    • 1970-01-01
    • 2013-10-02
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多