如何使用app.xaml在WPF中设置我的应用程序样式

时间:2012-05-27 18:13:01

标签: wpf styles app.xaml

我已成功将一个资源字典(包含我的主题/样式模板资源集合)添加到我的Window.Resources。这会适当地调整每个窗口的样式。但是,当我添加相同的行时:

<ResourceDictionary Source="BureauBlack.xaml" x:Key="BureauBlackKey"/>

到我的App.xaml没有任何变化。

编辑#1:

<Application x:Class="EventPlanner.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="clr-namespace:EventPlanner.ViewModels"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <vm:ViewModelLocator x:Key="ViewModelLocatorKey"/>
            <ResourceDictionary Source="BureauBlack.xaml" x:Key="BureauBlackKey"/>
        </ResourceDictionary>
    </Application.Resources>
</Application>

1 个答案:

答案 0 :(得分:4)

您需要将主题资源字典添加到MergedDictionaries集合:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="BureauBlack.xaml" />
        </ResourceDictionary.MergedDictionaries>

        <!-- other resources go here -->

        <vm:ViewModelLocator x:Key="ViewModelLocatorKey"/>

    </ResourceDictionary>
</Application.Resources>