Skip to content

Commit

Permalink
Added IsEnabled property to the acrylic brushes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jun 14, 2019
1 parent 4ceb64a commit 0eed37f
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,28 @@ public abstract class XamlCompositionEffectBrushBase : XamlCompositionBrushBase
[MustUseReturnValue, NotNull]
protected abstract PipelineBuilder OnBrushRequested();

private bool _IsEnabled = true;

/// <summary>
/// Gest or sets whether or not the current brush is using the provided pipeline, or the fallback color
/// </summary>
public bool IsEnabled
{
get => _IsEnabled;
set => OnEnabledToggled(value);
}

/// <inheritdoc/>
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();
}

Expand All @@ -44,5 +60,24 @@ protected override async void OnDisconnected()
}
base.OnDisconnected();
}

/// <summary>
/// Updates the <see cref="XamlCompositionBrushBase.CompositionBrush"/> property depending on the input value
/// </summary>
/// <param name="value">The new value being set to the <see cref="IsEnabled"/> property</param>
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();
}
}
}
}
}

0 comments on commit 0eed37f

Please sign in to comment.