简体   繁体   English

MahApps和Property Grid

[英]MahApps and Property Grid

First of all, great thanks to MahApps. 首先,非常感谢MahApps。 What a cool project! 多么酷的项目!

I have an existing application written in WPF that I have applied the MahApps library to. 我有一个用WPF编写的现有应用程序,我已经应用了MahApps库。 I used this tutorial: 我用过这个教程:

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

However the effect on the Property Grid (Xceed) is minimal. 然而,对Property Grid(Xceed)的影响微乎其微。

The combo boxes in my other windows look like this: 我其他窗口中的组合框如下所示:

在此输入图像描述

The property grid combo boxes still look like this (ugly!): 属性网格组合框仍然看起来像这样(丑陋!):

在此输入图像描述

However clicking on a combo box shows the right MahApps style for the items. 但是,单击组合框会显示项目的正确MahApp样式。 It is only the Combo Box itself (closed) that is not flat. 只有组合盒本身(封闭)不平坦。

在此输入图像描述

My knowledge on WPF is basic. 我对WPF的了解是基本的。 Where would I start to try and fix this? 我将从哪里开始尝试修复此问题? Do I need to manually override the combo box template in the Property Grid? 我是否需要手动覆盖Property Grid中的组合框模板?

in MainWindow.xaml use Controls:MetroWindow 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"
                      >

in MainWindow.xaml.cs inheritance MetroWindow MainWindow.xaml.cs继承MetroWindow

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

add App.xaml following settings 添加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>

Perhaps your other combobox looks ugly because the MahApps resources is not found? 也许你的其他组合框看起来很难看,因为找不到MahApps的资源?

Place the mahapp resources you are using in a resource dictionary in the App.xaml file so it will be accessible for all windows. 将您正在使用的mahapp资源放在App.xaml文件的资源字典中,以便所有窗口都可以访问它。 (and not place them in a resource dictionary in only one window, ie. mainwindow.xaml) (而不是只在一个窗口中将它们放在资源字典中,即mainwindow.xaml)

App.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>

The property grid overrides the styles of MahApps. 属性网格覆盖了MahApps的样式。 You have to create a own PropertyEditor for your properties. 您必须为您的属性创建一个自己的PropertyEditor。 The PropertyEditor overrides the styles of the property grid. PropertyEditor会覆盖属性网格的样式。

I know thats a lot of work, but its the only way to get the MahApps look. 我知道这很多工作,但它是获得MahApps外观的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM