3

I have a ComboBox that has a list of colors, and I want to use the color selected to fill a rectangle so I did this:

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);       
}

I get this error:

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

The commented lines I get the argb for the color, ie. #FFA07FF0 (something like that). What's wrong with what is already implemented and how can I make a color from this argb? Should I turn it into a string and then turn each 2 characters into an int and put them in a new color a,r,g,b?

4

1 回答 1

6

需要使用 SolidColorBrush:

 Rect_Sample.Fill = new SolidColorBrush( (Color)color.GetValue(null));
于 2013-04-21T02:30:29.683 回答