Search code examples
wpfvisual-studio-2008wpf-controlsdesigner

How can I prevent the VS WPF designer putting margins on every object from the toolbox


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!


Solution

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

    EDIT:

    I wrote the above nearly three years ago. In the meantime, it would appear that the design-time experience has gotten a lot better.

    While the designer still adds hard-coded margins if you drag-and-drop, there are ways to remove those margins without having to do it by hand.

    Here's a link to an article that illustrates how to use design tools in Visual Studio 2010 to lay out a form without having to type any XAML. (Despite the title, it's about WPF.)

    The first part of the article shows hard-coded pixels, but I've linked to the second part that shows how to lay out the controls without that hard coding.

    Layout Techniques for Windows Form Developers