Skip to content

Commit

Permalink
Merge pull request #4107 from arcadiogarcia/user/arcadiog/dropShadowMask
Browse files Browse the repository at this point in the history
Add custom alpha mask support to DropShadowPanel
  • Loading branch information
michael-hawker authored Jul 23, 2021
2 parents 00ce2f4 + 99ce32a commit d863f11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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();
}
}

0 comments on commit d863f11

Please sign in to comment.