Volkhard Vogeler

Volkhard Vogeler

  • NA
  • 11
  • 1.8k

Rendering Labels with TranslateTransform

Mar 27 2021 1:06 PM
Hello,
i do have the following Code:
  1. private static void AddElements(Canvas canvas)  
  2. {  
  3.     double canvasHeight = canvas.Height;  
  4.     double canvasWidth = canvas.Width;  
  5.     double y0 = canvasHeight / 2;  
  6.     double x0 = canvasWidth / 2;  
  7.   
  8.     // Defining the new Coordinate-Point (0,0) to mid auf Canvas  
  9.     TranslateTransform tt = new TranslateTransform(x0, y0);  
  10.   
  11.     Line line1 = new Line();  
  12.     line1.X1 = -350;  
  13.     line1.Y1 = 0;  
  14.     line1.X2 = 350;  
  15.     line1.Y2 = 0;  
  16.     line1.Stroke = Brushes.Black;  
  17.     line1.StrokeThickness = 2.0;  
  18.     line1.RenderTransform = tt;  
  19.     canvas.Children.Add(line1);  
  20.   
  21.     Line line2 = new Line();  
  22.     line2.X1 = 0;  
  23.     line2.Y1 = -350;  
  24.     line2.X2 = 0;  
  25.     line2.Y2 = 350;  
  26.     line2.Stroke = Brushes.Black;  
  27.     line2.StrokeThickness = 2.0;  
  28.     line2.RenderTransform = tt;  
  29.     canvas.Children.Add(line2);  
  30.   
  31.   
  32.     Label lblN = new Label();  
  33.     lblN.Width = 50;  
  34.     lblN.Background = Brushes.Red;  
  35.     lblN.Margin = new System.Windows.Thickness(0, -300, 0, 0);  
  36.     lblN.Content = $"N";  
  37.     lblN.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;  
  38.     lblN.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;  
  39.     lblN.RenderTransform = tt;  
  40.     lblN.Padding = new System.Windows.Thickness(0);  
  41.     lblN.BorderBrush = Brushes.Black;  
  42.     lblN.BorderThickness = new System.Windows.Thickness(2.0);  
  43.     lblN.RenderTransform = tt;  
  44.     canvas.Children.Add(lblN);  
  45.   
  46.     Label lblS = new Label();  
  47.     lblS.Width = 50;  
  48.     lblS.Background = Brushes.Red;  
  49.     lblS.Margin = new System.Windows.Thickness(0, 300, 0, 0);  
  50.     lblS.Content = $"S";  
  51.     lblS.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;  
  52.     lblS.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;  
  53.     lblS.RenderTransform = tt;  
  54.     lblS.Padding = new System.Windows.Thickness(0);  
  55.     lblS.BorderBrush = Brushes.Black;  
  56.     lblS.BorderThickness = new System.Windows.Thickness(2.0);  
  57.     lblS.RenderTransform = tt;  
  58.     canvas.Children.Add(lblS);  
  59. }  
this method is called on an Menu-Eventhandler and it shows an coordinate system with (0,0) in the mid of the canvas. It should show a label with "N" at the top and a label with "S" at the bottom.

But i shows the attached image

 

Does anyone know, why lblN looks different than lblS ?

best regards

Volkhard