Question

I'm testing wpf applications using MahApp.Metro. Somehow I'm not able to change the style of the ToggleSwitch. I just want to change simple properties like foreground or background of the switch. What am I doing wrong?

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>
Was it helpful?

Solution

Now there is a new ToggleSwitch property called SwitchForeground which allows changing the colour for ON position (tested on v0.14). Example:

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

OTHER TIPS

The problem is that in the Mahapps.Metro ToggleSwitch most of the properties can not be changed within a style, because there is no TemplateBinding or Key defined in the original template definition.
So the style can only be changed by creating a new template. For this the ToggleSwitch and the ToggleSwitchButton templates have to be changed.

Issue on GitHub
Source of the templates

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top