Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize WPF application

Tags:

c#

wpf

graphics

Have tried searching google but I'm struggling to find an answer to this.

I have a basic WPF application with a few controls on. When I maximise the application the controls on the screen stay the same size and I get a lot of wasted space.

Is there a way to get the controls to grow and shrink dynamically with the size of the main window?

Kind Regards

Ash

like image 683
user589195 Avatar asked Mar 24 '26 08:03

user589195


1 Answers

Don't set a fixed Height and Width properties for your controls. Instead set, horizontal and vertical alignment to stretch. And make sure your controls are contained inside an appropriate layout panel.

For example-

Fixed size grid:

<Grid Background="Red" Width="50" Height="50"/>

Dynamically expending grid:

<Grid Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
like image 62
MichaelS Avatar answered Mar 25 '26 22:03

MichaelS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!