12

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.

Noam M
  • 3,156
  • 5
  • 26
  • 41
mababin
  • 193
  • 4
  • 16

4 Answers4

20

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.

mababin
  • 193
  • 4
  • 16
Darnell W.
  • 374
  • 2
  • 13
  • 3
    I feel like the uppercase should not be a default behaviour from MahApps.Metro, but thank you for the solution. Works like a charm. – mababin Jun 22 '15 at 05:02
  • 1
    You can use the "http" mahapps namespace too: `xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"`. Of course you need to have mahapps package installed in the project. – heltonbiker Sep 08 '16 at 18:19
  • How to keep the original case for everything? Shoudn't "normal case" be the normal case?! – Leon Dec 12 '17 at 06:16
  • 1
    ButtonHelper.PreserveTextCase is now replayced by ControlsHelper.ContentCharacterCasing – Kux Jul 22 '21 at 06:15
7

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>

MGDsoft
  • 91
  • 1
  • 3
  • 1
    Looked good to me in the designer. But at runtime, the button style fell back to the default WPF style. – tm1 Apr 26 '18 at 07:56
  • ButtonHelper.PreserveTextCase is now replayced by ControlsHelper.ContentCharacterCasing. I found out that BasedOn="{StaticResource MahApps.Styles.Button}" seems to work. – Kux Aug 09 '21 at 20:57
4

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>
Kux
  • 1,362
  • 1
  • 16
  • 31
0

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>
Indy Singh
  • 27
  • 1
  • 5