views:

422

answers:

4

When I drag a control from the toolbox on to the Visual Studio 2008 WPF design surface, it sets a margin based on where I dropped it and a default size.

Is there any way to prevent VS setting those? When I drop a control on a stackpanel I want it to flow in to the existing controls in the panel.

Thanks!

+3  A: 

I've never found a way to prevent this. I just type the XAML instead.

Kyralessa
Same here. The WPF designer is way too slow and buggy for my tastes.
Andy
I agree. The designer's gotten better at providing a representative display of what the xaml denotes, but I don't know if it's even possible for it to provide the awesome drag/drop experience of the winforms designer given the radically different underlying model.
Greg D
I don't see any reason it *wouldn't* be possible. You can do drag-and-drop in ASP.NET into the designer or the markup. It doesn't seem like a long step to do the same thing in WPF. But for whatever reason, Microsoft hasn't made it a priority.
Kyralessa
A: 

When I drop a control into a stackpanel, it doesn't add margins, it "flows" in with the rest.

The controls you drop onto the design surface have a margin by default because that's how it knows where it's placed. What I typically do is create a grid and set it's margin where I want it, then create columns and rows to put controls into. I drop in my other controls which will add margins which are usually not what I want. After I have all my controls into my grid, reasonably placed, I switch to XAML view and either remove the margin completely (which causes a control like a button to fill the entire space), or make the margin something like 5, which puts some nice padding around the control.

Bottom line...and this is especially true with Silverlight development, you must get used to manipulating the XAML directly. It's the only way you'll get the layout exactly where you want it. This is my opinion and most everybody in my shop who does WPF/silverlight development.

Scott
A: 

Unfortunately there does not appear to be a means to do this.

The default size is set as a result of you manipulating the size of your control is the designer. When you increase the width and/or height of a control the designer is interpreting your actions as a request to make the control that specified width and/or height.

A similar situation is encountered with the margins. As you alter the position of your control within the designer, it modifies properties to achieve the layout you've created. In the case of most containers the simplest solution is to modify margins in order to achieve the desired position, as you've already pointed out the simples solution is not always the most desired.

Personally I prefer to only use the XAML editor and only occasionally take a peak at the WPF Designer when I want to see the current layout. I also tend to favor using the Grid to layout most of my windows/controls as it provides the greatest flexibility not only for sizing and positioning, but for other tasks/features such as animations, transforms, etc.

Richard C. McGuire
A: 

I have the same problem with Expression Blend and it is what prevents me from using that tool. I yearn for the days of the Windows Forms designer from VS 2003 -- of course it's even nicer now but Microsoft needs to make a UI designer that good for XAML too.

Pete