MahApps - 如何禁用默认按钮的自动大写

mab*_*bin 10 wpf mahapps.metro

我已经开始在我的WPF应用程序中引入MahApps .Metro(非常棒),我最喜欢的按钮是默认的.问题是它将我的所有文本都放在大写中,我不想要它.

小智 16

您可以通过设置所有按钮的属性来覆盖默认值 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>
Run Code Online (Sandbox Code Playgroud)

省略x:Key设置会导致样式应用于此中的所有按钮MetroWindow.

  • 我觉得大写不应该是MahApps.Metro的默认行为,但是谢谢你的解决方案.奇迹般有效. (3认同)

小智 7

如果您将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>
Run Code Online (Sandbox Code Playgroud)


kux*_*kux 5

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>
Run Code Online (Sandbox Code Playgroud)

  • 我认为应该是`&lt;Setter Property =“controls:ControlsHelper.ContentCharacterCasing”Value =“Normal”/&gt;` (2认同)