SizeToContent on UserControl
Asked Answered
L

2

14

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.

Loriannlorianna answered 2/8, 2010 at 20:15 Comment(0)
D
5

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

Demarcation answered 2/8, 2010 at 20:19 Comment(1)
I keep getting "*" cannot be converted to length. Can you show me an example of how to set the grid row and column height to *?Lanie
S
5

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

Semimonthly answered 2/8, 2010 at 20:19 Comment(1)
1) I have a grid in the main window with no sizes set. 2) I've got a user control with a grid and no sizes set. 3) I've got a third control that has a height and width defined. I'm injecting third into the second and the second into the first and my second control gets all the size it can take, but I want it to be framed around the third one.Loriannlorianna

© 2022 - 2024 — McMap. All rights reserved.