protected override void OnPropertyChanged()

in src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.cs [396:530]


        protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
        {
            if (change.Property == ColorProperty)
            {
                // If we're in the process of internally updating the color,
                // then we don't want to respond to the Color property changing.
                if (!_updatingColor)
                {
                    Color color = Color;

                    _updatingHsvColor = true;
                    Hsv newHsv = (new Rgb(color)).ToHsv();
                    SetCurrentValue(HsvColorProperty, newHsv.ToHsvColor(color.A / 255.0));
                    _updatingHsvColor = false;

                    UpdateEllipse();
                    UpdateBitmapSources();
                }

                _oldColor = change.GetOldValue<Color>();
            }
            else if (change.Property == HsvColorProperty)
            {
                // If we're in the process of internally updating the HSV color,
                // then we don't want to respond to the HsvColor property changing.
                if (!_updatingHsvColor)
                {
                    SetColor();
                }

                _oldHsvColor = change.GetOldValue<HsvColor>();
            }
            else if (change.Property == MinHueProperty ||
                     change.Property == MaxHueProperty)
            {
                int minHue = MinHue;
                int maxHue = MaxHue;

                if (minHue < 0 || minHue > 359)
                {
                    throw new ArgumentException("MinHue must be between 0 and 359.");
                }
                else if (maxHue < 0 || maxHue > 359)
                {
                    throw new ArgumentException("MaxHue must be between 0 and 359.");
                }

                ColorSpectrumComponents components = Components;

                // If hue is one of the axes in the spectrum bitmap, then we'll need to regenerate it
                // if the maximum or minimum value has changed.
                if (components != ColorSpectrumComponents.SaturationValue &&
                    components != ColorSpectrumComponents.ValueSaturation)
                {
                    CreateBitmapsAndColorMap();
                }
            }
            else if (change.Property == MinSaturationProperty ||
                     change.Property == MaxSaturationProperty)
            {
                int minSaturation = MinSaturation;
                int maxSaturation = MaxSaturation;

                if (minSaturation < 0 || minSaturation > 100)
                {
                    throw new ArgumentException("MinSaturation must be between 0 and 100.");
                }
                else if (maxSaturation < 0 || maxSaturation > 100)
                {
                    throw new ArgumentException("MaxSaturation must be between 0 and 100.");
                }

                ColorSpectrumComponents components = Components;

                // If value is one of the axes in the spectrum bitmap, then we'll need to regenerate it
                // if the maximum or minimum value has changed.
                if (components != ColorSpectrumComponents.HueValue &&
                    components != ColorSpectrumComponents.ValueHue)
                {
                    CreateBitmapsAndColorMap();
                }
            }
            else if (change.Property == MinValueProperty ||
                     change.Property == MaxValueProperty)
            {
                int minValue = MinValue;
                int maxValue = MaxValue;

                if (minValue < 0 || minValue > 100)
                {
                    throw new ArgumentException("MinValue must be between 0 and 100.");
                }
                else if (maxValue < 0 || maxValue > 100)
                {
                    throw new ArgumentException("MaxValue must be between 0 and 100.");
                }

                ColorSpectrumComponents components = Components;

                // If value is one of the axes in the spectrum bitmap, then we'll need to regenerate it
                // if the maximum or minimum value has changed.
                if (components != ColorSpectrumComponents.HueSaturation &&
                    components != ColorSpectrumComponents.SaturationHue)
                {
                    CreateBitmapsAndColorMap();
                }
            }
            else if (change.Property == ShapeProperty)
            {
                CreateBitmapsAndColorMap();
            }
            else if (change.Property == ComponentsProperty)
            {
                // Calculate and update the ThirdComponent value
                switch (Components)
                {
                    case ColorSpectrumComponents.HueSaturation:
                    case ColorSpectrumComponents.SaturationHue:
                        ThirdComponent = (ColorComponent)HsvComponent.Value;
                        break;
                    case ColorSpectrumComponents.HueValue:
                    case ColorSpectrumComponents.ValueHue:
                        ThirdComponent = (ColorComponent)HsvComponent.Saturation;
                        break;
                    case ColorSpectrumComponents.SaturationValue:
                    case ColorSpectrumComponents.ValueSaturation:
                        ThirdComponent = (ColorComponent)HsvComponent.Hue;
                        break;
                }

                CreateBitmapsAndColorMap();
            }

            base.OnPropertyChanged(change);
        }