I\'m trying to set the foreground of a textblock on the backend using a string ( something like \"Red\")
I\'ve tried this:
ColorText.Foreground = new Bru
BrushConverter
isn't available in windows phone. You could build up a dictionary of colors then pass the color you want to SolidColorBrush
ctor with a helper method.
public static class ColorsHelper {
private static readonly Dictionary dict =
typeof(Colors).GetProperties(BindingFlags.Public | BindingFlags.Static)
.Where(prop => prop.PropertyType == typeof(Color))
.ToDictionary(prop => prop.Name, prop => (Color)prop.GetValue(null, null));
public static Color FromName(string name) {
return dict[name];
}
}
ColorText.Foreground = new SolidColorBrush(ColorsHelper.FromName("Red"));
Make sure the above dictionary uses System.Windows.Media.Color
struct and System.Windows.Media.Colors
class. I believe there are a few Color
types around so type in the whole namespace if necessary or rename it.