private static void OnColorChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) {//此处不会触发OnColorRBGChanged,造成递归 Color newColor = (Color)e.NewValue; Color oldColor = (Color)e.OldValue; UCColorPicker ucColorPicker = (UCColorPicker)sender; ucColorPicker.Red = newColor.R; ucColorPicker.Green = newColor.G; ucColorPicker.Blue = newColor.B; RoutedPropertyChangedEventArgs <Color> args = new RoutedPropertyChangedEventArgs <Color>(oldColor, newColor); args.RoutedEvent = UCColorPicker.ColorChangedEvent; ucColorPicker.RaiseEvent(args); }
private static void OnColorRBGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { UCColorPicker ucColorPicker = (UCColorPicker)sender; Color color = ucColorPicker.Color; if (e.Property == RedProperty) { color.R = (byte)e.NewValue; } if (e.Property == GreenProperty) { color.G = (byte)e.NewValue; } if (e.Property == BlueProperty) { color.B = (byte)e.NewValue; } ucColorPicker.Color = color; }