private void SelectedBrush_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Angle")
            {
                double newAngle = SelectedBrush.Angle;
                double x2       = radius + radius * Math.Cos(newAngle * Math.PI / 180d);
                double y2       = radius - radius * Math.Sin(newAngle * Math.PI / 180d);

                if (stopAngleArrow != null)
                {
                    stopAngleArrow.X2 = x2;
                    stopAngleArrow.Y2 = y2;
                }
            }
            else if (e.PropertyName == "EndColor" && stopColorPanel != null)
            {
                stopColorPanel.Fill = DrawingColorToBrushConverter.Convert(SelectedBrush.EndColor);
            }
            else if (e.PropertyName == "StartColor" && stopColorPanel != null)
            {
                stopColorPanel.Fill = DrawingColorToBrushConverter.Convert(SelectedBrush.StartColor);
            }

            SetPreviewImage();
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            startArrow     = (Arrow)GetTemplateChild("StartArrow");
            endArrow       = (Arrow)GetTemplateChild("EndArrow");
            stopColorPanel = (System.Windows.Shapes.Rectangle)GetTemplateChild("StopColorPanel");
            alphaNumeric   = (Numeric)GetTemplateChild("nA");
            stopAnglePanel = (System.Windows.Shapes.Ellipse)GetTemplateChild("StopAnglePanel");
            stopAngleArrow = (System.Windows.Shapes.Line)GetTemplateChild("StopAngleArrow");
            SelectedBrush.PropertyChanged += new PropertyChangedEventHandler(SelectedBrush_PropertyChanged);

            alphaNumeric.ValueChanged += new RoutedEventHandler(alphaNumeric_ValueChanged);

            stopColorPanel.MouseLeftButtonUp += new MouseButtonEventHandler(ArrowDoubleClick);
            startArrow.MouseDoubleClick      += new MouseButtonEventHandler(ArrowDoubleClick);
            endArrow.MouseDoubleClick        += new MouseButtonEventHandler(ArrowDoubleClick);

            startArrow.MouseLeftButtonUp += new MouseButtonEventHandler(ArrowMouseUp);
            endArrow.MouseLeftButtonUp   += new MouseButtonEventHandler(ArrowMouseUp);

            stopAnglePanel.MouseDown += new MouseButtonEventHandler(Ellipse_MouseDown);
            stopAnglePanel.MouseMove += new MouseEventHandler(Ellipse_MouseMove);

            stopColorPanel.Fill = DrawingColorToBrushConverter.Convert(SelectedBrush.StartColor);
            alphaNumeric.Value  = SelectedBrush.StartColor.A;
            stopType            = StopType.Start;

            FillAngleArrow();
            //SetPreviewImage();
        }
 private void SetStopColor(Color color)
 {
     if (stopColorPanel != null)
     {
         stopColorPanel.Fill = DrawingColorToBrushConverter.Convert(color);
         alphaNumeric.Value  = color.A;
         OnSelectedBrushChanged();
     }
 }
        //private void ShowColorPickerHandler(object sender, MouseButtonEventArgs e)
        //{
        //    NormalColorPickerWindow window = new NormalColorPickerWindow();
        //    if (window.ShowDialog().GetValueOrDefault())
        //    {
        //        switch (stopType)
        //        {
        //            case StopType.Start:
        //                stopColorPanel.Fill = DrawingColorToBrushConverter.Convert(SelectedBrush.StartColor);
        //                break;
        //            case StopType.End:
        //                stopColorPanel.Fill = DrawingColorToBrushConverter.Convert(SelectedBrush.EndColor);
        //                break;
        //        }

        //        SetPreviewImage();
        //    }
        //}

        private void ArrowMouseUp(object sender, MouseButtonEventArgs e)
        {
            stopType = ((Arrow)sender).Name == "StartArrow" ? StopType.Start : StopType.End;
            switch (stopType)
            {
            case StopType.Start:
                stopColorPanel.Fill = DrawingColorToBrushConverter.Convert(SelectedBrush.StartColor);
                alphaNumeric.Value  = SelectedBrush.StartColor.A;
                break;

            case StopType.End:
                stopColorPanel.Fill = DrawingColorToBrushConverter.Convert(SelectedBrush.EndColor);
                alphaNumeric.Value  = SelectedBrush.EndColor.A;
                break;
            }
        }