private static void RenderElement(Canvas parent, CompositeTransform textRotation, ElementDescription element) { switch (element.Type) { case ElementType.Circle: Ellipse e = new Ellipse() { Width = element.Width, Height = element.Height, Fill = BrushForColor(element.Fill), Stroke = BrushForColor(element.Stroke), }; parent.Children.Add(e); Canvas.SetLeft(e, element.CenterX); Canvas.SetTop(e, element.CenterY); break; case ElementType.Path: Path path = new Path() { Data = ProcessPathData(element.Path), Tag = element.Text, Fill = BrushForColor(element.Fill), Stroke = BrushForColor(element.Stroke), }; parent.Children.Add(path); break; case ElementType.Text: Grid g = new Grid() { Width = 200, Height = 200 }; parent.Children.Add(g); Canvas.SetLeft(g, element.CenterX - g.Width / 2); Canvas.SetTop(g, element.CenterY - g.Height / 2); TextBlock tb = new TextBlock() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, RenderTransform = textRotation, Foreground = BrushForColor(element.Stroke), FontSize = element.FontSize, Text = element.Text, }; g.Children.Add(tb); break; default: throw new InvalidOperationException("Unexpected node: " + element.Type); } }
private static void RenderElement(UIElementCollection childCollection, Transform textRotation, ElementDescription element) { // Debug.WriteLine(element.ToString()); switch (element.Type) { case ElementType.Circle: Ellipse e = new Ellipse() { Width = element.Width.Value, Height = element.Height.Value, Fill = BrushForColor(element.Fill), Stroke = BrushForColor(element.Stroke), }; childCollection.Add(e); Canvas.SetLeft(e, element.CenterX.Value); Canvas.SetTop(e, element.CenterY.Value); break; case ElementType.Path: Path path = new Path() { Data = ProcessPathData(element.GetPath()), Tag = element.Text, Fill = BrushForColor("#80000000"), // element.Fill), Stroke = BrushForColor(element.Stroke), StrokeThickness = element.Scale.Value * (double)Path.StrokeThicknessProperty.GetMetadata(typeof(Path)).DefaultValue, }; childCollection.Add(path); //Canvas.SetLeft(path, element.CenterX.Value); //Canvas.SetTop(path, element.CenterY.Value); break; case ElementType.Text: Canvas canvas = new Canvas() { RenderTransform = textRotation, }; FrameworkElement tb = new Border() { // BorderThickness = new Thickness(1), // BorderBrush = new SolidColorBrush(Colors.Magenta), Child = new TextBlock() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, // Foreground = BrushForColor(string.IsNullOrEmpty(element.Stroke) ? "white" : element.Stroke), Foreground = BrushForColor("white"), FontSize = element.FontSize * 0.85, Text = element.Text, } }; canvas.Children.Add(tb); tb.LayoutUpdated += (a, b) => { Canvas.SetLeft(tb, -tb.ActualWidth / 2); Canvas.SetTop(tb, -tb.ActualHeight / 2); }; childCollection.Add(canvas); Canvas.SetLeft(canvas, element.CenterX.Value); Canvas.SetTop(canvas, element.CenterY.Value); break; default: throw new InvalidOperationException("Unexpected node: " + element.Type); } }