From 0eed37f5951fb9569ce53b66407edf0c387e210b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 14 Jun 2019 16:28:31 +0200 Subject: [PATCH] Added IsEnabled property to the acrylic brushes --- .../Base/XamlCompositionEffectBrushBase.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/UICompositionAnimations/Brushes/Base/XamlCompositionEffectBrushBase.cs b/UICompositionAnimations/Brushes/Base/XamlCompositionEffectBrushBase.cs index a967254..7bc90b1 100644 --- a/UICompositionAnimations/Brushes/Base/XamlCompositionEffectBrushBase.cs +++ b/UICompositionAnimations/Brushes/Base/XamlCompositionEffectBrushBase.cs @@ -22,12 +22,28 @@ public abstract class XamlCompositionEffectBrushBase : XamlCompositionBrushBase [MustUseReturnValue, NotNull] protected abstract PipelineBuilder OnBrushRequested(); + private bool _IsEnabled = true; + + /// + /// Gest or sets whether or not the current brush is using the provided pipeline, or the fallback color + /// + public bool IsEnabled + { + get => _IsEnabled; + set => OnEnabledToggled(value); + } + /// protected override async void OnConnected() { using (await ConnectedMutex.LockAsync()) + { if (CompositionBrush == null) - CompositionBrush = await OnBrushRequested().BuildAsync(); + { + if (_IsEnabled) CompositionBrush = await OnBrushRequested().BuildAsync(); + else CompositionBrush = await PipelineBuilder.FromColor(FallbackColor).BuildAsync(); + } + } base.OnConnected(); } @@ -44,5 +60,24 @@ protected override async void OnDisconnected() } base.OnDisconnected(); } + + /// + /// Updates the property depending on the input value + /// + /// The new value being set to the property + protected async void OnEnabledToggled(bool value) + { + using (await ConnectedMutex.LockAsync()) + { + if (_IsEnabled == value) return; + _IsEnabled = value; + + if (CompositionBrush != null) + { + if (_IsEnabled) CompositionBrush = await OnBrushRequested().BuildAsync(); + else CompositionBrush = await PipelineBuilder.FromColor(FallbackColor).BuildAsync(); + } + } + } } }