[英]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.