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 https://github.com/mrlacey/WPMisc/blob/master/ToggleSwitchStyling.xaml (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. :)


3 comments:

  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.

    ReplyDelete
  2. atlanta falcons, http://www.atlantafalconsjersey.us/
    michael kors outlet online, http://www.michaelkorsusa.us/
    mbt sneakers, http://www.mbtshoesoutlet.us.com/
    dallas cowboys, http://www.dallascowboysjersey.us/
    oklahoma city thunder, http://www.thunderjerseystore.com/
    san francisco 49ers, http://www.sanfrancisco49ersjerseys.us/
    cheap uggs, http://www.uggsale.in.net/
    polo ralph lauren uk, http://www.ralphlauren-outletonline.co.uk/
    chicago bulls, http://www.chicagobullsjerseys.net/
    babyliss hair dryer, http://www.babyliss.us.com/
    supra sneakershttp://www.suprashoes.us.com
    ray ban sunglasses, http://www.ray-bansunglasses.eu.com/
    toms shoes outlet online, http://www.toms.us.com/
    snapback hats, http://www.cheapsnapbacks.us.com/
    fitflop sandals, http://www.fitflop.in.net/
    louis vuitton outlet,louis vuitton outlet online,louis vuitton,louisvuitton.com,authentic louis vuitton,louis vuitton factory outlet,cheap louis vuitton
    ralph lauren sale, http://www.ralphlaurenoutlet.in.net/
    oakley outlet online, http://www.oakleyoutlet.in.net/
    kkk10 13

    ReplyDelete