Tôi muốn tạo SolidColorBrush từ giá trị Hex, chẳng hạn như #ffaacc. Tôi có thể làm cái này như thế nào?
Trên MSDN, tôi đã nhận được:
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255);
Vì vậy, tôi đã viết (xem xét phương pháp của tôi nhận được màu như #ffaacc
):
Color.FromRgb(
Convert.ToInt32(color.Substring(1, 2), 16),
Convert.ToInt32(color.Substring(3, 2), 16),
Convert.ToInt32(color.Substring(5, 2), 16));
Nhưng điều này đã gây ra lỗi như
The best overloaded method match for 'System.Windows.Media.Color.FromRgb(byte, byte, byte)' has some invalid arguments
Ngoài ra 3 lỗi như: Cannot convert int to byte.
Nhưng sau đó, ví dụ MSDN hoạt động như thế nào?