Sunday, October 27, 2013

Fixing the styling of the WPToolkit ToggleSwitch

If you've ever done any XAML based development for Windows Phone you'll be aware of just how essential the WPToolkit is.

One of the most popular controls contained in the toolkit is the ToggleSwitch. Unfortunately though, its default styling doesn't play well when you want to use it with custom foreground and background colours.

Looking at this image we can see the same page in both light and dark themes. (At 50% in Blend)
The first pair of toggleswitches show the checked and unchecked states with the default theme colours.
The second pair shows what happens if with the default styling when the background and foreground are modified though.
This is almost certainly NOT what you want to see.
With a modified foregound and background I'd expect you want to see something like in the final pair of switches.

So, how to get the toggleswitch to display "properly"?
It's just a case of modifying both the `toolkit:ToggleSwitch` and the `toolkitPrimitives:ToggleSwitchButton`.
Add a `Foreground` reference to `ToggleSwitch` and then replace all the StaticResource references to PhoneForegroundBrush and PhoneBackgroundBrush with TemplateBinding references to `Foreground` and `Background`.
If that sounds complicated, don't worry. You can just copy it from (Which also contains the xaml used to create the above images.)

If you've developed an app where the toggleswitches look like the middle pair you now know how to update them.
Similarly, if you know of any apps where there are toggleswitches look like the middle pair above, point them to this article. :)


  1. Anonymous5:53 am

    Every one of these exercise physical exercise chanel replica sale the standard Couture lender together with spectacular colours, breezy material, in addition to a few an incredible in addition to trendy. In addition there is a 100 % to be able to special distinctive line of Luscious louis vuitton replica sale Couture rings additionally extra supplies. Every one of these types are often precise neo-conservative attitude making use of their distinctive layouts. The actual Couture to be able to special distinctive line of chanel replica sale suitcases additionally totes in addition to carriers will probably be versatile sufficient to utilize the client furnished by a stylish time of day louis vuitton replica sale for the crushed lime scale size rock and roll, every single child girls' particular day time. Because of the fact Luscious louis vuitton replica sale Totes in addition to carriers supply numerous textures, material additionally layouts.

  2. atlanta falcons,
    michael kors outlet online,
    mbt sneakers,
    dallas cowboys,
    oklahoma city thunder,
    san francisco 49ers,
    cheap uggs,
    polo ralph lauren uk,
    chicago bulls,
    babyliss hair dryer,
    supra sneakers
    ray ban sunglasses,
    toms shoes outlet online,
    snapback hats,
    fitflop sandals,
    louis vuitton outlet,louis vuitton outlet online,louis vuitton,,authentic louis vuitton,louis vuitton factory outlet,cheap louis vuitton
    ralph lauren sale,
    oakley outlet online,
    kkk10 13