があり、 のようにBitmapImage
設定したいと考えています。私はこれを試しましたBackground
Grid
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;
出力:出力は黒のみです。
質問:上記のコードを使用すると、要素のbitmapimage
時点background
で設定できません。何か不足していますか?Grid
私が知っていた更新、次のように設定image
すると正常に動作します:background
grid
ImageBrush ib = new ImageBrush() { ImageSource = bmp };
ContentPanel.Background = ib;
しかし、私はxaml
方法を使用する必要があります。質問は同じです。