MahApps - 如何禁用默认按钮的自动大写
MahApps - How to disable automatic uppercase of default button
我已经开始在我的 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
中的所有按钮。
如果您将 ImaBrokeDude 的答案应用到您的 App.xaml,它将适用于您项目的任何 window 中的所有按钮。
<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>
我已经开始在我的 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
中的所有按钮。
如果您将 ImaBrokeDude 的答案应用到您的 App.xaml,它将适用于您项目的任何 window 中的所有按钮。
<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>