I’m making a WPF/C# program with a Polygon to make a triangle. When the size of my window changes, I want it to be redraw, so here is my WPF :
<Polygon Name="Plg" Grid.Row="1" Grid.Column="1" Stroke="Red" StrokeThickness="1">
<Polygon.Fill>
<SolidColorBrush Color="White" />
</Polygon.Fill>
</Polygon>
And here is my code in the Window_SizeChanged Event:
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
Plg.Points.Clear();
Plg.Points.Add(new Point(Plg.ActualWidth / 2 , 0));
Plg.Points.Add(new Point(2, Plg.ActualHeight));
Plg.Points.Add(new Point(Plg.ActualWidth, Plg.ActualHeight));
}
If i increase the size of the window, it works well, but if I try to reduce it, the triangle keeps the biggest size that it has. I also try with RenderSize, but the result is the same.
Is it a bug, or did i make something wrong ?
with this XAML, it works: (the grid is in the window)
Change your code like this: