private Path CreatePolyline(IEnumerable <Point> points) { var geometry = new StreamGeometry(); if (points != null && points.Any()) { var ctx = geometry.Open(); ctx.BeginFigure(points.First(), false, false); ctx.PolyLineTo(points.Skip(1).ToList(), true, true); ctx.Close(); } var scaleTransform = new ScaleTransform(); scaleTransform.Bind(ScaleTransform.ScaleXProperty, () => this.ActualWidth, width => width / 2); scaleTransform.Bind(ScaleTransform.ScaleYProperty, () => this.ActualHeight, height => height / 2); var translateTransform = new TranslateTransform(); translateTransform.Bind(TranslateTransform.XProperty, () => this.ActualWidth, width => width / 2); translateTransform.Bind(TranslateTransform.YProperty, () => this.ActualHeight, height => height / 2); var transformGroup = new TransformGroup { Children = { scaleTransform, translateTransform } }; geometry.Transform = transformGroup; var path = new Path { Data = geometry }; return(path); }
private Path CreatePath(Infrastructure.Data.PointsSequence polylineData, bool isClosed, VGKind vgKind) { var points = (from pnt in polylineData.Points select new Point { X = pnt.X, Y = pnt.Y }).ToArray(); var geometry = new StreamGeometry(); using (var context = geometry.Open()) { context.BeginFigure(points[0], false, isClosed); context.PolyLineTo(points.Skip(1).ToList(), true, false); } var scaleTransform = new ScaleTransform(); scaleTransform.Bind(ScaleTransform.ScaleXProperty, () => polyRoot.ActualWidth, width => width / 2); scaleTransform.Bind(ScaleTransform.ScaleYProperty, () => polyRoot.ActualHeight, height => height / 2); var translateTransform = new TranslateTransform(); translateTransform.Bind(TranslateTransform.XProperty, () => polyRoot.ActualWidth, width => width / 2); translateTransform.Bind(TranslateTransform.YProperty, () => polyRoot.ActualHeight, height => height / 2); var transformGroup = new TransformGroup { Children = { scaleTransform, translateTransform } }; geometry.Transform = transformGroup; var path = new Path(); path.Data = geometry; path.DataContext = polylineData; path.Bind(Path.StrokeProperty, () => polylineData.CurveCategory, () => polylineData.ColorCodingIndex, (curveCategory, colorCodingIndex) => { if (colorCodingIndex != PointsSequence.INVALID_COLOR_CODING) { return(Constants.PRIMITIVE_CURVES_COLOR_CODING[colorCodingIndex]); } else { switch (curveCategory) { case CurveCategories.None: return(SKETCH_STROKE_UNCATEGORIZED); case CurveCategories.Feature: return(SKETCH_STROKE_FEATURE); case CurveCategories.Silhouette: return(SKETCH_STROKE_SILHOUETTE); default: return(Binding.DoNothing); } } }); path.Bind(Path.StrokeThicknessProperty, () => polylineData.IsSelected, () => polylineData.IsEmphasized, () => polylineData.CurveCategory, (isSelected, isEmphasized, curveCategory) => { if (isSelected || isEmphasized) { return(4.0); } if (curveCategory == CurveCategories.Feature) { return(2.0); } return(1.0); }); SetVGKind(path, vgKind); return(path); }