I’ve got a WPF application which starts off with a very small window. Something in the area of 200×100. When certain events are raised from an external source, I add a control to the ItemsControl area of my window. The items control is currently set to use a StackPanel PanelTemplate.
What I want, is for the application window to grow when controls are added to the itemscontrol. Is this at all possible? The idea behind this is to keep the window as small as possible at all times. It should also shrink when controls are removed from the itemscontrol.
Thanks.
Yes, it is possible. You can use
Window.SizeToContentproperty to do that. And just set aMaxHeightandMaxWidthonWindowor theItemsControlinside just so it won’t keep growing and getting out of screen bounds.