设定图像和纯色中的VisualBrush背景 [英] Setting an image AND a solid color as a background in VisualBrush
本文介绍了设定图像和纯色中的VisualBrush背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的code:
<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的不透明度随着$ c中的窗口$ C我上面的图像设置为背景,它是模糊的,但我不知道如何设置一个白色的图像的顶部。
I want the window that has this style to have the myImage.png image as a background, which would be blurred and over that image there should be a layer of solid white color which would have an opacity of 0.8 With the code I have above, the image is set as background and it's blurred, but I don't know how to set a white color on top of the image.
它应该是这个样子:
推荐答案
只需添加一个白色矩形与适当的不透明性的VisualBrush的Visual:
Just add a white Rectangle with an appropriate Opacity to the VisualBrush's Visual:
<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>
通过设置网格的 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>
这篇关于设定图像和纯色中的VisualBrush背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文