Skip to content

Commit 9ac676b

Browse files
Sergio0694Arlodotexe
authored andcommitted
Enable 'AcrylicBrush' in WinUI 3 again
1 parent 4e7e574 commit 9ac676b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

components/Media/src/Brushes/AcrylicBrush.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if WINUI2
65
using CommunityToolkit.WinUI.Media.Pipelines;
6+
#if WINUI3
7+
using Microsoft.UI.Composition;
8+
#endif
79
using Windows.UI;
10+
#if WINUI2
811
using Windows.UI.Composition;
12+
#endif
913

1014
namespace CommunityToolkit.WinUI.Media;
1115

1216
/// <summary>
1317
/// A <see cref="XamlCompositionBrush"/> that implements an acrylic effect with customizable parameters
1418
/// </summary>
15-
public sealed class AcrylicBrush : XamlCompositionEffectBrushBase
19+
public sealed partial class AcrylicBrush : XamlCompositionEffectBrushBase
1620
{
1721
/// <summary>
1822
/// The <see cref="EffectSetter{T}"/> instance in use to set the blur amount
@@ -30,6 +34,7 @@ public sealed class AcrylicBrush : XamlCompositionEffectBrushBase
3034
/// </summary>
3135
private EffectSetter<float>? tintOpacitySetter;
3236

37+
#if WINUI2
3338
/// <summary>
3439
/// Gets or sets the background source mode for the effect (the default is <see cref="AcrylicBackgroundSource.Backdrop"/>).
3540
/// </summary>
@@ -62,6 +67,7 @@ private static void OnSourcePropertyChanged(DependencyObject d, DependencyProper
6267
brush.OnConnected();
6368
}
6469
}
70+
#endif
6571

6672
/// <summary>
6773
/// Gets or sets the blur amount for the effect (must be a positive value)
@@ -90,7 +96,9 @@ public double BlurAmount
9096
private static void OnBlurAmountPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
9197
{
9298
if (d is AcrylicBrush brush &&
99+
#if WINUI2
93100
brush.BackgroundSource != AcrylicBackgroundSource.HostBackdrop && // Blur is fixed by OS when using HostBackdrop source.
101+
#endif
94102
brush.CompositionBrush is CompositionBrush target)
95103
{
96104
brush.blurAmountSetter?.Invoke(target, (float)(double)e.NewValue);
@@ -197,6 +205,7 @@ private static void OnTextureUriPropertyChanged(DependencyObject d, DependencyPr
197205
/// <inheritdoc/>
198206
protected override PipelineBuilder OnPipelineRequested()
199207
{
208+
#if WINUI2
200209
switch (BackgroundSource)
201210
{
202211
case AcrylicBackgroundSource.Backdrop:
@@ -217,6 +226,15 @@ protected override PipelineBuilder OnPipelineRequested()
217226
TextureUri);
218227
default: throw new ArgumentOutOfRangeException(nameof(BackgroundSource), $"Invalid acrylic source: {BackgroundSource}");
219228
}
229+
#else
230+
return PipelineBuilder.FromBackdropAcrylic(
231+
TintColor,
232+
out this.tintColorSetter,
233+
(float)TintOpacity,
234+
out this.tintOpacitySetter,
235+
(float)BlurAmount,
236+
out blurAmountSetter,
237+
TextureUri);
238+
#endif
220239
}
221240
}
222-
#endif

0 commit comments

Comments
 (0)