簡體   English   中英

在VisualBrush中將圖像和純色設置為背景

[英]Setting an image AND a solid color as a background in VisualBrush

這是我的代碼:

<Style x:Key="BackgroundStyle" TargetType="{x:Type Window}">
        <Setter Property="Background">
            <Setter.Value>
                <VisualBrush Viewbox="0, 0,1280,1024" ViewboxUnits="Absolute" >
                    <VisualBrush.Visual>
                        <Image Source="Images\myImage.png">
                                <Image.Effect>
                                    <BlurEffect Radius="20"/>
                                </Image.Effect>
                            </Image>
                    </VisualBrush.Visual>
                </VisualBrush>
            </Setter.Value>
        </Setter>
    </Style>

我希望具有這種樣式的窗口將myImage.png圖像作為背景,該圖像將變得模糊,並且在該圖像上應該有一層純白色,其不透明度為0.8。使用上面的代碼,圖像被設置為背景並且模糊,但是我不知道如何在圖像頂部設置白色。

它看起來應該像這樣:

在此處輸入圖片說明

只需在VisualBrush的Visual中添加具有適當不透明度的白色Rectangle:

<VisualBrush Viewbox="0,0,1280,1024" ViewboxUnits="Absolute" >
    <VisualBrush.Visual>
        <Grid Width="1280" Height="1024">
            <Image Source="Images\myImage.png">
                <Image.Effect>
                    <BlurEffect Radius="20"/>
                </Image.Effect>
            </Image>
            <Rectangle Fill="White" Opacity="0.8"/>
        </Grid>
    </VisualBrush.Visual>
</VisualBrush>

通過設置Grid的ClipToBounds屬性,您還可以擺脫Viewbox設置:

<VisualBrush>
    <VisualBrush.Visual>
        <Grid Width="1280" Height="1024" ClipToBounds="True">
            <Image Source="Images\myImage.png">
                <Image.Effect>
                    <BlurEffect Radius="20"/>
                </Image.Effect>
            </Image>
            <Rectangle Fill="White" Opacity="0.8"/>
        </Grid>
    </VisualBrush.Visual>
</VisualBrush>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM