什么元素可以阻止 WPF 依赖属性的继承?

huangapple go评论73阅读模式
英文:

What elements can block WPF dependency property inheritance?

问题

我的WPF应用程序将一个自定义继承的依赖属性(来自行为)附加到我的主应用程序视图上。想法是将这个属性(一旦应用程序运行,就不会改变)传递到一些非常嵌套的需要它的控件中。

<Window x:Class="MyApp.Views.MainWindow"
        core:SystemBehavior.SystemService="{Binding MySystem}"

它运行得很好。到目前为止,我的所有控件都能访问这个数据。

<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource Self}, 
                                Path=(core:SystemBehavior.SystemService).Units}"

但在MS关于属性值继承的文档中有这样一个令我犹豫的警句。

但是,只要可继承属性被注册为附加属性,并且没有遇到故意阻止继承的边界(如框架),属性值继承就可以弥补逻辑树中的这个差距,仍然可以传递继承的值。

(强调部分由我添加)

所以我的问题是:除了框架之外,还有哪些元素可以“阻止”依赖属性继承?

英文:

My WPF App attaches a custom inherited dependency property (from a behavior) to my main application view. The idea is to pass this property (which never changes once the app is running) all the way down to some very nested controls that need it

&lt;Window x:Class=&quot;MyApp.Views.MainWindow&quot;
        core:SystemBehavior.SystemService=&quot;{Binding MySystem}&quot;

It works well. So far, all of my controls have been able to access this data

&lt;ComboBox ItemsSource=&quot;{Binding RelativeSource={RelativeSource Self}, 
                                Path=(core:SystemBehavior.SystemService).Units}&quot;

But there's this ominous sentence in the MS documentation about Property Value Inheritance that gives me pause.

> However, property value inheritance can bridge this gap in the logical
> tree and can still pass inherited values through, so long as the
> inheritable property was registered as an attached property and no
> deliberate inheritance-blocking boundary (such as a Frame) is
> encountered.

(emphasis added by me)

So my question is: What elements (besides a frame) can "block" dependency property inheritance?

答案1

得分: 1

我找不到明确回答这个问题的任何文档。

我在referencesource.microsoft.com上搜索,列出了以下内容:

  • Frame(框架)

  • Page(页面)

  • DocumentReference(文档引用)

  • FixedPage(固定页面)

  • PageContent(页面内容)

英文:

I can't find any documentation that explicitly answers the question.

I searched referencesource.microsoft.com to come up with this list:

  • Frame
  • Page
  • DocumentReference
  • FixedPage
  • PageContent

huangapple
  • 本文由 发表于 2020年1月4日 01:19:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582729.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定