MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

ColorPicker doesn't triger color Change event after color change from UI

Open flamaniac opened this issue 6 years ago • 4 comments

After clicking on UI on new color event doesn't trigger

 ColorPicker.ColorChanged += ColorPicker_ColorChanged;
 private void ColorPicker_ColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> e)
{
  // never triggered 
}

flamaniac avatar Jan 31 '20 22:01 flamaniac

You are right, it is only triggered if the color property is changed outside of the color picker.

@Keboo this is because if you change to color in the color picker, first the HsbPropertyChangedCallback is called, which sets _inCallback to true, but the ColorPropertyChangedCallback which fires the ColorChanged event then returns early because of this field beeing true. I seem to have overlooked that when making my PR (or something changed in between). I can make a PR to fix this and firing the event even if _inCallback istrue (it should not get called multiple times, right?)

Mrxx99 avatar Feb 01 '20 11:02 Mrxx99

I think multiple times - on every change not on Mouse Up. ColorPicker

I made workaround in my app to have this behavior and it works great. I call color getter on MouseMove Event. Mouse Move is called only when Mouse Left button and it suits me :) I am getting live upodate.

...
    ColorPicker.MouseMove += ColorPicker_MouseMove;
 }
 // ...
      private void ColorPicker_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
      {
          var items = ColorsList.Items;
          ColorItem item;
          for (int i = 0; i < items.Count; ++i)
          {
              item = (ColorItem)items[i];
              if (item.IsSelected)
              {
                  item.Color = ColorPicker.Color;
              }
          }
      }

flamaniac avatar Feb 01 '20 12:02 flamaniac

If you use binding you can also use the setter of the property bound to the Color property of the ColorPicker (that's how it is done in the Demo App)

Mrxx99 avatar Feb 01 '20 12:02 Mrxx99

@Keboo When I add raising event to every time the hsb value change callback is called the color tool get's very laggy. Do you have any idea how this could be done better? Maybe not using a routed event could improve it?

Mrxx99 avatar Feb 28 '20 21:02 Mrxx99