简体   繁体   English

忽略 App.xaml 样式

[英]Ignore App.xaml styles

I am using WPF Material Design where I had to add resource dictionary into my App.xaml.我正在使用 WPF Material Design,我必须将资源字典添加到我的 App.xaml 中。 This way styles are applied to each of my control.这样样式就应用于我的每个控件。

App.xaml应用程序.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?我已经创建了 UserControl,我想忽略 MaterialDesign 样式,这可能吗?

Sure, you've got some options - are you looking to override the Material Design in one or two cases?当然,您有一些选择 - 您是否希望在一两种情况下覆盖 Material Design? 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.即使它实际上没有改变默认 WPF 控件的任何内容,它仍然应该覆盖材料设计。

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}}.同样的事情,创建一个没有键并使用 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.无论哪种方式,我都建议将自定义样式的 ResourceDictionary 放在单独的 Styles.xaml 文件中,并将其添加到 app.xaml 文件中,就像使用 Material Design 样式一样。

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:如果您在 app.xaml 中覆盖了诸如<Style TargetType={x:Type Button}/>的内容,并试图将其重置为 Microsoft 在特定页面上的样式,那么 Marco Zhou 提供了一个很好的解决方案

If you want to apply the luna theme, you could simply merge the theme dictionary under App.Resources as follows:如果你想应用luna主题,你可以简单地合并App.Resources下的主题字典,如下所示:

<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.请注意,您需要添加对 PresentationFramework.luna dll 的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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