I have a BitmapImage
, and want to set it as Background
of Grid
. I have tried this
xaml:
<Grid x:Name="ContentPanel">
<Grid.Background>
<ImageBrush x:Name="imgBg" />
</Grid.Background>
</Grid>
c#:
BitmapImage bmp = new BitmapImage();
bmp.DecodePixelWidth =(int) scrnWidth;
bmp.DecodePixelHeight = (int)scrnHeight;
bmp.SetSource(e.ChosenPhoto);
ImageBrush ib = new ImageBrush() { ImageSource = bmp };
imgBg.ImageSource = ib.ImageSource;
Output: Output is just black.
Question: using above code I am unable to set bitmapimage
as background
of Grid
element, Am I missing something ?
Update I knew, it works fine when we set image
as background
to grid
like:
ImageBrush ib = new ImageBrush() { ImageSource = bmp };
ContentPanel.Background = ib;
But I need to use xaml
way, Question is same.