Exemple #1
0
		private TextBlock CreateTextLabel(IsolineTextLabel textLabel)
		{
			var transform = Plotter2D.Viewport.Transform;
			Point screenPos = textLabel.Position.DataToScreen(transform);

			double angle = textLabel.Rotation;
			Debug.WriteLine(angle);
			if (angle < 0)
				angle += 360;
			if (135 < angle && angle < 225)
				angle -= 180;

			TextBlock res = new TextBlock
			{
				Text = textLabel.Text,
				RenderTransform = new RotateTransform(angle),
				Tag = textLabel,
				RenderTransformOrigin = new Point(0.5, 0.5)
			};

			res.Measure(SizeHelper.CreateInfiniteSize());

			Size textSize = res.DesiredSize;
			Point position = new Point(screenPos.X - textSize.Width / 2, screenPos.Y - textSize.Height / 2);

			Canvas.SetLeft(res, position.X);
			Canvas.SetTop(res, position.Y);
			return res;
		}
		private static Transform CreateTransform(IsolineTextLabel isolineLabel, FormattedText text, Point position)
		{
			double angle = isolineLabel.Rotation;
			if (angle < 0)
				angle += 360;
			if (90 < angle && angle < 270)
				angle -= 180;

			RotateTransform transform = new RotateTransform(angle, position.X, position.Y);
			return transform;
		}
		private FrameworkElement CreateTextLabel(IsolineTextLabel textLabel)
		{
			var transform = Plotter2D.Viewport.Transform;
			Point screenPos = textLabel.Position.DataToScreen(transform);

			double angle = textLabel.Rotation;
			if (angle < 0)
				angle += 360;
			if (135 < angle && angle < 225)
				angle -= 180;

            string tooltip = textLabel.Value.ToString("F"); //String.Format("{0} at ({1}, {2})", textLabel.Text, textLabel.Position.X, textLabel.Position.Y);
            Grid grid = new Grid
            {
                RenderTransform = new RotateTransform(angle),
                Tag = textLabel,
                RenderTransformOrigin = new Point(0.5, 0.5),
                ToolTip = tooltip
            };

            TextBlock res = new TextBlock
            {
                Text = textLabel.Value.ToString("F"),
                Margin = new Thickness(3,1,3,1)
            };

            //res.Measure(SizeHelper.CreateInfiniteSize());

            Rectangle rect = new Rectangle
            {
                Stroke = Brushes.Gray,
                Fill = labelBackground,
                RadiusX = 8,
                RadiusY = 8
            };

            grid.Children.Add(rect);
            grid.Children.Add(res);

			grid.Measure(SizeHelper.CreateInfiniteSize());

            Size textSize = grid.DesiredSize;
			Point position = new Point(screenPos.X - textSize.Width / 2, screenPos.Y - textSize.Height / 2);

            Canvas.SetLeft(grid, position.X);
            Canvas.SetTop(grid, position.Y);
            return grid;
		}