Resize the main WPF window dynamically

In this post I will explain you how to resize dynamically the size of your main WPF GUI.It's a very easy trick that can be very useful, and can be done in three steps:1 / Add few parameters in your XAML2 / Change the visibility of controls from the PS13 / Add some conditions or actionsWhen can it be useful ?- You have a GUI as below.

Main GUI

- When you click on the Hide me button, you want to hide the GroupBox Hide me if you can and all included controls.- You configured the Visibility attribute with the collapsed value. - After clicking on the Hide button, the GroupBox will be hidden as below.

Hide with no dynamic resize

- Ok, that's cool but there is still a blank space in my GUI, see below.

Blank space

This is due to the size set in the Window part.

How to proceed ?

1 / Open your XAML2 / In the Window part, add the below lines:3 / Open your PS14 / Add the below lines in the Hide button action part:And now here we are, let's try again.- Open the GUI- The GroupBox is displayed- Click on the Hide button- And voila, the GroupBox is hidden and the GUI height has changed