diff --git a/RGB.NET.Brushes/Gradients/AbstractGradient.cs b/RGB.NET.Brushes/Gradients/AbstractGradient.cs
index 4cc0744..c32a0da 100644
--- a/RGB.NET.Brushes/Gradients/AbstractGradient.cs
+++ b/RGB.NET.Brushes/Gradients/AbstractGradient.cs
@@ -2,7 +2,10 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
+using System;
using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.ComponentModel;
using System.Linq;
using RGB.NET.Core;
@@ -36,13 +39,23 @@ namespace RGB.NET.Brushes.Gradients
#endregion
+ #region Events
+
+ ///
+ public event EventHandler GradientChanged;
+
+ #endregion
+
#region Constructors
///
/// Initializes a new instance of the class.
///
protected AbstractGradient()
- { }
+ {
+ GradientStops.CollectionChanged += GradientCollectionChanged;
+ PropertyChanged += (sender, args) => OnGradientChanged();
+ }
///
/// Initializes a new instance of the class.
@@ -50,6 +63,9 @@ namespace RGB.NET.Brushes.Gradients
/// The stops with which the gradient should be initialized.
protected AbstractGradient(params GradientStop[] gradientStops)
{
+ GradientStops.CollectionChanged += GradientCollectionChanged;
+ PropertyChanged += (sender, args) => OnGradientChanged();
+
foreach (GradientStop gradientStop in gradientStops)
GradientStops.Add(gradientStop);
}
@@ -63,6 +79,9 @@ namespace RGB.NET.Brushes.Gradients
{
this.WrapGradient = wrapGradient;
+ GradientStops.CollectionChanged += GradientCollectionChanged;
+ PropertyChanged += (sender, args) => OnGradientChanged();
+
foreach (GradientStop gradientStop in gradientStops)
GradientStops.Add(gradientStop);
}
@@ -106,6 +125,26 @@ namespace RGB.NET.Brushes.Gradients
gradientStop.Offset += 1;
}
+ ///
+ /// Should be called to indicate that the gradient was changed.
+ ///
+ protected void OnGradientChanged() => GradientChanged?.Invoke(this, null);
+
+ private void GradientCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
+ {
+ if (e.OldItems != null)
+ foreach (GradientStop gradientStop in e.OldItems)
+ gradientStop.PropertyChanged -= GradientStopChanged;
+
+ if (e.NewItems != null)
+ foreach (GradientStop gradientStop in e.NewItems)
+ gradientStop.PropertyChanged += GradientStopChanged;
+
+ OnGradientChanged();
+ }
+
+ private void GradientStopChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) => OnGradientChanged();
+
#endregion
}
}
diff --git a/RGB.NET.Brushes/Gradients/IGradient.cs b/RGB.NET.Brushes/Gradients/IGradient.cs
index 7ccc77f..590ba4c 100644
--- a/RGB.NET.Brushes/Gradients/IGradient.cs
+++ b/RGB.NET.Brushes/Gradients/IGradient.cs
@@ -1,4 +1,5 @@
-using RGB.NET.Core;
+using System;
+using RGB.NET.Core;
namespace RGB.NET.Brushes.Gradients
{
@@ -8,6 +9,11 @@ namespace RGB.NET.Brushes.Gradients
///
public interface IGradient : IDecoratable
{
+ ///
+ /// Occurs if the is changed.
+ ///
+ event EventHandler GradientChanged;
+
///
/// Gets the of the on the specified offset.
///
diff --git a/RGB.NET.Brushes/Gradients/RainbowGradient.cs b/RGB.NET.Brushes/Gradients/RainbowGradient.cs
index 8ecb057..b99a87a 100644
--- a/RGB.NET.Brushes/Gradients/RainbowGradient.cs
+++ b/RGB.NET.Brushes/Gradients/RainbowGradient.cs
@@ -1,6 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
+using System;
using RGB.NET.Core;
namespace RGB.NET.Brushes.Gradients
@@ -37,6 +38,13 @@ namespace RGB.NET.Brushes.Gradients
#endregion
+ #region Events
+
+ ///
+ public event EventHandler GradientChanged;
+
+ #endregion
+
#region Constructors
///
@@ -48,6 +56,8 @@ namespace RGB.NET.Brushes.Gradients
{
this.StartHue = startHue;
this.EndHue = endHue;
+
+ PropertyChanged += (sender, args) => OnGradientChanged();
}
#endregion
@@ -90,6 +100,11 @@ namespace RGB.NET.Brushes.Gradients
}
}
+ ///
+ /// Should be called to indicate that the gradient was changed.
+ ///
+ protected void OnGradientChanged() => GradientChanged?.Invoke(this, null);
+
#endregion
}
}