Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/MaterialDesignThemes.Wpf/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public Color Color
private static void ColorPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var colorPicker = (ColorPicker)d;
if (colorPicker._inCallback)

if (!colorPicker._inCallback)
{
return;
colorPicker._inCallback = true;
colorPicker.SetCurrentValue(HsbProperty, ((Color)e.NewValue).ToHsb());
colorPicker._inCallback = false;
}

colorPicker._inCallback = true;
colorPicker.SetCurrentValue(HsbProperty, ((Color)e.NewValue).ToHsb());
var args = new RoutedPropertyChangedEventArgs<Color>(
(Color)e.OldValue,
(Color)e.NewValue)
{ RoutedEvent = ColorChangedEvent };
colorPicker.RaiseEvent(args);
colorPicker._inCallback = false;
}

public static readonly RoutedEvent ColorChangedEvent =
Expand Down
22 changes: 22 additions & 0 deletions tests/MaterialDesignThemes.Wpf.Tests/ColorPickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ public async Task SettingTheColorRaisesColorChangedEvent()
await Assert.That(wasRaised).IsTrue();
}

[Test]
public async Task ColorChangedShouldFireWhenColorIsChangedThroughHsb()
{
var colorPicker = new ColorPicker();

var called = false;
Color receivedColor = default;

colorPicker.ColorChanged += (_, args) =>
{
called = true;
receivedColor = args.NewValue;
};

colorPicker.SetCurrentValue(
ColorPicker.HsbProperty,
new Hsb(120, 1, 1));

await Assert.That(called).IsTrue();
await Assert.That(receivedColor).IsEqualTo(Colors.Lime);
}

[Test]
public async Task DraggingTheHueSliderChangesHue()
{
Expand Down