我的 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" >
边框被移除,但图像被拉伸了很多。几乎一半的图像甚至没有显示。
我怎样才能解决这个问题?
这样做就像所示这个答案 https://stackoverflow.com/a/24914260/1136211您之前的问题之一。将图像控件放入网格中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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)