WPF 通过透明边框投影
WPF drop shadow by transparent border
美好的一天。我正在创建一个网格 like this
(有影子)。一切都会好起来的,但是我不能做一个透明背景的阴影边框,所以网格的背景不能是透明的(这很关键)。这个问题有解决办法吗? current
<Grid Visibility="{Binding InfoPanelVisibility}" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2">
<Border Background="White" BorderThickness="1,0,0,0" >
<Border.Effect>
<DropShadowEffect BlurRadius="8" Color="WhiteSmoke" Direction="250"></DropShadowEffect>
</Border.Effect>
</Border>
<Grid.Background>
<SolidColorBrush Color="White" Opacity="0.4" />
</Grid.Background>
<ScrollViewer>
...
</ScrollViewer>
</Grid>
这段代码是我自己写的
,其功能显而易见
Style.Resource里面有一个ControlTemplate,我在里面定义了一个grid
在网格中,有一个使用其边框创建阴影的矩形和一个 ContentPresenter!
(抱歉我的英语不好)
<Style TargetType="Grid">
<Setter Property="Template" Value="{DynamicResource GridBorderShadowEffect}"></Setter>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="Transparent"/>
</Setter.Value>
</Setter>
<Style.Resources>
<ControlTemplate x:Key="GridBorderShadowEffect" TargetType="{x:Type Grid}">
<Grid>
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Margin" Value="5"></Setter>
</Style>
</Grid.Style>
<Rectangle>
<Rectangle.Style>
<Style TargetType="Rectangle">
<Style.Triggers>
<DataTrigger Binding="{Binding
RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}},
Path=WindowState}" Value="Normal">
<Setter Property="StrokeThickness" Value="2"/>
<Setter Property="Stroke" Value="Purple"></Setter>
<Setter Property="BitmapEffect">
<Setter.Value>
<DropShadowBitmapEffect ShadowDepth="10" Softness="1" Opacity="1" Color="Purple" />
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
<ContentPresenter>
</ContentPresenter>
</Grid>
</ControlTemplate>
</Style.Resources>
</Style>
美好的一天。我正在创建一个网格 like this (有影子)。一切都会好起来的,但是我不能做一个透明背景的阴影边框,所以网格的背景不能是透明的(这很关键)。这个问题有解决办法吗? current
<Grid Visibility="{Binding InfoPanelVisibility}" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2">
<Border Background="White" BorderThickness="1,0,0,0" >
<Border.Effect>
<DropShadowEffect BlurRadius="8" Color="WhiteSmoke" Direction="250"></DropShadowEffect>
</Border.Effect>
</Border>
<Grid.Background>
<SolidColorBrush Color="White" Opacity="0.4" />
</Grid.Background>
<ScrollViewer>
...
</ScrollViewer>
</Grid>
这段代码是我自己写的 ,其功能显而易见
Style.Resource里面有一个ControlTemplate,我在里面定义了一个grid
在网格中,有一个使用其边框创建阴影的矩形和一个 ContentPresenter!
(抱歉我的英语不好)
<Style TargetType="Grid">
<Setter Property="Template" Value="{DynamicResource GridBorderShadowEffect}"></Setter>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="Transparent"/>
</Setter.Value>
</Setter>
<Style.Resources>
<ControlTemplate x:Key="GridBorderShadowEffect" TargetType="{x:Type Grid}">
<Grid>
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Margin" Value="5"></Setter>
</Style>
</Grid.Style>
<Rectangle>
<Rectangle.Style>
<Style TargetType="Rectangle">
<Style.Triggers>
<DataTrigger Binding="{Binding
RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}},
Path=WindowState}" Value="Normal">
<Setter Property="StrokeThickness" Value="2"/>
<Setter Property="Stroke" Value="Purple"></Setter>
<Setter Property="BitmapEffect">
<Setter.Value>
<DropShadowBitmapEffect ShadowDepth="10" Softness="1" Opacity="1" Color="Purple" />
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
<ContentPresenter>
</ContentPresenter>
</Grid>
</ControlTemplate>
</Style.Resources>
</Style>