Best way to create data entry forms in WPF?

When creating WPF forms that are used for data entry (for example, a bunch of labels next to a bunch of text fields and combo boxes), I saw two methods:

  • Create a main grid, divide it into two columns and add lines with Height="auto" for each field and two lines for the header and footer (and the submit button), and each label and text field have their own row.
  • Another method is to create a main stack panel and inside it a horizontal stack panel for each pair of text labels.

How do you create data entry forms? I am currently torn between two methods, maybe there is an alternative that I do not know about?

EDIT: Henk said I have to better define, and I agree that best of all, I mean that the easiest way to maintain, create, align, and add or remove fields is because of changing requirements.

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

+8
forms wpf stackpanel grid
source share
3 answers

Definitely the first method!

it is well aligned, especially using SharedSizeGroup , so that you can have the same alignment, for example, in different group blocks.

+2
source share

I used both, and it really depends on how your form will look. If you have a really simple layout where you are going to have labels and corresponding fields of about the same size, then your first method works well. It allows you to create two columns that line up very well. However, if your fields are different from each other, and the heights and you want to be more complex with layouts, then it might be better to use a hybrid approach. If you are doing something more complex than just tagging fields on basic controls, you can create custom controls, rather than just using what is out of the box. When stacking fields both horizontally and vertically, it becomes difficult to maintain a grid layout, since you must have a grid with a large number of columns and rows. Fields and labels must span columns and rows for proper alignment. It works, but it's a nightmare if you want to reorganize the form.

For what you wrote, the first approach seems to be better. If its simple now and at some point in the future becomes more complex, it is easy to change. However, if you have a more complex layout, then a clean grid approach is probably not the best.

+1
source share

Disclaimer: I'm going to talk a little about my own product on my blog, which gives comparisons and problems in maintaining forms.

Both Grid and StackPanel have Maintanence nightmares, so we went for a different approach to creating the layout of the form, and I set out our approach here at this link.

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

0
source share

All Articles