我有一个WPF窗口,它仅包含一个Frame元素。该Frame显示一个页面;根据用户交互,显示的页面会发生变化。
<Window x:Class="MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="720" Width="1280">
<Grid>
<Frame Source="{Binding Source={StaticResource MainPageIntent}, Path=Path}"/>
</Grid>
</Window>
我希望所有出现在该框架中的页面共享一个公共的资源字典,以便它们可以以一种常见的方式进行样式设置。
目前,每个页面都会加载类似于以下内容的代码:
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ResourceDictionaries/BaseControlStyles/MenuStyle.xaml"/>
我希望可以在窗口上设置资源字典,然后它们会“继承”这些资源,但似乎并非如此。我尝试了以下方法,但在Frame加载的页面中,未应用MenuStyle.xaml中找到的样式到控件:
<Window x:Class="MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="720" Width="1280">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ResourceDictionaries/BaseControlStyles/MenuStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Frame Source="{Binding Source={StaticResource MainPageIntent}, Path=Path}"/>
</Grid>
</Window>
有没有一种方法可以在窗口级别定义样式,使得所有在子框架中加载的页面都使用这些样式呢?
注意:我不想将这些样式应用于我的应用程序中的所有窗口,因此将这个ResourceDictionary放在我的App.xaml中似乎不是一个有效的解决方案。