C# 向边界厚度为0的WPF窗体添加阴影
我有一个WPF无边界窗口,其阴影设置为网格,如下所示:C# 向边界厚度为0的WPF窗体添加阴影,c#,wpf,vb.net,window,C#,Wpf,Vb.net,Window,我有一个WPF无边界窗口,其阴影设置为网格,如下所示: <Window x:Class="Wpf.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="52
<Window x:Class="Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" WindowStyle="None"
AllowsTransparency="True" Background="Transparent" BorderThickness="0">
<Grid>
<Grid.Effect>
<DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" ShadowDepth="2"/>
</Grid.Effect>
</Grid>
</Window>
但是,当BorderThickness设置为0时,阴影不会出现。当我增加这个值时,阴影会出现,但是当使用DragMove()将窗口移动到屏幕边缘时,会留下一个间隙(大概是BorderThickness的宽度)
因此,如何在BorderThickness设置为0的窗口周围添加阴影?提前感谢。
<Window x:Class="WpfApp7.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp7"
mc:Ignorable="d" WindowStyle="None"
AllowsTransparency="True" Background="Transparent" BorderThickness="0"
Title="MainWindow" Height="450" Width="800">
<Grid Margin="10">
<Grid.Background>
<SolidColorBrush Color="Green" Opacity="1"/>
</Grid.Background>
<Grid.Effect>
<DropShadowEffect Color="Black" BlurRadius="15" Direction="-90"
RenderingBias="Quality" ShadowDepth="2"/>
</Grid.Effect>
</Grid>
:)只需在网格中添加边距。它需要空间来显示阴影