Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing wpf window programmatically in c#

Tags:

c#

wpf

xaml

resize

I have a wpf window with two usercontrols inside of which the second is only shown when needed. I only set the MinWidth of the window in XAML, the MinHeight is provided through databinding an ist set depending on if the second usercontrol is shown. Now: How can I set the size of the window to different values than the MinWidth/Height during runtime. I tried setting the values before the Show(), after the Show(), in various events (Initialized, Loaded, etc.). I tried with and without UpdateLayout(), I tried setting the Height/Width through databinding. Nothing works! But when I debug the approaches I see that the Height/Width properties of the window are set to the expected values, but ActualHeight/Width stay. I thought it would be a bagatelle but it turned out it is not (to me). Thy for any help.

like image 281
Jorosch Avatar asked Aug 18 '11 06:08

Jorosch


1 Answers

You have no given much information, so I am just guessing here.

The only way I could reproduce the window not respecting its width and height settings was when I set SizeToContent to WidthAndHeight.

like image 182
Jens Avatar answered Oct 09 '22 12:10

Jens