WPF窗體無邊框陰影效果-程式碼
資源字典:
<Style x:Key="NormalWinStyle" TargetType="{x:Type Window}">
<Setter Property="WindowStyle" Value="None" />
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="Background" Value="{x:Null}"/>
<!--在Window中設定SnapsToDevicePixels屬性值為True,子元素繼承此值-->
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border Background="#FFFFFF" CornerRadius="3" Margin="{TemplateBinding Padding}">
<!--設定窗體的陰影效果-->
<Border.Effect>
<DropShadowEffect ShadowDepth="0" BlurRadius="10" Opacity="0.75"/>
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid></Grid>
<!--使用AdornerDecorator裝飾ContentPresenter-->
<AdornerDecorator Grid.Row="1">
<ContentPresenter></ContentPresenter>
</AdornerDecorator>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
效果: