【问题标题】:How can I apply a Metro style to the Page Control in WPF?如何将 Metro 风格应用于 WPF 中的页面控件?
【发布时间】:2015-12-01 17:07:17
【问题描述】:

我正在使用 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 的方法。

这是我的 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>

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

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

【问题讨论】:

    标签: wpf mahapps.metro


    【解决方案1】:

    Pages 的样式在Controls.Page.xaml 中定义,它从Controls.xaml 引用。当我检查您的资源时,您不会导入任何前面提到的资源。根据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.xamlBaseDark.xaml,作为重音,您可以在GitHub 上找到任何可能的颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      • 2013-04-07
      相关资源
      最近更新 更多