I am trying to draw a non-static (variable width height x y) filled rectangle in WPF. I have experience with Winforms but I never used WPF before. This is what I would do in WinForm using GDI+ drawing calls.
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(_brush1, _rect1);
}
And also, I would call this.Invalidate()
whenever I change my _rect1
properties.
All the "tutorials" I have seen on this matter are only drawing static non-filled rectangles inside .xaml
files (or they don't mention where the code the show goes...).
I know WPF's painting works differently, I just don't understand how. I found a similar method protected override void OnRender(DrawingContext dc)
and trying adding this on the default class I got when I made my project public partial class MainWindow : Window
, but nothing is drawn on the screen. Another thing that concerns me, is that DrawingContext
class has only a DrawRectangle
class and there is no FillRectangle
.
How can I draw something like this efficiently ?