kristofdielis
Programmer
- Sep 1, 2011
- 25
Hi,
Is there some way to draw with WPF, like you could with GDI?
I mean, not add a rectangle object to a stackpanel (which is how it's apparently often done), but really draw a rectangle or whatever, on the surface of a control, at a specified point.
I mean like it was in 'the old days':
Is there a workable alternative in WPF?
I don't want something like this:
While this 'works', this approach will prove a serious pain later on.
Thanks.
Is there some way to draw with WPF, like you could with GDI?
I mean, not add a rectangle object to a stackpanel (which is how it's apparently often done), but really draw a rectangle or whatever, on the surface of a control, at a specified point.
I mean like it was in 'the old days':
Code:
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics gr = e.Graphics;
for (int row = 0; row < 5; row++)
{
for (int col = 0; col < 5; col++)
{
gr.DrawRectangle(new Pen(Brushes.Black), new Rectangle(new Point(col * 50, row * 50), new Size(50, 50)));
}
}
}
Is there a workable alternative in WPF?
I don't want something like this:
Code:
for (int r = 0; r < this.Height; r++)
{
StackPanel rowStackPanel = new StackPanel();
for (int c = 0; c < this.Width; c++)
{
Rectangle rect = new Rectangle();
...
rowStackPanel.Children.Add(rect);
}
baseControl.Children.Add(rowStackPanel);
}
While this 'works', this approach will prove a serious pain later on.
Thanks.