I have a set of styles that I want to load to use as a StaticResource throughout my app: Styles.xaml
Everything works fine if I include the style in each window or page:
<Window x:Class="MainWindow"
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
</Window>
If I try to include the style in my app resource, it throws an error that it can't find the MainWindow.xaml resource.
<Application x:Class="App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Anyone know why I can't include this in my app resource?
I would comment on your post but there's a 50 rep requirement...
Have you tried setting a key for the ResourceDictionary?
<ResourceDictionary x:Key="Styles" Source="Resources/Styles.xaml" />
I'm not sure why the MergedDictionary doesn't work, but if I add the style as a standalone resource it works fine.
<Application x:Class="App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Excavator"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary Source="Resources/Styles.xaml" />
</Application.Resources>
</Application>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.