MahApps.Metro如何更改ToggleSwitch样式

4
我将翻译如下:

我正在使用MahApp.Metro测试WPF应用程序。

但是,我无法更改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>
2个回答

2

现在有一个名为SwitchForeground的新ToggleSwitch属性,它允许更改ON位置的颜色(在v0.14上测试)。

示例:

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

3
注意:此属性现已过时,应使用OnSwitchBrush / OffSwitchBrush。 - MaLiN2223

1
问题在于,在Mahapps.Metro ToggleSwitch中,大多数属性不能在样式中更改,因为原始模板定义中没有TemplateBinding或Key。
因此,只能通过创建新模板来更改样式。为此,必须更改ToggleSwitch和ToggleSwitchButton模板。

GitHub上的问题
模板源代码


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接