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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.