Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <summary>
        /// gets some controls from the style
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            base.OnTemplateApplied(e);

            Rectangle rectangle = e.NameScope.Find <Rectangle>(PART_OffSwitch);

            _BackgroundTranslate = rectangle.RenderTransform as TranslateTransform; //e.NameScope.Find<TranslateTransform>(PART_BackgroundTranslate);
            _DraggingThumb       = e.NameScope.Find <Thumb>(PART_DraggingThumb);
            _SwitchTrack         = e.NameScope.Find <Grid>(PART_SwitchTrack);
            _ThumbIndicator      = e.NameScope.Find <IControl>(PART_ThumbIndicator);
            _ThumbTranslate      = _ThumbIndicator.RenderTransform as TranslateTransform; //e.NameScope.Find<TranslateTransformExt>(PART_ThumbTranslate);

            if (_ThumbIndicator != null && _ThumbTranslate != null && _BackgroundTranslate != null)
            {
                Binding translationBinding;
                translationBinding        = new Binding("X");
                translationBinding.Source = _ThumbTranslate;
                _BackgroundTranslate.Bind(TranslateTransform.XProperty, translationBinding);
            }
            if (_DraggingThumb != null && _ThumbIndicator != null && _ThumbTranslate != null)
            {
                _DraggingThumb.DragStarted   -= _DraggingThumb_DragStarted;
                _DraggingThumb.DragDelta     -= _DraggingThumb_DragDelta;
                _DraggingThumb.DragCompleted -= _DraggingThumb_DragCompleted;
                _DraggingThumb.DragStarted   += _DraggingThumb_DragStarted;
                _DraggingThumb.DragDelta     += _DraggingThumb_DragDelta;
                _DraggingThumb.DragCompleted += _DraggingThumb_DragCompleted;
                if (_SwitchTrack != null)
                {
                    _SwitchTrack.PropertyChanged += SwitchTrack_PropertyChanged;
                }
            }

            UpdateThumb();
        }
        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);
        }