2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
- #if WINUI2
6
5
using CommunityToolkit . WinUI . Media . Pipelines ;
6
+ #if WINUI3
7
+ using Microsoft . UI . Composition ;
8
+ #endif
7
9
using Windows . UI ;
10
+ #if WINUI2
8
11
using Windows . UI . Composition ;
12
+ #endif
9
13
10
14
namespace CommunityToolkit . WinUI . Media ;
11
15
12
16
/// <summary>
13
17
/// A <see cref="XamlCompositionBrush"/> that implements an acrylic effect with customizable parameters
14
18
/// </summary>
15
- public sealed class AcrylicBrush : XamlCompositionEffectBrushBase
19
+ public sealed partial class AcrylicBrush : XamlCompositionEffectBrushBase
16
20
{
17
21
/// <summary>
18
22
/// The <see cref="EffectSetter{T}"/> instance in use to set the blur amount
@@ -30,6 +34,7 @@ public sealed class AcrylicBrush : XamlCompositionEffectBrushBase
30
34
/// </summary>
31
35
private EffectSetter < float > ? tintOpacitySetter ;
32
36
37
+ #if WINUI2
33
38
/// <summary>
34
39
/// Gets or sets the background source mode for the effect (the default is <see cref="AcrylicBackgroundSource.Backdrop"/>).
35
40
/// </summary>
@@ -62,6 +67,7 @@ private static void OnSourcePropertyChanged(DependencyObject d, DependencyProper
62
67
brush . OnConnected ( ) ;
63
68
}
64
69
}
70
+ #endif
65
71
66
72
/// <summary>
67
73
/// Gets or sets the blur amount for the effect (must be a positive value)
@@ -90,7 +96,9 @@ public double BlurAmount
90
96
private static void OnBlurAmountPropertyChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
91
97
{
92
98
if ( d is AcrylicBrush brush &&
99
+ #if WINUI2
93
100
brush . BackgroundSource != AcrylicBackgroundSource . HostBackdrop && // Blur is fixed by OS when using HostBackdrop source.
101
+ #endif
94
102
brush . CompositionBrush is CompositionBrush target )
95
103
{
96
104
brush . blurAmountSetter ? . Invoke ( target , ( float ) ( double ) e . NewValue ) ;
@@ -197,6 +205,7 @@ private static void OnTextureUriPropertyChanged(DependencyObject d, DependencyPr
197
205
/// <inheritdoc/>
198
206
protected override PipelineBuilder OnPipelineRequested ( )
199
207
{
208
+ #if WINUI2
200
209
switch ( BackgroundSource )
201
210
{
202
211
case AcrylicBackgroundSource . Backdrop :
@@ -217,6 +226,15 @@ protected override PipelineBuilder OnPipelineRequested()
217
226
TextureUri ) ;
218
227
default : throw new ArgumentOutOfRangeException ( nameof ( BackgroundSource ) , $ "Invalid acrylic source: { BackgroundSource } ") ;
219
228
}
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
220
239
}
221
240
}
222
- #endif
0 commit comments