Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <text value="Hello, World" color="Red"/>
- Brush color = Brushes.Black; // Default
- // later on...
- this.color = (Brush)Enum.Parse(typeof(Brush), prasedValue("color"));
- // best, using Color's static method
- Color red1 = Color.FromName("Red");
- // using a ColorConverter
- TypeConverter tc1 = TypeDescriptor.GetConverter(typeof(Color)); // ..or..
- TypeConverter tc2 = new ColorConverter();
- Color red2 = (Color)tc.ConvertFromString("Red");
- // using Reflection on Color or Brush
- Color red3 = (Color)typeof(Color).GetProperty("Red").GetValue(null, null);
- // in WPF you can use a BrushConverter
- SolidColorBrush redBrush = (SolidColorBrush)new BrushConverter().ConvertFromString("Red");
- Color.FromName(a.Value)
- color = new SolidBrush(Color.FromName(a.Value));
- myTextBlock.Foreground = new BrushConverter().ConvertFromString("#FFFFFF") as SolidColorBrush;
- Type t = typeof(Brushes);
- Brush b = (Brush)t.GetProperty("Red").GetValue(null, null);
- var tc = TypeDescriptor.GetConverter(typeof(Brush));
- Color c = (Color)TypeDescriptor.GetConverter(typeof(Color)).ConvertFromString("Red");
- return new Brush(c);
Add Comment
Please, Sign In to add comment