Split WPF Style XAML Files
- by anon
Most WPF styles I have seen are split up into one very long Theme.xaml file. I want to split mine up for readability so my Theme.xaml looks like this:
<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>
The problem is that this solution does not work. I have a default button style which is BasedOn the default Aero style for a button:
<Style x:Key="{x:Type Button}" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="FontSize" Value="14"/>
...
</Style>
If I place all of this in one file it works but as soon as I split it up I get StackOverflow exceptions because it thinks it is BasedOn itself. Is there a way around this? How does WPF add resources when merging resource dictionaries?