How to set selectedcolor of ColorCanvas by using Argb in code behind

249 views Asked by At

I have a ARGB color code and now I'm trying to set selectedcolor of ColorCanvas by using that ARGB color code in codebehind. Argb color code is not static value since it'll kept changing. Can anyone know how to set it?I have tried to do like this but it's not working:

rec.Fill = new SolidColorBrush(Color.FromArgb(a, r, g, b));
1

There are 1 answers

0
Mark Hall On

Not sure why it looks like you are using the Fill property of a Rectangle and not showing a ColorCanvas, but the ColorCanvas.SelectedColor is a Color not a Brush. So something like this should work(My ColorCanvas has x:Name of colorCanvas).

colorCanvas.SelectedColor = Color.FromArgb(255, 0, 0, 255); //Your Color Value

if you are trying to get the color from a SolidColorBrush like the Fill Property of a Rectangle(Providing it is a SolidColorBrush), something like this should work.

colorCanvas.SelectedColor = ((SolidColorBrush)rect.Fill).Color;

If neither of these example is what you are asking please clarify your question, add more code that you have tried plus any and all errors that you may be getting.