合并你的
MyResourceDictionaryWindowStyle
App.xaml
. 请参见下面的示例。您的项目可能与其他项目的名称不同
MyWPFProject.App
和
Source
资源字典的位置取决于您的自定义资源字典在项目中的实际位置,因此您应该相应地调整两者,以及
StartupUri
为您的主窗口。
<Application x:Class="MyWPFProject.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="pack://application:,,,/MyWPFProject;component/MyResourceDictionaryWindowStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
然后将样式设置为
StaticResource
在你的窗户里。
<Window x:Class="MyWPFProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Style="{StaticResource CustomWindowStyle}"
Title="MainWindow" Height="450" Width="800">
<!-- ...your XAML code -->
</Window>