Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Update Glow Brush when Theme brush color change
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenveo committed Jan 2, 2023
1 parent 1cd7c3b commit 6652255
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,43 @@ public sealed class CustomizeGlowWindowAttach
{
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.RegisterAttached("IsActive", typeof(bool),
typeof(CustomizeGlowWindowAttach), new PropertyMetadata(false, OnIsActiveChangedCallback));
typeof(CustomizeGlowWindowAttach), new FrameworkPropertyMetadata(false, OnIsActiveChangedCallback));

public static readonly DependencyProperty GlowBrushProperty =
DependencyProperty.RegisterAttached("GlowBrush", typeof(SolidColorBrush),
typeof(CustomizeGlowWindowAttach), new FrameworkPropertyMetadata(Brushes.Transparent,
FrameworkPropertyMetadataOptions.AffectsRender));
FrameworkPropertyMetadataOptions.AffectsRender, OnGlowBrushChangedCallback));

public static readonly DependencyProperty NonActiveGlowBrushProperty =
DependencyProperty.RegisterAttached("NonActiveGlowBrush", typeof(SolidColorBrush),
typeof(CustomizeGlowWindowAttach), new FrameworkPropertyMetadata(Brushes.Transparent,
FrameworkPropertyMetadataOptions.AffectsRender));
FrameworkPropertyMetadataOptions.AffectsRender, OnGlowBrushChangedCallback));

private static void OnIsActiveChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Window && e.NewValue is bool b)
if (d is Window window && e.NewValue is bool b)
{
var brush = b ? GetGlowBrush(d) : GetNonActiveGlowBrush(d);
UpdateGlowBrush(window, b);
}
}

d.GetOrAddBehavior(BehaviorFactory.CreateGlowWindowBehavior).GlowColor = brush.Color;
d.GetOrAddBehavior(BehaviorFactory.CreateGlowWindowBehavior).NonActiveGlowColor = brush.Color;
private static void OnGlowBrushChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Window window)
{
UpdateGlowBrush(window, GetIsActive(window));
}
}

private static void UpdateGlowBrush(Window window, bool isActive)
{
var brush = isActive ? GetGlowBrush(window) : GetNonActiveGlowBrush(window);

var glowWindowBehavior = window.GetOrAddBehavior(BehaviorFactory.CreateGlowWindowBehavior);
glowWindowBehavior.GlowColor = brush.Color;
glowWindowBehavior.NonActiveGlowColor = brush.Color;
}

public static bool GetIsActive(DependencyObject obj)
=> (bool)obj.GetValue(IsActiveProperty);

Expand Down

0 comments on commit 6652255

Please sign in to comment.