Skip to content

Commit d863f11

Browse files
Merge pull request #4107 from arcadiogarcia/user/arcadiog/dropShadowMask
Add custom alpha mask support to DropShadowPanel
2 parents 00ce2f4 + 99ce32a commit d863f11

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Core/DropShadowPanel/DropShadowPanel.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System;
66
using System.Numerics;
7-
using System.Threading.Tasks;
87
using Windows.UI;
98
using Windows.UI.Composition;
109
using Windows.UI.Xaml;
@@ -168,7 +167,13 @@ private void UpdateShadowMask()
168167
{
169168
CompositionBrush mask = null;
170169

171-
if (Content is Image)
170+
// We check for IAlphaMaskProvider first, to ensure that we use the custom
171+
// alpha mask even if Content happens to extend any of the other classes
172+
if (Content is IAlphaMaskProvider maskedControl)
173+
{
174+
mask = maskedControl.GetAlphaMask();
175+
}
176+
else if (Content is Image)
172177
{
173178
mask = ((Image)Content).GetAlphaMask();
174179
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Windows.UI.Composition;
6+
7+
namespace Microsoft.Toolkit.Uwp.UI
8+
{
9+
/// <summary>
10+
/// Any user control can implement this interface to provide a custom alpha mask to it's parent DropShadowPanel
11+
/// </summary>
12+
public interface IAlphaMaskProvider
13+
{
14+
/// <summary>
15+
/// This method should return the appropiate alpha mask to be used in the shadow of this control
16+
/// </summary>
17+
/// <returns>The alpha mask as a composition brush</returns>
18+
CompositionBrush GetAlphaMask();
19+
}
20+
}

0 commit comments

Comments
 (0)