MahApps - How to disable automatic uppercase of default button

5.6k views Asked by At

I have started to introduce MahApps.Metro (really awesome) in my WPF application and my favorite button is the default. The problem is that it puts all my text in uppercase and I don't want it.

4

There are 4 answers

4
Darnell W. On BEST ANSWER

You can override the default value by setting the property for all buttons in 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>

Omitting the x:Key setting causes the style to be applied to all buttons in this MetroWindow.

1
Kux On

Update for 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>
0
Indy Singh On

The following line worked for me:

<Setter Property="mah:ControlsHelper.ContentCharacterCasing" Value="Normal"/>

I had to use the namespace "mah" instead of "controls" to match the instructions of the current quick-start guide. It was a bit tricky making it work from fragments of xml as they need to be consistent with other directives in the code. Below is a complete working example.

App.xml:

<Application x:Class="Example.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Example"
             xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <!-- Theme setting -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Blue.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <!-- Change default Button character case from Upper to Normal -->
            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource MahApps.Styles.Button}">
                <Setter Property="mah:ControlsHelper.ContentCharacterCasing" Value="Normal"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

MainWindow.xml:

<mah:MetroWindow x:Class="Example.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Example"
        mc:Ignorable="d"
        xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        TitleCharacterCasing="Normal"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Content="Button"  HorizontalAlignment="Left" Margin="92,73,0,0" VerticalAlignment="Top" Height="144" Width="197" FontSize="22" />
    </Grid>
</mah:MetroWindow>
2
MGDsoft On

If you apply the answer of ImaBrokeDude to your App.xaml, it will work for all the buttons in any window of your project.

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