Beispiel #1
0
        private static void OnSelectedColorChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            // Debug.WriteLine("OnSelectedColorChanged");

            SmallColorPicker cp = obj as SmallColorPicker;

            Debug.Assert(cp != null);

            Color newColor = (Color)args.NewValue;
            Color oldColor = (Color)args.OldValue;

            if (newColor == oldColor)
            {
                return;
            }

            // When the SelectedColor changes, set the selected value of the combo box
            if (cp.Picker.SelectedValue == null || (Color)cp.Picker.SelectedValue != newColor)
            {
                // Add the color if not found
                if (!cp.Picker.Items.Contains(newColor))
                {
                    cp.Picker.Items.Add(newColor);
                }
            }

            // Also update the brush
            cp.SelectedBrush = new SolidColorBrush(newColor);

            cp.OnColorChanged(oldColor, newColor);
        }
Beispiel #2
0
        private static void OnSelectedBrushChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            // Debug.WriteLine("OnSelectedBrushChanged");
            SmallColorPicker cp       = (SmallColorPicker)obj;
            SolidColorBrush  newBrush = (SolidColorBrush)args.NewValue;

            // SolidColorBrush oldBrush = (SolidColorBrush)args.OldValue;

            if (cp.SelectedColor != newBrush.Color)
            {
                cp.SelectedColor = newBrush.Color;
            }
        }