The next code always centers the Canvas element i create.
But my goal is to set my own location, for example, 0,0.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Canvas canvas = new Canvas();
canvas.Height = 100;
canvas.Width = 100;
canvas.Background = Brushes.Black;
Canvas.SetTop(canvas, 0);
Canvas.SetLeft(canvas, 0);
this.Content = canvas;
}
}
Notes:
If you write a code of doing it, please do it in C#, not XAML.
The next code sets location to Left, Top.
But my goal is to define exact location.
How to define exact location like axb?
public MainWindow()
{
InitializeComponent();
Canvas canvas = new Canvas();
canvas.Height = 100;
canvas.Width = 100;
canvas.Background = Brushes.Black;
canvas.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
canvas.VerticalAlignment = System.Windows.VerticalAlignment.Top;
Canvas.SetTop(canvas, 20);
Canvas.SetLeft(canvas, 20);
this.Content = canvas;
}