我正在使用WPF Material Design,我必须将资源字典添加到我的App.xaml中。这样,样式就可以应用于我的每个控件。
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>我已经创建了UserControl,我想忽略MaterialDesign样式,这是可能的吗?
发布于 2017-09-30 04:27:37
当然,您有一些选择--您是否希望在一种或两种情况下覆盖Material Design?您可以继续使用该用户控件的键来创建自己的样式。即使它实际上没有对默认的WPF控件做任何更改,它仍然应该覆盖材料设计。
是否希望在所有情况下覆盖特定的用户控件?同样,创建一个没有键的样式,并使用TargetType {x:Type {your control}}。在所有情况下都应覆盖材料设计。
无论哪种方式,我都建议您将自定义样式的ResourceDictionary放在一个单独的Styles.xaml文件中,并将其添加到app.xaml文件中,就像您对Material Design样式所做的那样。
发布于 2020-02-19 03:23:23
如果你已经在你的app.xaml中覆盖了像<Style TargetType={x:Type Button}/>这样的东西,并试图将它重置为微软在特定页面上的样式,这是Marco Zhou的excellent solution:
如果您想要应用露娜主题,您可以简单地合并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>请注意,您需要添加对PresentationFramework.luna dll的引用。
https://stackoverflow.com/questions/46494135
复制相似问题