Loading...

Resize the main WPF window dynamically

2 A+ A-

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 XAML
2 / Change the visibility of controls from the PS1
3 / Add some conditions or actions

When 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 XAML
2 / In the Window part, add the below lines:
3 / Open your PS1
4 / 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









WPF_Guides 4877284993363367728

Enregistrer un commentaire

2 commentaires

Anonyme a dit…

could have been a great article, but it is missing a lot of explanation...dunno if u did it on purpose...would have been great for instance to let your code on github. or on the same page.

Gas Technicians New York a dit…

Awesome blog youu have here

Accueil item

Award

Learn KQL in one month

Sponsors

You want to support me ?

Mes articles en français

Books in French


Stats