Sunday 15 March 2015

c# - Getting SolidColorBrush from a string -


I am trying to set the foreground of the text box on the backend using a string (something like "red")

I have tried this:

  ColorText.Foreground = New brushconverter (). ConvertFromString (Color [color2] .tostring ());   

However, it does not seem to recognize BrushConvert () . I've included System.Windows.Media , but it still can not be found.

Is there another way to do this?

Brush Canoner is not available in Windows Phone. You can make a dictionary of colors, then you can pass the color you want to SolidColorBrush ctor with a helpful method.

  Color of the public static class Helper {Only for reading the static static & lt; String, Color & gt; Dict = typeof (color) .GetProperties (BindingFlags.Public | BindingFlags.Static) Where (prop = & gt; prop.propertyType == type (color)) .Odod (prop = & gt; prop.Name, prop = & gt; (color) prop.GetValue (empty, null)); Name by public static color (string name) {return word [name]; }} ColorText.Foreground = New SolidColorBrush (ColorsHelper.FromName ("Red"));   

Make sure the above dictionary uses the System.Windows.Media.Color struct and System.Windows.Media.Colors class is. I believe that if something is necessary or changes its name then there are some types of colors in the entire namespace.

No comments:

Post a Comment