static void OnSelectedPaletteColorChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ColorPropertyEditor editor = obj as ColorPropertyEditor;

            if (editor != null)
            {
                if (editor.SelectedPaletteColor == null || editor.Color == editor.SelectedPaletteColor.Color)
                {
                    // Color already matches; must auto-set to ensure our value becomes the palette color object
                    editor.AutoSetValue();
                }
                else
                {
                    // Since the color needs to change, let it auto-set the value
                    editor.Color = editor.SelectedPaletteColor.Color;
                }
            }
        }
        static void OnComponentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ColorPropertyEditor editor = obj as ColorPropertyEditor;

            if (editor != null)
            {
                if (!editor.autoSettingComponents)
                {
                    editor.autoSettingColor = true;
                    editor.Color            = Color.FromArgb(editor.A, editor.R, editor.G, editor.B);
                    editor.autoSettingColor = false;

                    editor.autoSettingComponents = true;
                    editor.GrayScale             = (byte)(((int)editor.R + editor.G + editor.B) / 3);
                    editor.autoSettingComponents = false;
                }
            }
        }
        static void OnGrayScaleChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ColorPropertyEditor editor = obj as ColorPropertyEditor;

            if (editor != null)
            {
                if (!editor.autoSettingComponents)
                {
                    editor.autoSettingColor = true;
                    editor.Color            = Color.FromArgb(editor.A, editor.GrayScale, editor.GrayScale, editor.GrayScale);
                    editor.autoSettingColor = false;

                    editor.autoSettingComponents = true;
                    editor.R = editor.GrayScale;
                    editor.G = editor.GrayScale;
                    editor.B = editor.GrayScale;
                    editor.autoSettingComponents = false;
                }
            }
        }
        static void OnColorChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ColorPropertyEditor editor = obj as ColorPropertyEditor;

            if (editor != null)
            {
                editor.Brush = new SolidColorBrush(editor.Color);
                editor.AutoSetValue();

                if (!editor.autoSettingColor)
                {
                    editor.autoSettingComponents = true;
                    editor.R                     = editor.Color.R;
                    editor.G                     = editor.Color.G;
                    editor.B                     = editor.Color.B;
                    editor.A                     = editor.Color.A;
                    editor.GrayScale             = (byte)(((int)editor.R + editor.G + editor.B) / 3);
                    editor.autoSettingComponents = false;
                }
            }
        }