设置WindowButtonCommands样式Mahapps.Metro [英] Setting WindowButtonCommands styles in Mahapps.Metro

查看:1850
本文介绍了设置WindowButtonCommands样式Mahapps.Metro的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变最小,最大和我的WPF应用程序关闭按钮的样式

I want to change the style of the Min, Max and Close buttons for my WPF application.

我使用的 Mahapps.Metro ,我已经成功地设法达到我想要的结果,但只有过时的 WindowMinButtonStyle WindowMaxButtonStyle WindowCloseButtonStyle MetroWindow 类。对过时的消息,例如 WindowMinButtonStyle 属性如下:

I'm using Mahapps.Metro and I have successfully managed to achieve the result I want, but only with the obsolete WindowMinButtonStyle, WindowMaxButtonStyle and WindowCloseButtonStyle properties in the MetroWindow class. The obsolete message on for example the WindowMinButtonStyle property reads:

这属性将是在下一版本中被删除。您应该使用LightMinButtonStyle或DarkMinButtonStyle在WindowButtonCommands覆盖的风格。

This property will be deleted in the next release. You should use LightMinButtonStyle or DarkMinButtonStyle in WindowButtonCommands to override the style.

现在的问题是,我无法弄清楚如何具体做那。在 MetroWindow 类有一个字段 WindowButtonCommands ,但内部,因此这似乎是错了吠叫起来。我是相当新的WPF,而且对如何做到这一点在他们的网站上的导游没有资料,所以我很丢失。 。我希望有人能给我提供一个简短的代码示例点我在正确的方向

The problem is that I can't figure out how specifically to do that. The MetroWindow class has a field called WindowButtonCommands, but it is internal, so that seems to be the wrong tree to bark up. I'm fairly new to WPF and there is no info on how to do this in the guides on their website, so I'm pretty lost. I'm hoping someone can provide me with a short code example to point me in the right direction.

修改 - 在这里是产生XAML警告:

EDIT - Here is XAML that produces the warning:

<controls:MetroWindow x:Class="Project.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
        WindowMinButtonStyle="{DynamicResource DarkWindowButtonStyle}"
        WindowMaxButtonStyle="{DynamicResource DarkWindowButtonStyle}"
        WindowCloseButtonStyle="{DynamicResource DarkWindowCloseButtonStyle}">
    <Grid>
    </Grid>
</controls:MetroWindow>



我还要提到我使用Mahapps.Metro的新V1.2.0,但我有同样的问题,与以前的版本。
Mahapps.Metro源代码具有过时属性:的 https://github.com/MahApps/MahApps.Metro/blob/develop/MahApps.Metro/Controls/MetroWindow.cs#L88 -L93

推荐答案

根据的 crumbl3d 更改,短怎么..

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

现在有两种款式(光线暗),将根据 OverrideDefaultWindowCommandsBrush 会用到的属性(可在 MetroWindow ),它的亮度(默认是光样式)。

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).

那么,把这些在你的的App.xaml (或别的东西)

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>



希望这有助于。

Hope this helps.

这篇关于设置WindowButtonCommands样式Mahapps.Metro的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆