C#UWP工具包DropShadowPanel内部阴影(C# UWP Toolkit DropShadowPanel inner shadow)

编程入门 行业动态 更新时间:2024-10-26 08:22:21
C#UWP工具包DropShadowPanel内部阴影(C# UWP Toolkit DropShadowPanel inner shadow)

在C#UWP中如何制作内在的阴影效果?

喜欢这个:

我创建了一个只有边框的网格,但阴影填充了整个网格。

<controls:DropShadowPanel BlurRadius="5" ShadowOpacity="0.5" OffsetX="0" OffsetY="0" Color="Black"> <Grid BorderBrush="White" BorderThickness="5"/> </controls:DropShadowPanel>

如何使用此控件制作内部阴影效果?

In C# UWP how to make inner shadow effect?

Like this:

I have created one grid with just a border, but shadow is populating the whole grid.

<controls:DropShadowPanel BlurRadius="5" ShadowOpacity="0.5" OffsetX="0" OffsetY="0" Color="Black"> <Grid BorderBrush="White" BorderThickness="5"/> </controls:DropShadowPanel>

How to make inner shadow effect with this control?

最满意答案

请注意, DropShadowPanel可以遮罩Rectangle ,因此您可以创建一个无填充的 Rectangle并将其放置在DropShadowPanel ,以便为Rectangle的边框创建一个扩散阴影。 然后,您只需将其放置在Grid并剪切Grid即可切断外部阴影。 如果你想要一个背景颜色,只需在Grid添加另一个Rectangle并将其放在DropShadowPanel后面即可。

示例代码

<Grid Width="400" Height="200" Margin="24"> <Grid.Clip> <RectangleGeometry Rect="0,0,400,200" /> </Grid.Clip> <Rectangle x:Name="BackgroundColor" Fill="LightSteelBlue" /> <controls:DropShadowPanel x:Name="InnerShadow" HorizontalContentAlignment="Stretch" BlurRadius="15" ShadowOpacity="0.5" Color="Black"> <Rectangle x:Name="BorderColor" Stroke="LightGray" StrokeThickness="10" /> </controls:DropShadowPanel> </Grid>

结果 在这里输入图像描述


关于剪辑

需要注意的一点是,只要Grid的大小发生变化,您就需要手动更新Rect的大小。 或者,您可以使用新的合成API来剪辑 -

var visual = ElementCompositionPreview.GetElementVisual(RootGrid); var compositor = visual.Compositor; visual.Clip = compositor.CreateInsetClip();

Note that DropShadowPanel can mask a Rectangle, so you can create a fill-less Rectangle and place it inside a DropShadowPanel to create a spreading shadow for the Rectangle's border only. Then, you just place it inside a Grid and clip the Grid to cut off the outer shadow. If you want a background color, simply add another Rectangle to the Grid and place it behind the DropShadowPanel.

Sample Code

<Grid Width="400" Height="200" Margin="24"> <Grid.Clip> <RectangleGeometry Rect="0,0,400,200" /> </Grid.Clip> <Rectangle x:Name="BackgroundColor" Fill="LightSteelBlue" /> <controls:DropShadowPanel x:Name="InnerShadow" HorizontalContentAlignment="Stretch" BlurRadius="15" ShadowOpacity="0.5" Color="Black"> <Rectangle x:Name="BorderColor" Stroke="LightGray" StrokeThickness="10" /> </controls:DropShadowPanel> </Grid>

Result enter image description here


About Clipping

One thing to note is that you will need to manually update the size of the Rect whenever the size of your Grid changes. Alternatively, you can use the new Composition API to do the clipping -

var visual = ElementCompositionPreview.GetElementVisual(RootGrid); var compositor = visual.Compositor; visual.Clip = compositor.CreateInsetClip();

更多推荐

本文发布于:2023-04-29 11:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工具包   阴影   UWP   DropShadowPanel   shadow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!