2013-04-21 116 views
1

我有一个组合框有一个颜色列表,我想使用选中的颜色来填充矩形我这样做:不能隐式地将类型'Windows.UI.Color'转换为'Windows.UI.Xaml.Media.Brush'

var alwan = typeof(Colors).GetTypeInfo().DeclaredProperties; 
      foreach (var item in alwan) 
      { 
       x.Add(item); 
      } 
      CbForColors.ItemsSource = x; 
      CbForColors_Copy.ItemsSource = x; 

private void CbForColors_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
     var color = CbForColors.SelectedItem as PropertyInfo; 
     //var color2 = color.GetMethod; 
     //var color3 = color2.Invoke(color,null); 
     Rect_Sample.Fill = (Color)color.GetValue(null);  
} 

我得到这个错误:

Cannot implicitly convert type ' Windows.UI.Color ' to ' Windows.UI.Xaml.Media.Brush '

注释行,我得到了argb的颜色,即。 #FFA07FF0(类似的东西)。什么是已经实施的,以及如何从这个argb颜色?我应该把它变成一个字符串,然后把每个2个字符变成一个int,并把它们放在一个新的颜色a,r,g,b?

+0

我相信这是一个欺骗http://stackoverflow.com/questions/5641078/convert-from-color-to-brush – Bit 2013-04-21 02:28:54

回答

4

需要使用的SolidColorBrush:

Rect_Sample.Fill = new SolidColorBrush((Color)color.GetValue(null)); 
+1

哇TY这实际上相当显然我想我现在应该休息一下:D – 2013-04-21 02:33:57

+1

@AmgadSerry,如果这就是你要找的,把它标记为答案。 – 2013-04-21 02:37:11

相关问题