/// <inheritdoc/> protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { if (change.Property == HsvColorProperty) { OnColorChanged(new ColorChangedEventArgs( change.GetOldValue <HsvColor>().ToRgb(), change.GetNewValue <HsvColor>().ToRgb())); } base.OnPropertyChanged(change); }
/// <inheritdoc/> protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { if (ignorePropertyChanged) { base.OnPropertyChanged(change); return; } // Always keep the two color properties in sync if (change.Property == ColorProperty) { ignorePropertyChanged = true; HsvColor = Color.ToHsv(); SetColorToHexTextBox(); OnColorChanged(new ColorChangedEventArgs( change.GetOldValue <Color>(), change.GetNewValue <Color>())); ignorePropertyChanged = false; } else if (change.Property == HsvColorProperty) { ignorePropertyChanged = true; Color = HsvColor.ToRgb(); SetColorToHexTextBox(); OnColorChanged(new ColorChangedEventArgs( change.GetOldValue <HsvColor>().ToRgb(), change.GetNewValue <HsvColor>().ToRgb())); ignorePropertyChanged = false; } else if (change.Property == PaletteProperty) { IColorPalette?palette = Palette; // Any custom palette change must be automatically synced with the // bound properties controlling the palette grid if (palette != null) { PaletteColumnCount = palette.ColorCount; List <Color> newPaletteColors = new List <Color>(); for (int shadeIndex = 0; shadeIndex < palette.ShadeCount; shadeIndex++) { for (int colorIndex = 0; colorIndex < palette.ColorCount; colorIndex++) { newPaletteColors.Add(palette.GetColor(colorIndex, shadeIndex)); } } PaletteColors = newPaletteColors; } } else if (change.Property == IsAlphaEnabledProperty) { // Manually coerce the HsvColor value // (Color will be coerced automatically if HsvColor changes) HsvColor = OnCoerceHsvColor(HsvColor); } else if (change.Property == IsColorComponentsVisibleProperty || change.Property == IsColorPaletteVisibleProperty || change.Property == IsColorSpectrumVisibleProperty) { // When the property changed notification is received here the visibility // of individual tab items has not yet been updated through the bindings. // Therefore, the validation is delayed until after bindings update. Dispatcher.UIThread.Post(() => { ValidateSelection(); }, DispatcherPriority.Background); } else if (change.Property == SelectedIndexProperty) { // Again, it is necessary to wait for the SelectedIndex value to // be applied to the TabControl through binding before validation occurs. Dispatcher.UIThread.Post(() => { ValidateSelection(); }, DispatcherPriority.Background); } base.OnPropertyChanged(change); }
/// <inheritdoc/> protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { if (ignorePropertyChanged) { base.OnPropertyChanged(change); return; } // Always keep the two color properties in sync if (change.Property == ColorProperty) { ignorePropertyChanged = true; HsvColor = Color.ToHsv(); SetColorToSliderValues(); UpdateBackground(); UpdatePseudoClasses(); OnColorChanged(new ColorChangedEventArgs( change.GetOldValue <Color>(), change.GetNewValue <Color>())); ignorePropertyChanged = false; } else if (change.Property == ColorModelProperty) { ignorePropertyChanged = true; SetColorToSliderValues(); UpdateBackground(); UpdatePseudoClasses(); ignorePropertyChanged = false; } else if (change.Property == HsvColorProperty) { ignorePropertyChanged = true; Color = HsvColor.ToRgb(); SetColorToSliderValues(); UpdateBackground(); UpdatePseudoClasses(); OnColorChanged(new ColorChangedEventArgs( change.GetOldValue <HsvColor>().ToRgb(), change.GetNewValue <HsvColor>().ToRgb())); ignorePropertyChanged = false; } else if (change.Property == IsRoundingEnabledProperty) { SetColorToSliderValues(); } else if (change.Property == BoundsProperty) { UpdateBackground(); } else if (change.Property == ValueProperty || change.Property == MinimumProperty || change.Property == MaximumProperty) { ignorePropertyChanged = true; Color oldColor = Color; (var color, var hsvColor) = GetColorFromSliderValues(); if (ColorModel == ColorModel.Hsva) { HsvColor = hsvColor; Color = hsvColor.ToRgb(); } else { Color = color; HsvColor = color.ToHsv(); } UpdatePseudoClasses(); OnColorChanged(new ColorChangedEventArgs(oldColor, Color)); ignorePropertyChanged = false; } base.OnPropertyChanged(change); }