I've asked this question of a few colleagues who I believe have good design sense. Interestingly, I've received varying responses. So which option do you think best fits the MVVM pattern and why?
Say I have a requirement to show an alert icon when $ greater than $10k.
Thanks for the feedback!
In your case you have definite business rule Shown WHEN > 10k
, it should be encapsulated in ViewModel rather than View because View is aware on HOW data will be shown rather then WHEN and WHY.
So I would suggest exposing both Amount
and ShowAlert
properties and avoid exposing AlertVisibility
property because it scatter such WPF View specific things like Visibility enum states (Hidden, Collapsed, ...)
If you would prefer to exposeAlertVisibility
you could face following problem in the future - just imagine that newer versions of WPF got rid of the annoying Visibility enum and in this case you've to modify ViewModel to expose new Visibility infrastructure/property to keep View working fine, but this is not correct from the MVVM perspectives when a View behaviour encapsulated in ViewModel. So Keep it Simple and expose straightforward bool AlertVisible
property.
EDIT: Regarding naming suggestion in the comment
Absolutely agree! I would suggest renaming AmountVisible
to IsAmountSpecified
or something like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With