【发布时间】:2010-03-12 17:03:19
【问题描述】:
我见过的大多数 WPF 样式都被拆分为一个很长的 Theme.xaml 文件。为了便于阅读,我想拆分我的,所以我的 Theme.xaml 看起来像这样:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;v3.0.0.0;31bf3856ad364e35;component/themes/aero.normalcolor.xaml"/>
<ResourceDictionary Source="Controls/Brushes.xaml"/>
<ResourceDictionary Source="Controls/Buttons.xaml"/>
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
问题是这个解决方案不起作用。我有一个默认按钮样式,它是基于按钮的默认 Aero 样式:
<Style x:Key="{x:Type Button}" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="FontSize" Value="14"/>
...
</Style>
如果我将所有这些都放在一个文件中,它就可以工作,但是一旦我将它拆分,我就会得到 StackOverflow 异常,因为它认为它是 BasedOn 本身。有没有解决的办法? WPF在合并资源字典时如何添加资源?
【问题讨论】: