| 714 | } |
| 715 | |
| 716 | void ColorPicker::OnDispatcherQueueTimerTick(const IInspectable &, const IInspectable &) |
| 717 | { |
| 718 | if (m_UpdatedRgbColor) |
| 719 | { |
| 720 | const auto newColor = *m_UpdatedRgbColor; |
| 721 | |
| 722 | // Clear first to avoid timing issues if it takes longer than the timer interval to set the new color |
| 723 | m_UpdatedRgbColor.reset(); |
| 724 | |
| 725 | // An equality check here is important |
| 726 | // Without it, OnColorChanged would continuously be invoked and preserveHsvColor overwritten when not wanted |
| 727 | if (newColor != Color()) |
| 728 | { |
| 729 | // Disable events here so the color update isn't repeated as other controls in the UI are updated through binding. |
| 730 | // For example, the Spectrum should be bound to Color, as soon as Color is changed here the Spectrum is updated. |
| 731 | // Then however, the ColorSpectrum.ColorChanged event would fire which would schedule a new color update -- |
| 732 | // with the same color. This causes several problems: |
| 733 | // 1. Layout cycle that may crash the app |
| 734 | // 2. A performance hit recalculating for no reason |
| 735 | // 3. preserveHsvColor gets overwritten unexpectedly by the ColorChanged handler |
| 736 | ConnectEvents(false); |
| 737 | UpdateColorRightNow(newColor, m_UpdateFromSpectrum); |
| 738 | ConnectEvents(true); |
| 739 | } |
| 740 | |
| 741 | m_UpdateFromSpectrum = false; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | void ColorPicker::OnXamlRootChanged(const wux::XamlRoot &, const wux::XamlRootChangedEventArgs &) |
| 746 | { |