Gradient picker - Properly react to gradient changes once again

This commit is contained in:
Robert committed 2021-04-06 20:56:12 +02:00
1 parent b342eabe4d
commit 2bc882c814
4 files changed
+40 -19

No files matched your search

@@ -1,8 +1,10 @@
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.Core;
using Artemis.UI.Shared.Properties;
using Artemis.UI.Shared.Services;
@@ -17,12 +19,14 @@ namespace Artemis.UI.Shared
{
private static IColorPickerService? _colorPickerService;
private bool _inCallback;
private ColorGradientToGradientStopsConverter _gradientConverter;
/// <summary>
/// Creates a new instance of the <see cref="GradientPicker" /> class
/// </summary>
public GradientPicker()
{
_gradientConverter = new ColorGradientToGradientStopsConverter();
InitializeComponent();
}
@@ -99,10 +103,27 @@ namespace Artemis.UI.Shared
return;
gradientPicker._inCallback = true;
if (e.OldValue is ColorGradient oldGradient)
oldGradient.CollectionChanged -= gradientPicker.GradientChanged;
if (e.NewValue is ColorGradient newGradient)
newGradient.CollectionChanged += gradientPicker.GradientChanged;
gradientPicker.UpdateGradientStops();
gradientPicker.OnPropertyChanged(nameof(ColorGradient));
gradientPicker._inCallback = false;
}
private void GradientChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
Dispatcher.Invoke(UpdateGradientStops);
}
private void UpdateGradientStops()
{
GradientPreview.GradientStops = (GradientStopCollection)_gradientConverter.Convert(ColorGradient, null!, null!, null!);
}
private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (_colorPickerService == null)