Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Comparing WPF and Asp.Net Razor/HtmlHelper I find WPF/Xaml to be somewhat lacking in creating views.

With HtmlHelpers you could define in one place how you wan't to represent specific type of data and include elements set from the DataAnnotations of the property.

In WPF you can also define DataTemplates for data but it seems much more limited then EditorTemplates. It doesn't use information from DataAnnotations.

Also the layout of elements can be bothersome. I hate having to constantly add RowDefinitions and update the Grid.Row attribute of lot of elements when I add a new property somewhere in line.

I understand that GUI programming can be a lot of grunt work like this but as Asp.Net MVC has shown there are ways around that.

What solutions are out there to make view creation in WPF a little bit cleaner, maintainable and more dynamic?

share|improve this question
You should use IDataErrorInfo for validation in WPF as that's what the UI uses. You can make that interface read errors from your DataAnnotations too if that's how you want it. As for your Grid layout, first off be sure you're using the right Layout for what you want, as the Grid is often not the most efficient control. But if you're sure you want a Grid, I have some GridHelpers on my blog that makes maintaining a Grid's Rows/Columns easier – Rachel Nov 5 '12 at 15:13

Some random thoughts from the decent-sized project I worked on in WPF:

MVVM (cf. helps. It does not do all the work for you, but it gets you a little closer to feeling like you are in MVC. When properly implemented, it enforces a separation of concerns that makes everything a lot more maintainable.

When working with WPF, it is best to use explicit row/column definitions for your grids. All of the time. Yes, it is a lot of work, but when you do it, WPF ends up working the way it was really meant to (the visual designer, IMHO, should not exist or should be hidden--it just creates a cesspool in the XAML). Your views will then dynamically resize and be far more robust.

WPF is about as close as you can get to writing web apps while still writing desktop apps (of course, Microsoft is poised to change all that...). For all of its warts, it is a far more declarative and maintainable way to write GUI apps than straight winforms or Win32 calls.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.