如何将Metro样式应用于WPF中的页面控件?

时间:2015-12-01 17:07:18

标签: wpf mahapps.metro

我正在使用Microsoft Visual Studio Ultimate 2013开发一个WPF项目。我正在尝试使用类似于Visual Studio Dark Theme的样式,本文Visual Studio 2012 Metro Styles for WPF帮助我实现了这一目标。我正在为Menu,Button,ComboBox,DataGrid,ScrollBar,TextBox等设置样式,但是对于控件页面,我没有找到一种方法来获取Metro Style。

enter image description here

这是我的app.xaml

Application x:Class="Chem.Managment.Visual.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:,,,/Selen.Wpf.Core;component/MetroWindowResources.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Tooltip.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Buttons.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.Core;component/Resources.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/MenuStyles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/ButtonStyles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/ComboBoxStyles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/DataGridStyles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/GroupBoxStyles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/ScrollBarStyles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/TextBoxStyles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/WindowStyles.xaml"/>
                <ResourceDictionary Source="ChemResDict.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Style TargetType="Button" BasedOn="{StaticResource StandardButton}"/>
            <Style TargetType="Window" BasedOn="{StaticResource StandardWindow}"/>
            <Style TargetType="Menu" BasedOn="{StaticResource StandardMenu}"/>
            <Style TargetType="ScrollBar" BasedOn="{StaticResource StandardScrollBar}"/>
            <Style TargetType="TextBox" BasedOn="{StaticResource StandardTextBox}"/>
            <Style TargetType="DataGrid" BasedOn="{StaticResource StandardDataGrid}"/>
            <Style TargetType="ComboBox" BasedOn="{StaticResource StandardComboBox}"/>
            <Style TargetType="GroupBox" BasedOn="{StaticResource StandardGroupBox}"/>
        </ResourceDictionary>

    </Application.Resources>

</Application>

我尝试在上面的代码中添加页面控件,但我不知道如何,可能没有实现。

我在这里缺少什么?有任何建议请。 提前致谢

1 个答案:

答案 0 :(得分:1)

Pages的样式在Controls.Page.xaml中定义,引用自Controls.xaml。当我检查您的资源时,您不会导入前面提到的资源。根据{{​​1}}的文档,您必须包含以下资源才能获得完整的MahApps体验:

MahApps

作为主题,您可以使用<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> BaseLight.xaml作为重音,在GitHub上找到任何可能的颜色。