tags:

views:

859

answers:

2

I have a custom canvas that I can drop controls on, move, and resize. I need to be able to at least start with a pre-determined size but then allow re-sizing.

My problem is that I have a user control that doesn't appear to resize. I set Height and Width on the user control (works on drop). then as the control is resized on the canvas the visual size stays the same (the sizing handles are changing). I can see the Height property changing (usercontrol.height) as the control is resized. But again, the appearance of the control stays the same size.

I had a thought that the inner container on the user control should be bound to the usercontrol.height but that didn't seem to help. (or maybe I didn't have the binding right).

On the same canvas, if the dropped control is say, an Image control, I can set an explicit height on the drop and everything resizes as it should. So it seems to be UserControl thing.

So is there something special I need to do with UserControls to get the visuals to resize? Should I be using explicit height and width to get it all started?

Thanks for any help.

A: 

Not a WPF expert but I believe you need to enable auto-sizing in order to achieve the scenario you are looking for. This is done by setting the Height/Width of a control to Double.NaN which essentially says, "I have no specific size". Once you do that, the control should resize to occupy available space based on the need of the control.

JaredPar
+1  A: 

The WPF layout system can be confusing, as you've discovered. There is no substitute for a solid understanding of the layout and measurement system. If you plan on doing much WPF development, it's worth taking 20 minutes to read this article on the layout system and then experimenting for a while in an iterative environment such as Kaxaml until you feel comfortable.

The system is very logical. It won't take long for the penny to drop. Sorry for the indirect answer, but I don't believe there's enough information in your question to really explain what's going on.

You might also look at the HorizontalAlignment and VerticalAlignment properties.

Drew Noakes