简体   繁体   中英

Ignore App.xaml styles

I am using WPF Material Design where I had to add resource dictionary into my App.xaml. This way styles are applied to each of my control.

App.xaml

  <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" />
                <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>

I have created UserControl where I would like to ignore the MaterialDesign styles is it possible?

Sure, you've got some options - are you looking to override the Material Design in one or two cases? You can go ahead and make your own style with a key for that User Control. Even if it doesn't actually change anything from the default WPF control, it should still override the material design.

Looking to override the specific user control in all cases? Same thing, create a style that doesn't have a key and uses TargetType {x:Type {your control}}. That should override the material design in all cases.

Either way I recommend putting your custom styles' ResourceDictionary in a separate Styles.xaml file and adding it into your app.xaml file just like you did with the Material Design styles.

If you've overridden something like <Style TargetType={x:Type Button}/> in your app.xaml and are trying to reset it to how Microsoft styled it on a particular page, here's an excellent solution by Marco Zhou:

If you want to apply the luna theme, you could simply merge the theme dictionary under App.Resources as follows:

<Application x:Class="WpfTestHarness.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="RenderNotificationDemo.xaml">
  <Application.Resources>
    <!--This is the relevant bit-->
    <ResourceDictionary Source="/PresentationFramework.luna, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/luna.normalcolor.xaml" />
  </Application.Resources>
</Application>

Note that you need to add reference to the PresentationFramework.luna dll.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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