Setting WindowButtonCommands styles in Mahapps.Metro

杀马特。学长 韩版系。学妹 提交于 2019-12-04 10:07:50

based on crumbl3d changes, a short how to...

There are now two styles (Light, Dark) which will be used based on OverrideDefaultWindowCommandsBrush property (available at MetroWindow) and it's lightness (default is the Light style).

So, put these at your App.xaml (or something else)

<Style x:Key="CustomLightMetroWindowButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource LightMetroWindowButtonStyle}">
    <Setter Property="Foreground" Value="Chocolate" />
</Style>

<Style x:Key="CustomDarkMetroWindowButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DarkMetroWindowButtonStyle}">
    <Setter Property="Foreground" Value="Crimson" />
</Style>

<Style TargetType="{x:Type controls:WindowButtonCommands}" BasedOn="{StaticResource {x:Type controls:WindowButtonCommands}}">
    <Setter Property="LightMinButtonStyle" Value="{StaticResource CustomLightMetroWindowButtonStyle}" />
    <Setter Property="LightMaxButtonStyle" Value="{StaticResource CustomLightMetroWindowButtonStyle}" />
    <Setter Property="LightCloseButtonStyle" Value="{StaticResource CustomLightMetroWindowButtonStyle}" />
    <Setter Property="DarkMinButtonStyle" Value="{StaticResource CustomDarkMetroWindowButtonStyle}" />
    <Setter Property="DarkMaxButtonStyle" Value="{StaticResource CustomDarkMetroWindowButtonStyle}" />
    <Setter Property="DarkCloseButtonStyle" Value="{StaticResource CustomDarkMetroWindowButtonStyle}" />
</Style>

Edit

If you only want to use this at one window then you can create a style with a key and use it at this window like this:

<controls:MetroWindow.WindowButtonCommands>
    <controls:WindowButtonCommands Style="{DynamicResource CustomWindowButtonCommandsStyleLocatedtInAppXaml}" />
</controls:MetroWindow.WindowButtonCommands>

The style located in App.xaml

<Style x:Key="CustomWindowButtonCommandsStyleLocatedtInAppXaml" TargetType="{x:Type controls:WindowButtonCommands}" BasedOn="{StaticResource {x:Type controls:WindowButtonCommands}}">
    <Setter Property="LightMinButtonStyle" Value="{StaticResource CustomLightMetroWindowButtonStyle}" />
    <Setter Property="LightMaxButtonStyle" Value="{StaticResource CustomLightMetroWindowButtonStyle}" />
    <Setter Property="LightCloseButtonStyle" Value="{StaticResource CustomLightMetroWindowButtonStyle}" />
    <Setter Property="DarkMinButtonStyle" Value="{StaticResource CustomDarkMetroWindowButtonStyle}" />
    <Setter Property="DarkMaxButtonStyle" Value="{StaticResource CustomDarkMetroWindowButtonStyle}" />
    <Setter Property="DarkCloseButtonStyle" Value="{StaticResource CustomDarkMetroWindowButtonStyle}" />
</Style>

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!