Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MahApps - How to disable automatic uppercase of default button

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.

like image 466
mababin Avatar asked Jun 22 '15 04:06

mababin


3 Answers

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.

like image 97
ImaBrokeDude Avatar answered Oct 26 '22 08:10

ImaBrokeDude


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>
like image 40
kux Avatar answered Oct 26 '22 10:10

kux


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>

like image 36
MGDsoft Avatar answered Oct 26 '22 08:10

MGDsoft