【发布时间】:2015-06-22 04:22:02
【问题描述】:
我已经开始在我的 WPF 应用程序中引入 MahApps.Metro(真的很棒),我最喜欢的按钮是默认按钮。问题是它把我所有的文本都用大写,我不想要它。
【问题讨论】:
标签: wpf mahapps.metro
我已经开始在我的 WPF 应用程序中引入 MahApps.Metro(真的很棒),我最喜欢的按钮是默认按钮。问题是它把我所有的文本都用大写,我不想要它。
【问题讨论】:
标签: wpf mahapps.metro
您可以通过设置Window.Resources中所有按钮的属性来覆盖默认值
<controls:MetroWindow
...
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<ResourceDictionary>
<Style TargetType="{x:Type Button}"
BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="controls:ButtonHelper.PreserveTextCase" Value="True"/>
</Style>
</ResourceDictionary>
</Window.Resources>
<Grid>
<!-- This would have normally made the text uppercase if not for the style override -->
<Button Content="Button"/>
</Grid>
</controls:MetroWindow>
省略x:Key 设置会导致样式应用于此MetroWindow 中的所有按钮。
【讨论】:
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"。当然你需要在项目中安装 mahapps 包。
如果您将 ImaBrokeDude 的答案应用于您的 App.xaml,它将适用于您项目的任何窗口中的所有按钮。
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="{x:Type Button}"
BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="controls:ButtonHelper.PreserveTextCase" Value="True"/>
</Style>
</ResourceDictionary>
</Application.Resources>
【讨论】:
MahApps 2.4.7 更新
<Application
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">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="{x:Type Button}"
BasedOn="{StaticResource MahApps.Styles.Button}">
<Setter Property="controls:ControlsHelper.ContentCharacterCasing" Value="True"/>
</Style>
</ResourceDictionary>
</Application.Resources>
【讨论】: