Over a million developers have joined DZone.

Color Reflector for WP7 and Silverlight

DZone's Guide to

Color Reflector for WP7 and Silverlight

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

Let’s assume that you have a paint application.  A user can draw, modify pictures, save it, retrieve it back and even share it.  Now with such an application, you would want to enhance the user experience by allowing him customize the user-interface.  So user changes the background color, fonts, etc and closes the application.

Next day, he opens the application and he expects that his settings are saved.  You would definitely use IsolatedStorage to save his data in a local XML file.  And then, apply the colors, fonts to the UI.  Here’s where you need a Color Reflector that converts a color (in a String format) to a Color (as in Enum)

So, here you go for the ColorReflector

using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Shapes;

namespace OptimaX.WP7.Formatters
public class ColorReflector
public static Color FromKnownColor(string colorName)
Line lne = (Line)XamlReader.Load("<line xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Fill="" + colorName + "" />");
return (Color)lne.Fill.GetValue(SolidColorBrush.ColorProperty);

What is OptimaX.WP7?  That is my own-framework with all utilities/tools for Windows Phone 7

Source:  http://www.ganshani.com/2011/06/11/color-reflector-for-wp7-and-silverlight/

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}