Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

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?

like image 648
Amgad Serry Avatar asked Jan 24 '26 20:01

Amgad Serry


1 Answers

Need to use a SolidColorBrush:

 Rect_Sample.Fill = new SolidColorBrush( (Color)color.GetValue(null));
like image 114
loopedcode Avatar answered Jan 27 '26 10:01

loopedcode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!