如何淡化WPF背景图片?

时间:2018-03-28 13:25:23

标签: wpf xaml

如何淡化背景WPF图像?

我的XAML看起来像这样:

    <Grid.Background>
        <ImageBrush ImageSource="themes\backpic.png" Stretch="UniformToFill">
        </ImageBrush>
    </Grid.Background> 

我尝试过类似的事情:

 <Grid.Background>
        <ImageBrush ImageSource="pics\bl.png" Stretch="UniformToFill">
            <ImageBrush.Transform>
                <!-- some code here-->
            </ImageBrush.Transform>
        </ImageBrush>
    </Grid.Background>

1 个答案:

答案 0 :(得分:5)

启动ImageBrush的Opacity属性的DoubleAnimation:

<Grid>
    ...
    <Grid.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation
                        Storyboard.TargetProperty="Background.Opacity"
                        To="0" Duration="0:0:2"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>
    ...
</Grid>