Beispiel #1
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            colorPanel = (ColorPanel)GetTemplateChild("CP1");
            colorPanel.SelectedColor         = SelectedColor;
            colorPanel.SelectedColorChanged -= new System.EventHandler <SelectedColorChangedColorPanelEventArgs>(colorPanel_SelectedColorChanged);
            colorPanel.SelectedColorChanged += new System.EventHandler <SelectedColorChangedColorPanelEventArgs>(colorPanel_SelectedColorChanged);

            slA = (Slider)GetTemplateChild("slA");
            slR = (Slider)GetTemplateChild("slR");
            slG = (Slider)GetTemplateChild("slG");
            slB = (Slider)GetTemplateChild("slB");
            slH = (Slider)GetTemplateChild("slH");
            slS = (Slider)GetTemplateChild("slS");
            slL = (Slider)GetTemplateChild("slL");

            slA.ValueChanged -= new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slR.ValueChanged -= new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slG.ValueChanged -= new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slB.ValueChanged -= new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slH.ValueChanged -= new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slS.ValueChanged -= new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slL.ValueChanged -= new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);

            slA.ValueChanged += new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slR.ValueChanged += new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slG.ValueChanged += new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slB.ValueChanged += new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slH.ValueChanged += new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slS.ValueChanged += new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);
            slL.ValueChanged += new RoutedPropertyChangedEventHandler <double>(Slider_ValueChanged);

            nA = (Numeric)GetTemplateChild("nA");
            nR = (Numeric)GetTemplateChild("nR");
            nG = (Numeric)GetTemplateChild("nG");
            nB = (Numeric)GetTemplateChild("nB");
            nH = (Numeric)GetTemplateChild("nH");
            nS = (Numeric)GetTemplateChild("nS");
            nL = (Numeric)GetTemplateChild("nL");

            nA.ValueChanged -= new RoutedEventHandler(Numeric_ValueChanged);
            nR.ValueChanged -= new RoutedEventHandler(Numeric_ValueChanged);
            nG.ValueChanged -= new RoutedEventHandler(Numeric_ValueChanged);
            nB.ValueChanged -= new RoutedEventHandler(Numeric_ValueChanged);
            nH.ValueChanged -= new RoutedEventHandler(Numeric_ValueChanged);
            nS.ValueChanged -= new RoutedEventHandler(Numeric_ValueChanged);
            nL.ValueChanged -= new RoutedEventHandler(Numeric_ValueChanged);

            nA.ValueChanged += new RoutedEventHandler(Numeric_ValueChanged);
            nR.ValueChanged += new RoutedEventHandler(Numeric_ValueChanged);
            nG.ValueChanged += new RoutedEventHandler(Numeric_ValueChanged);
            nB.ValueChanged += new RoutedEventHandler(Numeric_ValueChanged);
            nH.ValueChanged += new RoutedEventHandler(Numeric_ValueChanged);
            nS.ValueChanged += new RoutedEventHandler(Numeric_ValueChanged);
            nL.ValueChanged += new RoutedEventHandler(Numeric_ValueChanged);

            OnPropertyChanged("SelectedColor");
            //SyncWithColor(SelectedColor);
        }
        private static void SelectedColorPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            Color      newColor   = (Color)e.NewValue;
            ColorPanel colorPanel = (ColorPanel)sender;

            colorPanel.OnSelectedColorChanged((Color)e.NewValue, (Color)e.OldValue);

            if (colorPanel.repositeThread != null && colorPanel.colorSourceMatrix != null)
            {
                colorPanel.repositeThread.CancelAsync();
                while (colorPanel.repositeThread.IsBusy)
                {
                    System.Windows.Forms.Application.DoEvents();
                }

                if (!colorPanel.isColorChangedByMouse)
                {
                    Tuple <Color, double, double> parameters = new Tuple <Color, double, double>(colorPanel.SelectedColor, colorPanel.bitmapSource.Width, colorPanel.bitmapSource.Height);
                    colorPanel.repositeThread.RunWorkerAsync(parameters);
                }
                colorPanel.isColorChangedByMouse = false;
            }
        }