什么是使用&QUOT之间的差异;用的StaticResource&QUOT约束力;并使用"的StaticResource直接"在WPF约束力、差异、直接、QUOT

2023-09-04 11:20:47 作者:清风烈酒

我在 App.Resources

<Application.Resources>
    <ItemsPanelTemplate x:Key="mycustomItemsPanel">
        .... Some code here
    </ItemsPanelTemplate>
</Application.Resources>

和提供这一个UIControl这样

and providing this to a UIControl this way

<.... ItemsPanel="{StaticResource mycustomItemsPanel}" />

不过,我才知道,这可以作为

But I came to know that this can be provided as

<.... ItemsPanel="Binding Source={StaticResource mycustomItemsPanel}}" />

这两者之间的区别是什么?

What is the difference between these?

推荐答案

一方面绑定只能在的依赖属性,另一种是某些对象的行为不同,当为一个 Binding.Source ,即的 DataSourceProviders

For one thing the binding will only be able on dependency properties, another would be that some objects behave differently when assigned as a Binding.Source, namely DataSourceProviders.

公共基类和合同的 DataSourceProvider 的对象,这是工厂中执行的一些查询,产生一个单一的对象,或者您可以使用作为绑定源对象的对象的列表。

Common base class and contract for DataSourceProvider objects, which are factories that execute some queries to produce a single object or a list of objects that you can use as binding source objects.

所规定的对象 DataSourceProvider 则是用来代替 DataSourceProvider 本身。

The object provided by the DataSourceProvider then is used instead of the DataSourceProvider itself.

在这种特定情况下出现,因此应的没有实际的区别的。

In this specific case there hence should be no practical difference.