首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >忽略App.xaml样式

忽略App.xaml样式
EN

Stack Overflow用户
提问于 2017-09-30 01:32:02
回答 2查看 408关注 0票数 0

我正在使用WPF Material Design,我必须将资源字典添加到我的App.xaml中。这样,样式就可以应用于我的每个控件。

App.xaml

代码语言:javascript
复制
  <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>

我已经创建了UserControl,我想忽略MaterialDesign样式,这是可能的吗?

EN

回答 2

Stack Overflow用户

发布于 2017-09-30 04:27:37

当然,您有一些选择--您是否希望在一种或两种情况下覆盖Material Design?您可以继续使用该用户控件的键来创建自己的样式。即使它实际上没有对默认的WPF控件做任何更改,它仍然应该覆盖材料设计。

是否希望在所有情况下覆盖特定的用户控件?同样,创建一个没有键的样式,并使用TargetType {x:Type {your control}}。在所有情况下都应覆盖材料设计。

无论哪种方式,我都建议您将自定义样式的ResourceDictionary放在一个单独的Styles.xaml文件中,并将其添加到app.xaml文件中,就像您对Material Design样式所做的那样。

票数 1
EN

Stack Overflow用户

发布于 2020-02-19 03:23:23

如果你已经在你的app.xaml中覆盖了像<Style TargetType={x:Type Button}/>这样的东西,并试图将它重置为微软在特定页面上的样式,这是Marco Zhou的excellent solution

如果您想要应用露娜主题,您可以简单地合并App.Resources下的主题字典,如下所示:

代码语言:javascript
复制
<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>

请注意,您需要添加对PresentationFramework.luna dll的引用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46494135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档