【发布时间】:2015-07-03 11:09:47
【问题描述】:
我有一个控件,其样式在单独的资源字典中定义,并使用 generic.xaml 魔法来应用它。
如果我理解 msdn (https://msdn.microsoft.com/de-de/library/ms750613%28v=vs.110%29.aspx) 上描述的查找机制,generic.xaml 是在应用程序资源之后使用的,但是为 MyWindow 添加样式将导致来自 generic.xaml 的样式 + App 中定义的样式.xaml。
这是我的代码:
Generic.xaml
<ResourceDictionary ...>
<Style TargetType="{x:Type test:MyWindow}" BasedOn="{StaticResource ResourceKey={x:Type Window}}">
<Setter Property="Background" Value="Gainsboro" />
<Setter Property="Title" Value="Default!" />
</Style>
</ResourceDictionary>
App.xaml
<Application.Resources>
<ResourceDictionary>
<Style TargetType="{x:Type test:MyWindow}" BasedOn="{StaticResource ResourceKey={x:Type Window}}">
<Setter Property="Background" Value="HotPink" />
</Style>
</Application.Resources>
窗口将具有粉红色背景(来自 application.resource 样式)和“默认!”作为 generic.xaml 样式的标题。
wpf 为什么不停止在应用程序级别搜索样式?
【问题讨论】:
标签: wpf xaml generic.xaml