![](/img/trans.png)
[英]Using StaticResource as an argument for MarkupExtension causes NullReferenceException in WPF
[英]What is the difference between using “Binding with StaticResource” and using “StaticResource directly” in WPF
我在mycustomItemsPanel
中创建了一个App.Resources
<Application.Resources>
<ItemsPanelTemplate x:Key="mycustomItemsPanel">
.... Some code here
</ItemsPanelTemplate>
</Application.Resources>
并以这种方式将其提供给UIControl
<.... ItemsPanel="{StaticResource mycustomItemsPanel}" />
但我知道这可以作为提供
<.... ItemsPanel="Binding Source={StaticResource mycustomItemsPanel}}" />
这些有什么区别?
一方面,绑定只能用于依赖属性 ,另一方面是某些对象在被指定为Binding.Source
时表现不同,即DataSourceProviders
。
DataSourceProvider对象的公共基类和契约,它们是执行某些查询以生成单个对象的工厂或可用作绑定源对象的对象列表。
然后使用DataSourceProvider
提供的对象而不是DataSourceProvider
本身。
在这种特定情况下,因此应该没有实际差异 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.