[英]Loop through Brushes in Silverlight to get all possible colors
我有一個在以前的項目中工作過的類,該項目遍歷了WPF應用程序中所有可用的顏色,如下所示;
public class ListOfColors
{
public List<ComboBoxItem> SelectableColours;
private PropertyInfo[] _propInfo;
public List<ComboBoxItem> GetListOfColours()
{
List<ComboBoxItem> SelectableColours = new List<ComboBoxItem>();
Type brushesType = typeof(Brushes);
PropertyInfo[] colors = brushesType.GetProperties();
_propInfo = colors;
foreach (var color in colors)
{
ComboBoxItem colour = new ComboBoxItem();
colour.Content = color.Name;
SelectableColours.Add(colour);
}
return SelectableColours;
}
}
這在我的WPF應用程序中可以正常工作,但是現在我試圖在Silverlight項目中復制相同的內容,但是它表示我缺少using指令或程序集引用。 我試圖添加System.Windows.Media
參考,但仍然說我錯過了它。
我是否缺少步驟,還是必須重新獲得其他類型?我嘗試使用“ Colors
作為類型,但這會帶回有限數量的顏色,總共15種。
Type brushesType = typeof(Colors);
Silverlight沒有Brushes
類,並且如您所述, Colors
類的數量有限。
我建議您制作擁有所有功能的自己的Colors
版本。
參見: http : //lotsacode.wordpress.com/2010/02/27/translating-c-color-to-silverlight-color/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.