Recently, a small issue in Windows Phone 7 development drove me nuts for a day .. don’t get me wrong, I love doing WP7 dev; just got frustrated with not being able to change a small setting. Here’s the story..
Any WP7 application that uses Location Services has to have permissions from the user, as per app certification guidelines. Makes sense. Also, one needs to provide the user with an in-app setting to turn Location Service use on/off, without affecting the master switch. Also makes sense. So, many apps are resorting to using the Silverlight WP7 Codeplex Toolkit controls to provide such a Settings screen. There is a very handy Toggle Switch to turn a setting on/off .. just like what you’ll find in the rest of the OS. So, this becomes a natural choice for the Location Service use setting. Following is the Setting screen in the Sogeti Hub WP7 app, with the real white theme and an altered wheat background :
A more in-depth use of the Toggle Switch is described here:
Now, here’s the little issue — when pitted against an all-white page background, the slider head of the Toggle switch could not be distinguished in the emulator window!!; in other words, got lost in the white back color. Now why not change the white background? .. because the rest of the app has the similar look & feel and a different color/transparency would be jarring.
The Toggle Switch is a rather flexible one though.. one may use highly customized templates for header & content ; assign event handlers to the user turning the switch on/off etc. However, I could not find a setting that would allow me to manipulate the look of the switch itself. Background and Brush Silverlight usuals were not handy. Now, I know what you’re thinking .. it’s a codeplex toolkit; get the code and manipulate. Yes, true .. but I was reluctant to try messing with the pre-built switch just to be able to draw a border. It should just work, right? Eventually, would probably have tried writing my own toggle switch; but a quick look at my HD7 WP7 phone revealed that with a Light background theme, the same toggle control rendered just fine !! Were there differences in what the OS was using versus what the Codeplex code had?
Then, just out of curiosity, took my app and deployed it to the phone with a light background theme. Voila .. it works! The Toggle Switch shows up exactly as it should with a black border around the switch head, which distinguishes it from the rest of the page content. So, it has always been working .. why was the emulator lying? May be a little issue in rendering with the Silverlight toolkit controls. Nonetheless, thought I would blog to save some other soul a day of frustration.
Sanity returns to earth .. ha ha.