2010-07-05 237 views

回答

9

您正在尋找ColorConverter.ConvertFromString

Color color = (Color)ColorConverter.ConvertFromString("#10eeee"); 
SolidColorBrush myBrush = new SolidColorBrush(color); 

您也需要using System.Windows.Media;在程序頂部。

以下string Color formats should be supported。您可以使用BrushConverter

+0

我得到一個無法轉換顏色刷錯誤。有任何想法嗎? – 2010-07-05 03:12:04

+0

@Sergio Tapia:你需要創建一個畫筆,看看我的編輯。 – 2010-07-05 03:15:14

+2

聽起來像你想要畫筆不是一種顏色。嘗試'new BrushConverter()。ConvertFromString(「#FFFFFF」)' – 2010-07-05 03:15:53