Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 506
henriksen Avatar asked Jan 30 '09 20:01

henriksen


People also ask

How do I set margins in WPF?

The Margin property of UIElement, which is parent class of all WPF controls is used to set the margin of a control. Margin property takes four numbers - Left, Top, Right and Bottom, that is margin to the left top and right bottom.

What is Padding in WPF?

Padding represents the distance between the side of the control (which can be the margin) and its content. The content depends on the type of the control. Margin is outside the UI element, while Padding is inside it.

What is margin in WPF?

The margin property in WPF allows you set spacing between elements in a window. You can assign the margins for the Top, Right, Bottom and Left. Every control that derives from FrameworkElement has this property.

How do I view XAML design in Visual Studio?

These include the artboard (which is the visual design surface), XAML editor, Document Outline window (Objects and Timeline window in Blend for Visual Studio), and Properties window. To open the XAML Designer, right-click a XAML file in Solution Explorer and choose View Designer.


1 Answers

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

like image 129
Ryan Lundy Avatar answered Sep 30 '22 15:09

Ryan Lundy