Bloggrammer
Bloggrammer

Reputation: 1111

How to Disable Material Design Style in WPF

I am using Material Design in XAML to style my WPF UI controls. I defined the default theme in the App.xaml file.

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

However, I want some of my controls to have the default WPF look and feel, but it looks like the Material Design in XAML overrides the WPF default control style.

Example: The button below automatically takes its style from the Material design without specifying it.

<Button Content="Hello" Width="100"/>

How can I disable the Material Design in some controls?

Upvotes: 5

Views: 2549

Answers (2)

mm8
mm8

Reputation: 169280

Setting the Style property to x:Null makes it fall back to the default Style that is implemented in the framework assembly:

<Button Content="Hello" Width="100" Style="{x:Null}" />

The other option would be to remove the <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> from your App.xaml and explicitly set the Style property of all controls that do you want to have the Material Design look.

Upvotes: 5

tntwist
tntwist

Reputation: 81

You can create an empty style inside a ResourceDict like this:

<Window.Resources>
        <ResourceDictionary>
            <Style x:Key="styleless" />
        </ResourceDictionary>
</Window.Resources>

and assign it to your button like this:

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

Upvotes: 1

Related Questions