Is it somehow possible to restrict Window.SizeToContent
to expand the size only?
I have a general window that is dynamically filled with content in a TabControl. As it is not known at the beginning how large each TabItem is going to be I cannot precalculate the required size (I only care about height though) to display it all without scrolling.
Enabling SizeToContent
will automatically adjust the size to the required size whenever the tab is changed. While it’s okay that it only expands when the current view requires more space, I dislike that the window will also shrink when less space is required. Is it possible to restrict the SizeToContent
behavior to just allow expansion of the window size? Or can the behavior be emulated in a different way, while still producing correct results taking the window frames and other components next to the tab control into account?
I tried hooking into different window events to find out where the new size information goes when changing the tab, but the only real useful one on the window, OnChildDesiredSizeChanged
, was not producing deterministic results (for some tabs it was called, for others it wasn’t). Do you have any other idea?
You can try using FrameworkElement.MinHeight and FrameworkElement.MinWidth to set the minimum height/width after the Window
has loaded.
public void WindowLoaded()
{
this.MinHeight = this.ActualHeight;
this.MinWidth = this.ActualWidth;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With