Last active
July 16, 2018 17:55
-
-
Save brunossn/0dd99083e327533466f12de1320051fc to your computer and use it in GitHub Desktop.
Convert a hexadecimal color string to SolidColorBrush in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of usage: | |
// var color = "#FF0000".ToBrush(); | |
public static class HexToBrushExtension | |
{ | |
public static SolidColorBrush ToBrush(this string value) | |
{ | |
var converter = new BrushConverter(); | |
return (SolidColorBrush)converter.ConvertFromString(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The same code, now using inline funcion: