Skip to content

Commit c0bf660

Browse files
NirmalKumarYuvarajPureWeen
authored andcommitted
[Windows] Fixed Shadow not updated when Clipping a View with a shadow (#27873)
* Fixed Shadow not updated when Clipping a View with a shadow * FIxed shadow not updating with vlip * Updated code changes * Updated testcase image * Updated test case * updated test case image * Added pending snapshots
1 parent bd31807 commit c0bf660

File tree

7 files changed

+110
-0
lines changed

7 files changed

+110
-0
lines changed
66.7 KB
Loading
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using Microsoft.Maui.Controls.Shapes;
2+
3+
namespace Maui.Controls.Sample.Issues
4+
{
5+
[Issue(IssueTracker.Github, 27730, "Shadow not updated when Clipping a View with a shadow", PlatformAffected.UWP)]
6+
public class Issue27730 : TestContentPage
7+
{
8+
Border _borderWithShadow;
9+
Border _normalBorder;
10+
11+
protected override void Init()
12+
{
13+
VerticalStackLayout rootLayout = new VerticalStackLayout
14+
{
15+
Spacing = 10,
16+
Padding = 10
17+
};
18+
19+
Label shadowLabel = new Label { Text = "Border with Shadow, Clipping applied at runtime" };
20+
Label clipLabel = new Label { Text = "Normal Border without shadow, Clipping first, Shadow added later" };
21+
22+
_borderWithShadow = CreateBorder(true);
23+
_normalBorder = CreateBorder(false);
24+
25+
Button applyClipButton = new Button { Text = "Apply Clip", AutomationId = "ApplyClipBtn" };
26+
Button applyShadowButton = new Button { Text = "Apply Shadow", AutomationId = "ApplyShadowBtn" };
27+
28+
applyClipButton.Clicked += (s, e) => ApplyClip();
29+
applyShadowButton.Clicked += (s, e) => ApplyShadow();
30+
31+
rootLayout.Add(shadowLabel);
32+
rootLayout.Add(_borderWithShadow);
33+
rootLayout.Add(clipLabel);
34+
rootLayout.Add(_normalBorder);
35+
rootLayout.Add(applyClipButton);
36+
rootLayout.Add(applyShadowButton);
37+
Content = rootLayout;
38+
}
39+
40+
Border CreateBorder(bool withShadow)
41+
{
42+
return new Border
43+
{
44+
StrokeShape = new RoundRectangle { CornerRadius = new CornerRadius(24) },
45+
Background = Colors.Red,
46+
WidthRequest = 100,
47+
HeightRequest = 100,
48+
Margin = new Thickness(12, 0),
49+
Shadow = withShadow ? new Shadow
50+
{
51+
Brush = Colors.Black,
52+
Offset = new Point(12, 12),
53+
Radius = 10,
54+
Opacity = 1
55+
} : null
56+
};
57+
}
58+
59+
void ApplyClip()
60+
{
61+
EllipseGeometry clipGeometry = new EllipseGeometry
62+
{
63+
Center = new Point(50, 50),
64+
RadiusX = 25,
65+
RadiusY = 25
66+
};
67+
68+
_borderWithShadow.Clip = clipGeometry;
69+
_normalBorder.Clip = clipGeometry;
70+
}
71+
72+
void ApplyShadow()
73+
{
74+
_normalBorder.Shadow = new Shadow
75+
{
76+
Brush = Colors.Black,
77+
Offset = new Point(12, 12),
78+
Radius = 10,
79+
Opacity = 1
80+
};
81+
}
82+
}
83+
}
26.7 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue27730 : _IssuesUITest
8+
{
9+
public Issue27730(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "Shadow not updated when Clipping a View with a shadow";
14+
15+
[Test]
16+
[Category(UITestCategories.Visual)]
17+
public void ShadowShouldUpdateWhenClipping()
18+
{
19+
App.WaitForElement("ApplyShadowBtn");
20+
App.Tap("ApplyClipBtn");
21+
App.Tap("ApplyShadowBtn");
22+
VerifyScreenshot();
23+
}
24+
}
25+
}
18.7 KB
Loading
68.6 KB
Loading

src/Core/src/Platform/Windows/WrapperView.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void UpdateClip()
121121
var geometricClip = compositor.CreateGeometricClip(pathGeometry);
122122

123123
visual.Clip = geometricClip;
124+
//When the clip is updated, the shadow must be updated as well
125+
UpdateShadowAsync().FireAndForget(IPlatformApplication.Current?.Services?.CreateLogger(nameof(WrapperView)));
124126
}
125127

126128
void DisposeClip()

0 commit comments

Comments
 (0)