Exemplo n.º 1
0
        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);
            }
        }