【问题标题】:MahApps.Metro change ToggleSwitch styleMahApps.Metro 更改 ToggleSwitch 样式
【发布时间】:2014-12-02 07:21:22
【问题描述】:

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

主窗口.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>

【问题讨论】:

    标签: wpf styles mahapps.metro toggleswitch


    【解决方案1】:

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

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

    【讨论】:

    • 注意:这个属性现在已经过时了,应该使用 OnSwitchBrush / OffSwitchBrush
    【解决方案2】:

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

    Issue on GitHub
    Source of the templates

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 2016-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多