tags:

views:

95

answers:

3

I am writing an app in WPF. It is getting tiresome making all my converters for simple stuff.

I looked around and found WPFix. It seems nice, but has not had any releases in almost a year and is looking abandoned.

Has anyone used this? Is it stable? Does anyone have any recommendations for a different solution to allow Lambdas in XAML (Or otherwise avoid lots of Converter)?

A: 

You are correct that there have been no official releases since 2008. However, the last source code check-in was done on October 22, 2009.

David Brown
+5  A: 

To skip to the last part of your question: This is a discussion on WPF Disciples that puts forward the notion that M-V-VM negates most of the need for converters; that the ViewModel should present the data to the View in a way that is appropriate for that View.

Why write a separate class, implement IValueConverter, flesh out the Convert and ConvertBack methods, just to get an Int32 to a Color, when you could just have the VM expose a Color property in the first place, right?

I guess the answer to that depends on how religious you are about separation between the View and the ViewModel... I'm starting to think that the ViewModel should simply present the Model and apply business rules to it, and should be 'View Agnostic', and maybe an intermediary layer is required to manipulate the ViewModel specifically for your View, so if you ever swap out your View (for whatever reasons!) you don't need to rewrite your VM, just the 'intermediary' layer... then it occurred to me that WPF already has such an intermediary in the form of ValueConverters...

So to summarise: You could remove lots of repetitive development of Converters by simply having your VM expose properties of an appropriate type in the first place...

Now you need to decide if you want to...

Just my 2c worth... :)

IanR
I'm totally agree with you Ian. I prefer to add special property in ViewModel instead of converter...
Anvaka
"M-V-VM negates most of the need for converters"... by replacing them with something far more heavyweight and complicated * grin *. Also, in this philosophy, the view model risks becoming highly coupled to the view. Suppose we want to change our AlertLevel UI from colours but to icons? In the value converter approach, we create a new value converter and it's job done. In "Full MVVM," we need to go back and change our view model class. The view model should provide the information required to build a view (AlertLevel): it shouldn't assume how that info will be rendered (AlertLevelColour).
itowlson
Which, duh, is almost exactly what you say in your third para.
itowlson
+3  A: 

After looking at the author's examples in his first blog post, i think he has missed the point somewhat with WPF and XAML.

Sure it can be tiresome writing simple converters, but when you embed lambdas into your XAML you are starting down the road of having a monolithic view. To use the author's own example of presenting short dates, as soon as you start doing it with a lambda then you have to change your view when you have a user that requires a different format (i.e. mm/dd/yy, dd/mm/yy, yy/mm/dd). If these were kept as converters then they could be housed with a resource assembly and swapped out at will without changing the view. The same concept goes for anything else that would change due to the culture of the user.

Obviously the WPFix library could be cool for some things, and everybody will have a slightly different opinion on it. But as you write those converters, think of the declarative nature of XAML as a positive instead of a negative - it gives you abstraction between the actual presentation of the data and the preparation of that data for presentation. If you are writing a simple app or a quick prototype then mixing these two together (the View and the ViewModel) might be fine, but for larger scale productions you would find it beneficial to maintain a separation between those two.

slugster
While I agree with you on dates and such things, it is frustrating to write a converter to set a checkbox if a TextBox has text. That is the kind of converting I am looking at.
Vaccano
I would add: testability, testability, testability. An IValueConverter is easy to get into a test harness. XAML is hard to get into a test harness. Over time, I can build up a library of simple, reusable value converters that have been tested to death. I can't do that with "lambdas in XAML." For me, that's the decision made.
itowlson
Excellent point Ivan :)
slugster