Color Reflector for WP7 and Silverlight
Join the DZone community and get the full member experience.
Join For FreeLet’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/
Opinions expressed by DZone contributors are their own.
Comments