maui
maui copied to clipboard
[Windows] Fix shadows on shapes
Description of Change
Fix shadows on shapes in Windows.

The issue comes because all Shapes are drawn using a canvas and drawing with Maui Graphics. Actually, this is not a problem, but the following happens:

A Path (for example) is a W2dCanvasView (a canvas where we draw the Path). When applying the Shadow we are applying it to the native control, not to the internally drawn Shape. When applying the Shadow we are applying it to the native control, not to the internally drawn Shape.
Possible options:
- Initially it thought to use the Canvas itself to draw the Shadow but this is not going to be correct in all cases or we would have to increase the size of the Canvas to achieve a correct rendering of the Shadow in all cases but distorting the size of the View and causing layout problems. Discarded this option.
- Dynamically create a Path to use to get the AlphaMaska to use. It would have been great but it won't render anything if that Path isn't part of the visual tree. Discarded this option.
- Create a native Path and add it to the visual tree just behind the W2dCanvasView. This is the option that includes this PR. In simple tests related to performance the penalty (from include another element in the visual hierarchy) does not seem high but I definitely have to do more benchmarks.
- Another option would be to change the ShapeHandler to create native Shapes on Windows and not use the Canvas. NOTE: This options require more effort than this PR.
Feedback?
Issues Fixed
Fixes #8796
Hey Team, this PR is kept in Draft until we decide what to do, feedback?
@jsuarezruiz will this resolve the following issue as well? https://github.com/dotnet/maui/issues/10630
To help focus and move faster, we're going to have fewer open PRs and focus on the ones we'll be working on in each release. This PR is not included in the next release so I close it for now. I will reopen it and adapt to changes later.