首页 > 解决方案 > UWP 内阴影与 LinearGradientBrush

问题描述

有什么办法可以产生这样的效果LinearGradientBrush吗? 在此处输入图像描述

我还检查了这个问题:C# UWP Toolkit DropShadowPanel inner shadow

作为回答,他们使用DropShadowPanelwith Rectangle,that has StrokeThickness="10"。但这会创建灰色边框。我想知道是否有任何方法可以使用 LinearGradientBrush 或不将 StrokeThickness 设置为 10 来实现它?

我想保持网格的原始大小,不要以某种方式切割它。

标签: c#uwpuwp-xamlwindows-community-toolkit

解决方案


您可以像在另一个答案中一样使用 DropShadowPanel 并将内部矩形笔划更改为白色(或任何您的页面背景)。

<Grid Width="400" Height="200">
    <Grid.Clip>
        <RectangleGeometry Rect="0,0,400,200" />
    </Grid.Clip>
    <Rectangle Fill="Yellow" />
    <TextBlock Text="Some text" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    <controls:DropShadowPanel HorizontalContentAlignment="Stretch"
                              BlurRadius="50"
                              ShadowOpacity="1"
                              Color="Black">
        <Rectangle Stroke="White"
                   StrokeThickness="10" />
    </controls:DropShadowPanel>
</Grid>

这将创建以下内容:

在此处输入图像描述


推荐阅读