Reputation: 2783
I am newbie of C# and WPF.
I want to draw simply a rectangle on canvas.
but I could not find the variable which decide origin point of rectangle.
void DrawRect(int x, int y)
{
Rectangle rec = new Rectangle
{
Fill = new SolidColorBrush(Colors.Red),
Width = width,
Height = y
...???
};
mainWindow.canvas.Children.Add(rec);
}
Thank you for your help.
Upvotes: 2
Views: 4122
Reputation: 1529
The Canvas' SetTop, SetLeft, SetRight, SetBottom properties should work.
So then
mainWindow.canvas.SetLeft(rec, xcoord);
mainWindow.canvas.SetTop(rec, ycoord);
Thanks to JerKimball for a little more information:
Individual shapes in WPF don't have a "Position", per se - they are positioned by setting the corresponding attached properties on the parent Canvas element
Upvotes: 4