MahApps和Property Grid

时间:2017-09-03 11:37:13

标签: c# wpf mahapps.metro

首先,非常感谢MahApps。多么酷的项目!

我有一个用WPF编写的现有应用程序,我已经应用了MahApps库。我用过这个教程:

http://mahapps.com/guides/quick-start.html

然而,对Property Grid(Xceed)的影响很小。

我其他窗口中的组合框如下所示:

enter image description here

属性网格组合框仍然看起来像这样(丑陋!):

enter image description here

但是,单击组合框会显示项目的正确MahApp样式。只有组合框本身(封闭)不平坦。

enter image description here

我对WPF的了解是基本的。我将从哪里开始尝试修复此问题?我是否需要手动覆盖属性网格中的组合框模板?

3 个答案:

答案 0 :(得分:5)

   MainWindow.xaml 中的

使用Controls:MetroWindow

<Controls:MetroWindow x:Name="MainApp" x:Class="AppWin.MainWindow"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                      MinHeight="700"
                      MinWidth="1024"
                      >
   MainWindow.xaml.cs 继承MetroWindow

namespace AppWin
{
    public partial class MainWindow : MetroWindow
    {
  ...
  

添加 App.xaml 以下设置

    <Application x:Class="AppWin.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:local="clr-namespace:AppWin"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
                    <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" />

/*--change template color for example green.xaml--*/
                    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/red.xaml" />

/*--change template style for example BaseDark.xaml--*/
                    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />

                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    </Application>

答案 1 :(得分:3)

也许你的其他组合框看起来很难看,因为找不到MahApps的资源?

将您正在使用的mahapp资源放在App.xaml文件的资源字典中,以便所有窗口都可以访问它。 (而不是只在一个窗口中将它们放在资源字典中,即.mainwindow.xaml)

<强> App.xaml中:

<Application... >
<Application.Resources>
    <ResourceDictionary>
         <!-- My other resources -->
         <!-- ... -->

        <!-- MahApps resources -->
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

答案 2 :(得分:0)

属性网格会覆盖MahApps的样式。您必须为您的属性创建一个自己的PropertyEditor。 PropertyEditor会覆盖属性网格的样式。

我知道这很多工作,但这是获得MahApps的唯一方法。