Mobile Zone is brought to you in partnership with:

Punit has over 6 years of professional experience working on .NET technology stack including C#, Windows Phone and WCF. He is an open-source contributor of CodeInject, Workflow Extractor and dI.Hook on CodePlex, has 6 applications in MarketPlace, and a freeware application 'myTracker' on Softpedia. He writes on various topics on his website & has spoken in various forums in UK and India and is blogs on his website www.ganshani.com Punit is a DZone MVB and is not an employee of DZone and has posted 15 posts at DZone. You can read more from them at their website. View Full User Profile

Color Reflector for WP7 and Silverlight

12.23.2011
| 3001 views |
  • submit to reddit

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/


Published at DZone with permission of Punit Ganshani, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Robert Craft replied on Thu, 2012/01/26 - 5:49am

Your post is really good. It is very helpful when 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.

Java Collection

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.