private static void ColorChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue == e.OldValue)
            {
                return;
            }

            HatchPicker hatchPicker = (HatchPicker)sender;

            if (hatchPicker.BitmapSources != null)
            {
                string selectedHatchStyleName = HatchStyle.BackwardDiagonal.ToString();
                if (hatchPicker.SelectedBitmapSource != null)
                {
                    selectedHatchStyleName = hatchPicker.SelectedBitmapSource.GetValue(Canvas.NameProperty).ToString();
                }

                HatchPicker.UpdatePatternSources(hatchPicker.BitmapSources, hatchPicker.PatternSize, hatchPicker.BackgroundColor, hatchPicker.ForegroundColor);
                if (hatchPicker.SelectedBitmapSource == null)
                {
                    hatchPicker.SelectedBitmapSource = hatchPicker.BitmapSources.FirstOrDefault(s => { return(s.GetValue(Canvas.NameProperty).Equals(selectedHatchStyleName)); });
                }
                else
                {
                    string oldHatchStyleName = hatchPicker.SelectedBitmapSource.GetValue(Canvas.NameProperty).ToString();
                    if (oldHatchStyleName != selectedHatchStyleName)
                    {
                        hatchPicker.SelectedBitmapSource = hatchPicker.BitmapSources.FirstOrDefault(s => { return(s.GetValue(Canvas.NameProperty).Equals(selectedHatchStyleName)); });
                    }
                }
            }
        }
Beispiel #2
0
        private void ChangeColorFromColorPicker(Control colorPicker, EventArgs e)
        {
            if (colorPicker is SolidColorPicker)
            {
                SolidColorPicker solidColorPicker = (SolidColorPicker)colorPicker;
                Color            newColor         = solidColorPicker.SelectedColor;
                GeoColor         newGeoColor      = GeoColor2MediaColorConverter.ConvertBack(newColor);

                hatchColorPicker.SyncBaseColor(DrawingColorToMediaColorConverter.ConvertBack(newColor));
                gradientPicker.SyncBaseColor(DrawingColorToMediaColorConverter.ConvertBack(newColor));

                SelectedBrush = new GeoSolidBrush(newGeoColor);
            }
            else if (colorPicker is HatchPicker)
            {
                HatchPicker hatchPicker = (HatchPicker)colorPicker;
                System.Drawing.Drawing2D.HatchStyle drawingHatchStyle = hatchPicker.SelectedHatchStyle;
                GeoHatchStyle geoHatchStyle = GeoHatchStyle2DrawingHatchStyle.ConvertBack(drawingHatchStyle);

                //solidColorPicker.SyncBaseColor(hatchPicker.ForegroundColor);
                gradientPicker.SyncBaseColor(hatchPicker.ForegroundColor);

                SelectedBrush = new GeoHatchBrush(geoHatchStyle, GeoColor2DrawingColorConverter.ConvertBack(hatchPicker.ForegroundColor)
                                                  , GeoColor2DrawingColorConverter.ConvertBack(hatchColorPicker.BackgroundColor));
            }
            else if (colorPicker is TexturePicker)
            {
                PropertyChangedEventArgs args          = (PropertyChangedEventArgs)e;
                TexturePicker            texturePicker = (TexturePicker)colorPicker;
                if (args.PropertyName == "SelectedBrush")
                {
                    ImageBrush mediaBrush = texturePicker.SelectedBrush as ImageBrush;
                    if (mediaBrush != null)
                    {
                        BitmapImage imageSource = (BitmapImage)mediaBrush.ImageSource;
                        if (imageSource != null)
                        {
                            SelectedBrush = new GeoTextureBrush(new GeoImage(imageSource.UriSource.LocalPath));
                        }
                    }
                }
            }
            else if (colorPicker is DrawingLinearGradientBrushPicker)
            {
                DrawingLinearGradientBrushPicker linearPicker = (DrawingLinearGradientBrushPicker)colorPicker;
                LinearGradientBrushEntity        brushEntity  = linearPicker.SelectedBrush;

                solidColorPicker.SyncBaseColor(brushEntity.StartColor);
                hatchColorPicker.SyncBaseColor(brushEntity.StartColor);

                SelectedBrush = new GeoLinearGradientBrush(GeoColor2DrawingColorConverter.ConvertBack(brushEntity.StartColor),
                                                           GeoColor2DrawingColorConverter.ConvertBack(brushEntity.EndColor),
                                                           brushEntity.Angle);
            }
        }
        private static void SelectedBitmapSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != null)
            {
                HatchPicker hatchPicker = (HatchPicker)sender;
                hatchPicker.OnPropertyChanged("SelectedHatchStyle");

                if (!hatchPicker.stopRaisingColorChangedEvent)
                {
                    hatchPicker.OnSelectionChanged();
                }
            }
        }
Beispiel #4
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            solidColorBrushTabItem = GetTemplateChild("SolidColorBrushTabItem") as TabItem;
            hatchBrushTabItem      = GetTemplateChild("HatchBrushTabItem") as TabItem;
            textureTabItem         = GetTemplateChild("TextureTabItem") as TabItem;
            gradientTabItem        = GetTemplateChild("GradientColorBrushTabItem") as TabItem;
            solidColorPicker       = GetTemplateChild("SolidColorPicker") as SolidColorPicker;
            textureColorPicker     = GetTemplateChild("TextureColorPicker") as TexturePicker;
            hatchColorPicker       = GetTemplateChild("HatchColorPicker") as HatchPicker;
            gradientPicker         = GetTemplateChild("GradientPicker") as DrawingLinearGradientBrushPicker;
            pickTextureButton      = GetTemplateChild("PickTextureButton") as Button;
            colorTabControl        = GetTemplateChild("ColorTabControl") as TabControl;
            customColorList        = GetTemplateChild("CustomColorList") as ListBox;
            helpContainer          = GetTemplateChild("HelpContainer") as ContentPresenter;
            addcutomColorButton    = GetTemplateChild("AddCustomColorButton") as Button;

            if (!isTemplateApplied)
            {
                solidColorPicker.IsEnabled   = IsSolidColorBrushTabEnabled;
                textureColorPicker.IsEnabled = IsTextureBrushTabEnabled;
                hatchColorPicker.IsEnabled   = IsHatchBrushTabEnabled;
                gradientPicker.IsEnabled     = IsGradientColorBrushTabEnabled;

                solidColorPicker.SelectionChanged   += new EventHandler(SolidColorPicker_SelectionChanged);
                hatchColorPicker.SelectionChanged   += new EventHandler(HatchColorPicker_SelectionChanged);
                textureColorPicker.PropertyChanged  += new PropertyChangedEventHandler(TextureColorPicker_PropertyChanged);
                gradientPicker.SelectedBrushChanged += new EventHandler(GradientPicker_SelectedBrushChanged);
                pickTextureButton.Click             += new RoutedEventHandler(PickTextureButton_Click);

                solidColorPicker.SelectedItemDoubleClick   += OnSelectedItemDoubleClick;
                hatchColorPicker.SelectedItemDoubleClick   += OnSelectedItemDoubleClick;
                textureColorPicker.SelectedItemDoubleClick += OnSelectedItemDoubleClick;

                solidColorPicker.ColorPanelMouseDoubleClick += new MouseButtonEventHandler(SolidColorPicker_ColorPanelMouseDoubleClick);
                customColorList.SelectionChanged            += new SelectionChangedEventHandler(CustomColorList_SelectionChanged);
                colorTabControl.SelectionChanged            += new SelectionChangedEventHandler(ColorTabControl_SelectionChanged);
                addcutomColorButton.Click += new RoutedEventHandler(AddcutomColorButton_Click);
                helpContainer.Content      = HelpResourceHelper.GetHelpButton("ColorPickerHelp", HelpButtonMode.IconWithLabel);

                defaultColors = CreateDefaultPalette();
                customColorList.ItemsSource = defaultColors;
                isTemplateApplied           = true;

                Loaded -= TabColorPicker_Loaded;
                Loaded += TabColorPicker_Loaded;
            }
        }