Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SizeToContent on UserControl

In fact the UserControl lacks the property 'SizeToContent' that we have in Window.

So the question is:

what's the easiest and right way to simulate SizeToContent=WidthAndHeight behavior on UserControl?

UPD... yeah I know it suppose to get that automatically if no Height and Width defined in the container where you're placing a user control.

But it doesn't work when you placing one userControl with defined sizes, into another with no sizes, and altogether they go inside the container.

it this case your second control will take all the space it can get.

like image 211
iLemming Avatar asked Aug 02 '10 20:08

iLemming


2 Answers

Use a Grid and set either the Row and Column height to * for the items you want to size to the window.

like image 124
David Basarab Avatar answered Nov 11 '22 07:11

David Basarab


Just don't set the Width and Height properties. It will then take on whatever width and height its child requires.

like image 5
Kent Boogaart Avatar answered Nov 11 '22 07:11

Kent Boogaart