Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Numerics;
using System.Threading.Tasks;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Xaml;
Expand Down Expand Up @@ -168,7 +167,13 @@ private void UpdateShadowMask()
{
CompositionBrush mask = null;

if (Content is Image)
// We check for IAlphaMaskProvider first, to ensure that we use the custom
// alpha mask even if Content happens to extend any of the other classes
if (Content is IAlphaMaskProvider maskedControl)
{
mask = maskedControl.GetAlphaMask();
}
else if (Content is Image)
{
mask = ((Image)Content).GetAlphaMask();
}
Expand Down
20 changes: 20 additions & 0 deletions Microsoft.Toolkit.Uwp.UI/Helpers/IAlphaMaskProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Windows.UI.Composition;

namespace Microsoft.Toolkit.Uwp.UI
{
/// <summary>
/// Any user control can implement this interface to provide a custom alpha mask to it's parent DropShadowPanel
/// </summary>
public interface IAlphaMaskProvider
{
/// <summary>
/// This method should return the appropiate alpha mask to be used in the shadow of this control
/// </summary>
/// <returns>The alpha mask as a composition brush</returns>
CompositionBrush GetAlphaMask();
}
}