【问题标题】:MahApps - How to disable automatic uppercase of default buttonMahApps - 如何禁用默认按钮的自动大写
【发布时间】:2015-06-22 04:22:02
【问题描述】:

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

【问题讨论】:

    标签: wpf mahapps.metro


    【解决方案1】:

    您可以通过设置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 中的所有按钮。

    【讨论】:

    • 我觉得大写不应该是 MahApps.Metro 的默认行为,但感谢您的解决方案。像魅力一样工作。
    • 您也可以使用“http”mahapps 命名空间:xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"。当然你需要在项目中安装 mahapps 包。
    • 如何为所有东西保留原案? “正常情况”不应该是正常情况吗?!
    • ButtonHelper.PreserveTextCase 现在由 ControlsHelper.ContentCharacterCasing 重播
    【解决方案2】:

    如果您将 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>
    

    【讨论】:

    • 在设计师看来我觉得不错。但在运行时,按钮样式会退回到默认的 WPF 样式。
    • ButtonHelper.PreserveTextCase 现在由 ControlsHelper.ContentCharacterCasing 重播。我发现 BasedOn="{StaticResource MahApps.Styles.Button}" 似乎有效。
    【解决方案3】:

    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>
    

    【讨论】:

      猜你喜欢
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 2018-04-01
      • 1970-01-01
      相关资源
      最近更新 更多