views:

168

answers:

6

I've created a user control using WPF and I want to add it to window. I've done that, but I can't make my control have a height higher than the height it has in its own xaml file. My MaxWidth and MaxHeight are both infinity, but I can't make the control any taller than what it is in its xaml file.

To get around this, I have to make all my user control enormous so I'll be able to size them to whatever I want. This doesn't seem right, I have to be missing something.

A: 

Why do you want your control to have a height higher than the height it has in its own XAML file? Couldn't you just remove the height in the control's XAML file, and explicitily set the height of the control when you declare it in the other XAML files (or code) that use it?

unforgiven3
A: 

If I remove the height and width in the controls XAML file I lose the ability to use the designer for my user control. So short answer, that did solve my problem, but now I can't use the designer for user controls. Doesn't seem like I'm any better off.

Jonathan Beerhalter
A: 

The problem could be that the inner controls in your user control aren't stretching to your control. Try setting HorizontalAlignment="Stretch" or Width="Auto" on the inner controls, or you could try binding the Width property.

thealliedhacker
A: 

Ok, after some further investigation, I've misspoken. its the Grid thats causing the problem. If I set the grid Width and Heigth to Auto then everything works fine, but I lose the ability to use the designer.

I have all of the alignments set to Stretch for both the Grid and its controls.

So in summary, everything works fine if I set Grid.Width = Auto and Grid.Height = Auto, but when i do that, I lose the ability to use the designer.

Jonathan Beerhalter
You could set the properties to Auto in the Load event instead.
thealliedhacker
+2  A: 

Removing the height and width is the way to go. The designer(blend) has some special designer width and height properties that they can use to design in, but won't set the height for runtime.

xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 mc:Ignorable="d" d:DesignWidth="412" d:DesignHeight="230"

That is the xaml that will be at the top of the Window/UserControl. This should help explain things.

Jab
A: 

I'm not aware of any width/height attributes for the VS designer if that's what you're using. I've used the MinWidth/MinHeight attributes in my xaml pretty effectively, however, to deal with the situation that I think you're describing.

Greg D