12/27/2022 0 Comments Wpf colorconverter xaml![]() ![]() You can expand this code to translate name to Media.Color directly. This code makes translating name to Color class faster: public class FastNameToColor It's a bit ugly, but it's a one-time hit.įyi, another easier way is just use microsoft built static class, ex Colors.Red .From the window, we need to create an object of the UserControl and pass the value as under: Copy Code. Public static Color FromName( string name)įoreach ( PropertyInfo property in typeof( Colors). The TextChanged operation is handled to ensure the actual object is modified whenever the value of the textbox is modified.You could fairly easily fetch the property names and values from once into a map: private static readonly Dictionary KnownColors = FetchColors() ![]() If you want to avoid boxing, build a dictionary up to start with for the standard names (still using ColorConverter) and then use the dictionary for subsequent lookups. Call ColorConverter.ConvertFromString and cast the result. Of course, ColorConverter is the way to go. With WPF its pretty easy to create a converter to display the color. ![]() var result = ColorConverter.ConvertFromString( "Red") as Color C Enum Color Converter with IValueConverter Code4Noobz.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |