如何在WPF中禁用Material Design风格

4

我正在使用 Material Design in XAML 来为我的 WPF UI 控件添加样式。我在 App.xaml 文件中定义了默认主题。

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
                    <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
                    <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>            
        </ResourceDictionary>
    </Application.Resources>

然而,我希望我的某些控件具有默认的WPF外观和感觉,但看起来XAML中的Material Design会覆盖WPF默认的控件样式。
例如:下面的按钮自动从Material design中获取其样式,而不需要指定。
<Button Content="Hello" Width="100"/>

我该如何在某些控件中禁用Material Design主题?

2个回答

4
Style属性设置为x:Null会使其回退到框架程序集中实现的默认Style
<Button Content="Hello" Width="100" Style="{x:Null}" />

另一种选择是从您的App.xaml中删除<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />,并显式设置所有控件的Style属性,以获得Material Design外观。

1
您可以像这样在ResourceDict中创建空样式:
<Window.Resources>
        <ResourceDictionary>
            <Style x:Key="styleless" />
        </ResourceDictionary>
</Window.Resources>

and assign it to your button like this:

<Button Style="{StaticResource styleless}" />

1
是的,那似乎可以工作。我是这样将按钮样式设置为 null 的:<Button Style="{x:Null}"/>,然后我认为可能有更好的方法来删除 Material Design 的默认样式。 - Bloggrammer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接