tags:

views:

392

answers:

1

Hi, Im having a grid in whre the user can specify an image to be shown, and its alignment. If the user chooses a small image and aligns it bottom -right, i want to provide the user with an option to assign a background color to fill in the rest, eg. pink/black/white. When the user now chooeses a small image the background is always white and i cant seem to get it right at runtime:

byte r = (byte)Convert.ToInt32(backcolorR);
            byte g = (byte)Convert.ToInt32(backcolorG);
            byte b = (byte)Convert.ToInt32(backcolorB);
            ((Grid)container).Background = new SolidColorBrush(Color.FromArgb(0, r, g, b));

This isnt working, its like, the image fille the entire grid and i should set the background color on the image instead... is this possible?

+1  A: 

The first argument of Color.FromArgb represents the Alpha blending value. 0 meaning fully transparent, 255 meaning totally not transparent (fully opaque). You're requesting a fully transparent color which means you don't see any color, just the background. I guess the color of the element your grid is on is white. Use this code to fix your problem:

Color.FromArgb(255, r, g, b)
// or
Color.FromArgb(r, g, b)
Lars Truijens