user3795349
user3795349

Reputation: 324

Windows phone 8 array to set Color.FromArgb

I would like to set the background colour of the grid using the colours array.

int[] coloursArray = {255, 0, 100, 0};    
GridBackgroundDARK.Background = new SolidColorBrush(Color.FromArgb(coloursArray.All));

The error is:

No overload for method 'FromArgb' takes 1 arguments

Thank you in advance for any help :)

Upvotes: 1

Views: 271

Answers (2)

Minh Thai
Minh Thai

Reputation: 578

You need to provide all 4 arguments a,r,g,b.

Upvotes: 1

keyboardP
keyboardP

Reputation: 69372

I don't think All is what you're looking for here. If you want to use the values in the array, assuming they're in the correct order, you can do this:

Color.FromArgb(coloursArray[0], coloursArray[1], coloursArray[2], coloursArray[3])

If you're going to do it often, you could create a method that does it for you

public Color ColourFromArray(int[] cArray) 
{
    //add your error handling checks
    //...

    return Color.FromArgb(cArray[0], cArray[1], cArray[2], cArray[3])
}

Upvotes: 2

Related Questions