silverlight - In MVVM, when should a property by used vs a converter? -


we've had discussion @ work few times when use property in viewmodel vs when use converter.

use converter when:

  • it can re-used in other places (a great example isvisibilityconverter)
  • it's ui related action such selecting toggle button based on parameter value
  • a parameter isn't needed or can static value

use viewmodel property when:

  • the value depends on property (example: duration shown in seconds depends on user chose in acombo box, hours, minutes, seconds)
  • it needs unit tested
  • propertychanged events can change value

edit: should mention work in silverlight. don't have multibinding converters out of box , binding parameter doesn't work (which think in wpf). thoughts?

in general, try think of ivalueconverter "pure view" thing. in case, should reusable view code. (you can use imultivalueconverter handle many of scenarios you'd need "parameters", provided it's still pure view related...)

the viewmodel, on other hand, application specific logic. if relies on state that's specific domain, i'd rather put directly inside of viewmodel.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -