我的 WPF 应用程序中有一个以图像作为背景的窗口。我希望该图像模糊。我是这样做的:
这是我的窗口:
<Window x:Class="kiosk.UI.Views.PageSwitch"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:myProjectName.Converters"
Title="PageSwitch" Height="1024" Width="1280"
Style="{StaticResource WindowStyle}"
WindowStyle="None" ResizeMode="NoResize"
WindowStartupLocation="CenterScreen">
</Window>
这是我应用的样式:
<Style x:Key="WindowStyle" TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="Verdana" />
<Setter Property="Background">
<Setter.Value>
<VisualBrush>
<VisualBrush.Visual>
<Image Source="Images\myImage.png" >
<Image.Effect>
<BlurEffect Radius="20"/>
</Image.Effect>
</Image>
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</Style>
这有效 - 图像模糊。但是,背景图像周围有一个大约 5 毫米的黑色粗边框。为什么它在那里,我该如何删除它?
这是我尝试过的替代方法:
<VisualBrush Viewbox="0, 0, 1280, 1024" ViewboxUnits="Absolute" >
并且边框被移除但是图像被拉伸(stretch)了很多。几乎一半的图像甚至没有显示。
我该如何解决这个问题?
最佳答案
按照 this answer 中所示进行操作到你之前的一个问题。将 Image 控件放在一个网格中,并将 ClipToBounds
设置为 true。
<VisualBrush>
<VisualBrush.Visual>
<Grid ClipToBounds="True">
<Image Source="Images\myImage.png">
<Image.Effect>
<BlurEffect Radius="20"/>
</Image.Effect>
</Image>
</Grid>
</VisualBrush.Visual>
</VisualBrush>
关于wpf - 对作为窗口背景的图像的模糊效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25018331/