コード例 #1
0
ファイル: ColorPicker.cs プロジェクト: zyj0021/kaxaml
        public static void OnColorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ColorPicker c = (ColorPicker)o;


            if (e.NewValue is Color)
            {
                Color color = (Color)e.NewValue;

                if (!c.HSBSetInternally)
                {
                    // update HSB value based on new value of color

                    double H = 0;
                    double S = 0;
                    double B = 0;
                    ColorPickerUtil.HSBFromColor(color, ref H, ref S, ref B);

                    c.HSBSetInternally = true;

                    c.Alpha      = (double)(color.A / 255);
                    c.Hue        = H;
                    c.Saturation = S;
                    c.Brightness = B;

                    c.HSBSetInternally = false;
                }

                if (!c.RGBSetInternally)
                {
                    // update RGB value based on new value of color

                    c.RGBSetInternally = true;

                    c.A = color.A;
                    c.R = color.R;
                    c.G = color.G;
                    c.B = color.B;

                    c.RGBSetInternally = false;
                }

                c.RaiseColorChangedEvent((Color)e.NewValue);
            }
        }