Skip to content

[Feature] Add DropShadowPanel Support for Grid & Border content with Translucent Brushes & Round Corners #3607

@seanocali

Description

@seanocali

Describe the problem this feature would solve

DropShadowPanel only supports obtaining an alpha mask from certain types of content (Image, Shape, TextBlock, and ImageEx). If you try to use content such as a Grid or Border that has either a background brush or border brush with rounded corners, you do not get a matching drop shadow. You can substitute a Rectangle to get rounded corners, however Rectangles don't stretch and must be a fixed size which can introduce UI design difficulties. Also if you want a translucent brush then the reduced opaqueness you set on the content will be applied to the drop shadow. Having semi-opaque content while also having a clearly defined dropshadow is basically not possible. On top of this, if you add an AcrylicBrush it fails and reverts to a fallback solid color.

Describe the solution

I've created an extended control which doesn't affect the existing functionality for Image, Shape, TextBlock, and ImageEx. When the content is a Grid or Border, a matching CompositionRoundedRectangleGeometry is generated. This is used to create a SpriteShape, which is added to a ShapeVisual, which is used to create a CompositionSurfaceBrush to provide the dropshadow mask. The Size, Fill, Stroke, and CornerRadius are mapped and updated accordingly.

The same support can be added for StackPanel, RelativePanel, etc. I'm more than happy to submit a pull request.

Additional context & Screenshots

Here's a screenshot of what my extended version of DropShadowPanel can do that the original cannot:
Screenshot 2020-12-04 142631

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions