2

があり、 のようにBitmapImage設定したいと考えています。私はこれを試しましたBackgroundGrid

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すると正常に動作します:backgroundgrid

ImageBrush ib = new ImageBrush() { ImageSource = bmp };
ContentPanel.Background = ib;

しかし、私はxaml方法を使用する必要があります。質問は同じです。

4

1 に答える 1