public void SetX(Shape view, double x)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.XProperty, x);
            UpdateShape(view, viewModel, "x");
        }
        public void setStrokeMiterlimit(Shape view, double strokeMiterlimit)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.StrokeMiterlimitProperty, strokeMiterlimit);
            UpdateShape(view, viewModel, "strokeMiterlimit");
        }
        public void SetStrokeOpacity(Shape view, double strokeOpacity)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.StrokeOpacityProperty, strokeOpacity);
            UpdateShape(view, viewModel, "strokeOpacity");
        }
        public void setStrokeDashoffset(Shape view, double strokeDashOffset)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.StrokeDashOffsetProperty, strokeDashOffset);
            UpdateShape(view, viewModel, "strokeDashoffset");
        }
        public void SetStroke(Shape view, uint?iColor)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.StrokeProperty, iColor);
            UpdateShape(view, viewModel, "stroke");
        }
        public void SetStrokeWidth(Shape view, double thickness)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.StrokeThicknessProperty, thickness);
            UpdateShape(view, viewModel, "strokeWidth");
        }
        private void UpdateGroup(Canvas view, ShapeViewModel viewModel, string updateKey)
        {
            // 更新UpdateKeys
            List <String> UpdateKeys = new List <string>(viewModel.UpdateKeys);

            UpdateKeys.Add(updateKey);
            viewModel.SetValue(ShapeViewModel.UpdateKeysProperty, UpdateKeys);

            view.SetValue(Canvas.LeftProperty, viewModel.X);
            view.SetValue(Canvas.TopProperty, viewModel.Y);
            view.RenderTransformOrigin = viewModel.Origin;
            ScaleTransform sctr = new ScaleTransform();

            sctr.ScaleY = viewModel.Scale;
            sctr.ScaleX = viewModel.Scale;
            RotateTransform rttr = new RotateTransform();

            rttr.Angle = viewModel.Rotate;
            TransformGroup trfg = new TransformGroup();

            trfg.Children.Add(sctr);
            trfg.Children.Add(rttr);
            view.RenderTransform = trfg;
            view.DataContext     = viewModel;
        }
        public void SetFill(Shape view, uint?iColor)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.FillProperty, iColor);
            UpdateShape(view, viewModel, "fill");
        }
        public void SetRotate(Shape view, double rotate)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.RotateProperty, rotate);
            UpdateShape(view, viewModel, "rotate");
        }
        public void SetOriginY(Shape view, Point origin)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.OriginProperty, origin);
            UpdateShape(view, viewModel, "origin");
        }
        public void SetScale(Shape view, double scale)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.ScaleProperty, scale);
            UpdateShape(view, viewModel, "scale");
        }
        public void SetFillOpacity(Shape view, double fillOpacity)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.FillOpacityProperty, fillOpacity);
            UpdateShape(view, viewModel, "fillOpacity");
        }
        public void setStrokeDasharray(Shape view, JArray strokeDasharray)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.StrokeDashArrayProperty, strokeDasharray);
            UpdateShape(view, viewModel, "strokeDasharray");
        }
        public void SetY(Shape view, double y)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.YProperty, y);
            UpdateShape(view, viewModel, "y");
        }
        public void SetOriginY(Shape view, double originY)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;
            Point          origin    = viewModel.Origin;

            origin.Y = originY;
            viewModel.SetValue(ShapeViewModel.OriginProperty, origin);
            UpdateShape(view, viewModel, "originY");
        }
        public void SetOriginX(Canvas view, double originX)
        {
            ShapeViewModel viewModel = (ShapeViewModel)view.DataContext;
            Point          origin    = viewModel.Origin;

            origin.X = originX;
            viewModel.SetValue(ShapeViewModel.OriginProperty, origin);
            UpdateGroup(view, viewModel, "originX");
        }
        public void SetStrokeLinecap(Shape view, string strokeLinecap)
        {
            List <string> strokeLinecapArray = new List <string>()
            {
                "butt", "square", "round"
            };
            int            iStrokeLinecap = strokeLinecapArray.IndexOf(strokeLinecap);
            ShapeViewModel viewModel      = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.StrokeLinecapProperty, iStrokeLinecap);
            UpdateShape(view, viewModel, "strokeLinecap");
        }
        /// <summary>
        /// 更新Shape组件
        /// </summary>
        /// <param name="view">Shape组件</param>
        /// <param name="viewModel">DataContext上下文数据</param>
        /// <param name="updateKey">更新的key值</param>
        public static void UpdateShape(Shape view, ShapeViewModel viewModel, string updateKey)
        {
            // 更新UpdateKeys
            List <String> UpdateKeys = new List <string>(viewModel.UpdateKeys);

            UpdateKeys.Add(updateKey);
            viewModel.SetValue(ShapeViewModel.UpdateKeysProperty, UpdateKeys);

            if (viewModel.Stroke.HasValue)
            {
                Color color = ColorHelpers.Parse(viewModel.Stroke.Value);
                color.A              = Convert.ToByte(Convert.ToUInt16(color.A) * viewModel.StrokeOpacity);
                view.Stroke          = new SolidColorBrush(color);
                view.StrokeThickness = viewModel.StrokeThickness;
                if (viewModel.StrokeDashArray != null)
                {
                    DoubleCollection dCollection = new DoubleCollection();
                    for (int i = 0; i < viewModel.StrokeDashArray.Count; ++i)
                    {
                        dCollection.Add(Convert.ToDouble(viewModel.StrokeDashArray[i].ToString()));
                    }
                    view.StrokeDashArray = dCollection;
                }
                view.StrokeDashOffset   = viewModel.StrokeDashOffset;
                view.StrokeMiterLimit   = viewModel.StrokeMiterlimit;
                view.StrokeLineJoin     = (PenLineJoin)viewModel.StrokeLinejoin;
                view.StrokeStartLineCap = (PenLineCap)viewModel.StrokeLinecap;
                view.StrokeDashCap      = (PenLineCap)viewModel.StrokeLinecap;
                view.StrokeEndLineCap   = (PenLineCap)viewModel.StrokeLinecap;
            }
            if (viewModel.Fill.HasValue)
            {
                Color color = ColorHelpers.Parse(viewModel.Fill.Value);
                color.A   = Convert.ToByte(Convert.ToUInt16(color.A) * viewModel.FillOpacity);
                view.Fill = new SolidColorBrush(color);
            }
            view.SetValue(Canvas.LeftProperty, viewModel.X);
            view.SetValue(Canvas.TopProperty, viewModel.Y);
            view.RenderTransformOrigin = viewModel.Origin;
            ScaleTransform sctr = new ScaleTransform();

            sctr.ScaleY = viewModel.Scale;
            sctr.ScaleX = viewModel.Scale;
            RotateTransform rttr = new RotateTransform();

            rttr.Angle = viewModel.Rotate;
            TransformGroup trfg = new TransformGroup();

            trfg.Children.Add(sctr);
            trfg.Children.Add(rttr);
            view.RenderTransform = trfg;
            view.DataContext     = viewModel;
        }
        public void SetStrokeLinejoin(Shape view, string strokeLinejoin)
        {
            List <string> strokeLinejoinArray = new List <string>()
            {
                "miter", "bevel", "round"
            };
            int            iStrokeLinejoin = strokeLinejoinArray.IndexOf(strokeLinejoin);
            ShapeViewModel viewModel       = (ShapeViewModel)view.DataContext;

            viewModel.SetValue(ShapeViewModel.StrokeLinejoinProperty, iStrokeLinejoin);
            UpdateShape(view, viewModel, "strokeLinejoin");
        }