Wpf MahApps Metro设置应用程序资源中的窗口边框样式

Wpf MahApps Metro设置应用程序资源中的窗口边框样式,wpf,mahapps.metro,Wpf,Mahapps.metro,我正在尝试为我的MahApps Metro应用程序设置窗口边框样式。我读过关于如何设置不同边框样式的文章,我想我明白了。但是,我正在尝试将我的应用程序中所有窗口的边框样式设置为相同(全部为阴影),但它似乎不起作用 我的应用程序资源如下所示: <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> &l

我正在尝试为我的MahApps Metro应用程序设置窗口边框样式。我读过关于如何设置不同边框样式的文章,我想我明白了。但是,我正在尝试将我的应用程序中所有窗口的边框样式设置为相同(全部为阴影),但它似乎不起作用

我的应用程序资源如下所示:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/GSDXThemes;component/GSDXDarkYellowTheme.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
<!-- Merge in ResourceDictionaries defining base styles to use. This theme is based on the Metro Dark Yellow theme. -->
<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/Accents/Yellow.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
    <ResourceDictionary Source="pack://application:,,,/GSDXThemes;component/GSDXControlStyles.xaml" />
</ResourceDictionary.MergedDictionaries>

我的资源字典如下所示:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/GSDXThemes;component/GSDXDarkYellowTheme.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
<!-- Merge in ResourceDictionaries defining base styles to use. This theme is based on the Metro Dark Yellow theme. -->
<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/Accents/Yellow.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
    <ResourceDictionary Source="pack://application:,,,/GSDXThemes;component/GSDXControlStyles.xaml" />
</ResourceDictionary.MergedDictionaries>

GSDXControlStyles字典只是为我的应用程序设置一些自定义样式值。正是在这个文件中,我尝试设置窗口边框

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:resx="clr-namespace:GSDXThemes.Properties"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:System="clr-namespace:System;assembly=mscorlib"
                xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                xmlns:GSDUserControls="clr-namespace:GSD.CommonGUI.UserControls;assembly=CommonGUI">

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
</ResourceDictionary.MergedDictionaries>

<!-- Now customize the theme for our use...mostly just changing font sizes, etc...-->
<Style TargetType="{x:Type Controls:MetroWindow}" >
    <Setter Property="WindowTransitionsEnabled" Value="False" />
    <Setter Property="EnableDWMDropShadow" Value="True" />
</Style>

<Style TargetType="{x:Type Label}" BasedOn="{StaticResource MetroLabel}">
    <Setter Property="FontSize" Value="16"/>
</Style>

<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource MetroTextBox}">
    <Setter Property="FontSize" Value="16"/>
</Style>
...

...
所有其他样式设置都可以正常工作。但是设置窗口边框的第一行没有任何作用。我所有的窗户都没有边框


我如何才能使此功能正常工作,使所有窗口都具有阴影边框?

您必须为您的样式提供一个键,才能获得有效的解决方案

<Style x:Key="CustomDefaultWindowStyle"
       TargetType="{x:Type Controls:MetroWindow}"
       BasedOn="{StaticResource {x:Type Controls:MetroWindow}}" >
    <Setter Property="WindowTransitionsEnabled" Value="False" />
    <Setter Property="EnableDWMDropShadow" Value="True" />
</Style>
(不要害怕“无效样式目标类型:…”消息,这是一个VS错误)

希望有帮助