C# – How to quickly align the controls in a WPF window

cwpf

I noticed that the WPF designer does a very poor job on aligning the controls, compared to the Windows Forms designer.

In the window below, I am unable to align each label, so that its text is on the same line as the text in the text box beside. The first label is correctly aligned, but the WPF designer does not give me any snap lines to correctly align the second and the third one.

Also, I cannot align the button with the labels. The snap line puts the button a few pixels leftwards compared to the label texts.

I couldn't find a fast way to do this alignment manually, writing XAML code, either. Putting the controls in a grid, and setting the margin of each control is time consuming.

alt text http://img520.imageshack.us/img520/4843/wpfdesigneralignment.png

Do you know a fast way to align the controls in the WPF windows ?

Best Answer

Use a Grid to lay out your controls then make sure you don't have any padding on the controls...unless of course you want some padding and you make sure they're all even.

A quick Google Search returned a basic tutorial:

Introduction to the WPF Grid Control