#269 – Automatically Sizing a Window to Fit Its Contents
April 7, 2011 3 Comments
You normally set the width and height of a WPF Window by setting its Width and Height properties directly.
<Window Width="400" Height="300" >
At runtime, this sets the starting window size.
If you want the window to automatically size to fit its contents, you can set the SizeToContent property. By default, this property has a value of Manual, indicating that the Width and Height properties will dictate the window’s size. (Ignoring the effect of min/max properties).
Setting SizeToContent to Height will force the window to adjust its height to fit the contents.
<Window Width="400" Height="300" SizeToContent="Height">
Setting SizeToContent to Width will force the window to adjust its width to fit the contents.
<Window Width="400" Height="300" SizeToContent="Width">
And setting it to WidthAndHeight will tell the window to adjust both dimensions.
<Window Width="400" Height="300" SizeToContent="Width">
I am unable to resize the window for rad expander. Please Suggest me how to do it.
Do you mean the RadExpander control by Telerik? I would consult their documentation or post something in their forums to get help with that.
What to do when you also have a datagrid, with a datagridtextcolumn with Width=”*”?
When window is set to SizeToContent, this column always stretches the window to its maximum width.