简体   繁体   中英

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 :)

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

你需要提供所有4个参数a,r,g,b。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM