CommunityToolkit / WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/communitytoolkit/
Other
5.87k stars 1.37k forks source link

[Feature] Developers should be able to provide custom AlphaMasks to DropShadowPanel for their controls #3693

Closed arcadiogarcia closed 3 years ago

arcadiogarcia commented 3 years ago

Describe the problem this feature would solve

Currently it is impossible to use DropShadowPanel to project masked shadows for custom usercontrols, since GetAlphaMask is only implemented in a handful of framework controls (Image, Shape, TextBlock) the DropShadowPanel only attempts to get an alpha mask if the Content is an instance of those types.

This is especially painful if you need to wrap all your Images/Shapes/Text in some other control, since ideally you would just "pass through" the alpha mask provided by the native control.

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/0d43da7ae459d000ee29dcb108cc08a56bf5073f/Microsoft.Toolkit.Uwp.UI.Controls/DropShadowPanel/DropShadowPanel.cs#L171

Describe the solution

Solution A:

To allow developers to leverage DropShadowPanel for their own controls, we could define an interface e.g.

interface IAlphaMask
{
     CompositionBrush GetAlphaMask();
}

that they can implement to specify which alpha mask they want to be used, and DropShadowPanel would recognize it and use the right mask.

Solution B:

DropShadowPanel could have a SetContentAlphaMask method that allows the developer to provide alpha masks. This alpha mask would override the one that is provided by the content control, if it has one. This would be very useful to create non-rectangular shadows (e.g. with round corners) for existing framework elements (e.g. grid, inkcanvas...).

I think both solutions would be worth having in the control, I have been in many situations where I would have used them if they were available.

I'm happy to contribute this if it sounds valuable :)

ghost commented 3 years ago

Hello, 'arcadiogarcia! Thanks for submitting a new feature request. I've automatically added a vote 👍 reaction to help get things started. Other community members can vote to help us prioritize this feature in the future!

Kyaa-dost commented 3 years ago

@arcadiogarcia Thanks for the detailed info and for taking an initiative on this feature. I am going to open this up for discussion and see what other community members think and then you can proceed to open the PR 🚀

michael-hawker commented 3 years ago

Thanks @arcadiogarcia we definitely want to make some improvements to this control, it's just fallen out-of-scope for 7.0. I believe @JustinXinLiu may have a fork he's done some work on too (which may overlap), so we should all coordinate. 🙂

Part of what I was going to look at is inverting the relationship so it's not a panel anymore, so I'll definitely make sure to expose it in anything new. But there could still be improvements we could make in the meantime until that new thing is put together (if it works that is).

@JustinXinLiu any details you can provide us, or is your code in a fork somewhere? Maybe we can use that as a starting point for further improvements from @arcadiogarcia at least?

michael-hawker commented 3 years ago

(Sorry, hit the wrong button by mistake...)

arcadiogarcia commented 3 years ago

This is the fork I've been using myself; I'd be happy to contribute it as a temporary solution: #4107

arcadiogarcia commented 3 years ago

Closing this now that the PR has been merged :)

michael-hawker commented 3 years ago

I was leaving it open so we remember to add support for this on our new shadows too 😉