2013-10-09 62 views
2

我使用MahApp.Metro测试wpf应用程序。 不知何故,我无法改变ToggleSwitch的风格。我只想更改开关的前景或背景等简单属性。我究竟做错了什么?MahApps.Metro更改ToggleSwitch风格

Mainwindow.xaml

<Style x:Key="flyoutToggleSwitchStyle" TargetType="{x:Type Controls:ToggleSwitch}" BasedOn="{StaticResource {x:Type Controls:ToggleSwitch}}"> 
     <Setter Property="BorderBrush" Value="WhiteSmoke"/> 
     <Setter Property="Background" Value="White"/>  
     <Setter Property="Foreground" Value="Yellow"/> 
     <Setter Property="OnLabel" Value="Yes"/> <!--<<<---THIS WORKS!!--> 
     <Setter Property="OffLabel" Value="No"/> 
    </Style> 

<Controls:ToggleSwitch Style="{StaticResource flyoutToggleSwitchStyle}"> 
    <Controls:ToggleSwitch.Header> 
      <TextBlock> 
        Test        
      </TextBlock> 
    </Controls:ToggleSwitch.Header> 
</Controls:ToggleSwitch> 

回答

1

现在有一种新ToggleSwitch属性称为SwitchForeground其允许改变用于ON位置的颜色(上v0.14测试)。 示例:

<controls:ToggleSwitch SwitchForeground="{StaticResource MyGreen}" /> 
+1

注意:此属性现在已过时,应使用OnSwitchBrush/OffSwitchBrush – MaLiN2223

1

的问题是,在Mahapps.Metro ToggleSwitch大多数的属性不能在风格内改变,因为没有TemplateBinding或Key原始模板中定义描述。
所以风格只能通过创建一个新的模板来改变。为此,必须更改ToggleSwitch和ToggleSwitchButton模板。

Issue on GitHub
Source of the templates