我使用MahApps.Metro。在设置指南中,它告诉您在App.xaml中包含一些代码。所以我做了。
现在,我希望能够为其添加自己的样式。例如,这包括所有默认情况下具有边框的窗口。
但这是行不通的。不应用边框。我不知道如何在不使用MahApps.Metro时对样式进行样式设置,但是有了它,我俩都无法正常工作。
怎么了
<Application x:Class="ProjectName.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Windows/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<!-- This is what I added -->
<ResourceDictionary xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro">
<Style TargetType="Controls:MetroWindow">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
</Style>
</ResourceDictionary>
<!-------------------------->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
您忘记了通过以下方式继承样式BasedOn
:
<ResourceDictionary xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro">
<Style TargetType="Controls:MetroWindow"
BasedOn="{StaticResource {x:Type Controls:MetroWindow}}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
</Style>
</ResourceDictionary>
编辑
经过测试后,我的第一个答案不是很正确。您必须设置一个,x:Key
并在每个MetroWindow
xaml中使用此密钥。
<Style x:Key="CustomGlobalMetroWindow"
TargetType="{x:Type Controls:MetroWindow}"
BasedOn="{StaticResource {x:Type Controls:MetroWindow}}">
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="BorderBrush"
Value="Purple" />
</Style>
用法
<Controls:MetroWindow x:Class="Demo"
Style="{DynamicResource CustomGlobalMetroWindow}" />
希望对您有所帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句