WPF save colors to database
I've been trying to figure out how to handle brushes in WPF. I want to let the user configure the colors they like and save that in a database which I've more or less figured out how to do (use solidcolorbrushes then cast that to a color and toostring gives me the value which I can save as VARCHAR in an accdb.
What I haven't been able to decipher is how to go from a string like #FFE2F2EF to a color and then a solidbrush. Seems winforms has simple ways but I can't find anything for WPF.
Of course there is probably a simple method that I just can't seem to find.
Anyone have any ideas?
Re: WPF save colors to database
WPF is annoying like that with simple ways of doing thing just overlooked so we have to do it ourselves. Here is a function that could convert that String into a Color:-
Code:
Private Function GetColor(ByVal colorStr As String) As Color
Dim c As UInteger = Convert.ToUInt32(colorStr.Substring(1), 16)
Dim A, R, G, B As Byte
B = c And &HFFI
G = (c And (&HFFI << 8)) >> 8
R = (c And (&HFFI << 16)) >> 16
A = (c And (&HFFI << 24)) >> 24
Return Color.FromArgb(A, R, G, B)
End Function