2015-06-22 25 views

回答

14

您可以通過設置所有按鈕的財產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設置導致的風格在這個0​​適用於所有的按鈕。

+3

我覺得像大寫不應該從MahApps.Metro默認行爲,但感謝你的解決方案。奇蹟般有效。 – mababin

+1

您也可以使用「http」mahapps命名空間:'xmlns:controls =「http://metro.mahapps.com/winfx/xaml/controls」'。當然你需要在項目中安裝mahapps軟件包。 – heltonbiker

+0

如何保持一切的原始情況? Shoudn't「正常情況下」是正常情況?! – Leon

3

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