如何在 WPF 中禁用 Material 设计风格
How to Disable Material Design Style in WPF
我正在使用 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 设计似乎覆盖了 WPF 默认控件样式。
示例:下面的按钮自动采用 Material 设计的样式,无需指定。
<Button Content="Hello" Width="100"/>
如何禁用某些控件中的 Material 设计?
您可以像这样在 ResourceDict 中创建一个空样式:
<Window.Resources>
<ResourceDictionary>
<Style x:Key="styleless" />
</ResourceDictionary>
</Window.Resources>
并像这样将其分配给您的按钮:
<Button Style="{StaticResource styleless}" />
将 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 设计外观。
我正在使用 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 设计似乎覆盖了 WPF 默认控件样式。
示例:下面的按钮自动采用 Material 设计的样式,无需指定。
<Button Content="Hello" Width="100"/>
如何禁用某些控件中的 Material 设计?
您可以像这样在 ResourceDict 中创建一个空样式:
<Window.Resources>
<ResourceDictionary>
<Style x:Key="styleless" />
</ResourceDictionary>
</Window.Resources>
并像这样将其分配给您的按钮:
<Button Style="{StaticResource styleless}" />
将 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 设计外观。