10

When building WPF forms that are used for data entry (e.g. A bunch of labels next to a bunch of textboxes and comboboxes) I've seen two methods:

  • Create a master Grid, divide it into two columns, and add rows with Height="auto" for each field and two rows for header and footer (and submit button), and each label and text box has their own row.
  • The other method is to create a master stackpanel and inside it a horizontal stackpanel for each pair of label-textbox.

How do you design your data entry forms? I'm currently torn between the two methods, maybe there's an alternative that I'm unaware of?

EDIT: Henk said I should define best and I think I agree, by best I mean easiest to maintain, create, align and add or remove fields from as demands change.

So far the only criteria by which the grid is better is ease of alignment.

Ziv
  • 2,755
  • 5
  • 30
  • 42

3 Answers3

3

definately first method!

it's well aligned, especially with the use of SharedSizeGroup so you can have the same alignment eg in different Groupboxes.

Markus Hütter
  • 7,796
  • 1
  • 36
  • 63
  • I agree. StackPanels don't offer you nearly the amount of layout control you might need when you decide to make it look nice later, or if you needed a second part for a field somewhere. Just make sure you keep your tab order maintained, and be sure to test it often with real data while you lay it out. – djdanlib Apr 11 '11 at 21:36
1

I have used both and it really depends upon how your form is going to look. If you have a really simple layout where you are going to have labels and and corresponding fields of approximately the same size then your first method works well. It lets you create two columns that line up very well. However, if your fields are of varying withs, and heights and you want to be more complex with the layouts then a hybrid approach may be best. If you are doing anything more complex than just labeling fields on basic controls you may want to create user controls rather than just using what is there out of the box. When laying out fields in both a horizontal and vertical jagged manner it becomes hard to maintain the grid layout as you have to wind up having a grid with lots of columns and rows. The fields and labels have to span columns and rows to get your alignment correct. This works, but is a nightmare if you ever want to reorganize the form.

For what you wrote, it sounds like the first approach is best. If its simple now and some point in the future it becomes more complex, its easy to change. However, if you have a more complex layout already then a pure grid based approach probably isn't best.

Craig Suchanec
  • 10,474
  • 3
  • 31
  • 39
0

Disclaimer: I am going to say little about my own company's product in my blog that gives comparison and challenges in maintaining forms.

Both Grid and StackPanel have Maintanence nightmares so we went on different approach of creating Form Layout, and I have outlined our approach here on this link,

http://akashkava.com/blog/296/advanced-data-form-with-ui-atoms-on-wpf-and-silverlight/

Akash Kava
  • 39,066
  • 20
  • 121
  • 167