Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Why do you want validate before setting it? That is not something that is normally done. Commented Nov 21, 2017 at 13:28
  • @Euphoric Let me, maybe, provide you with a more specific scenario. Logged in user has some set of permissions. Depending on a particular permission application before setting the value of State property should check if some other property of ViewModel has a value. If not then the app should prompt user for a confimration whether it's OK to change state even though that other property does not have a value. Hopefully it gives you more context. If you think this information is important I can add it to the main question desription. Commented Nov 21, 2017 at 13:53
  • 1
    This might be question for UX.StackExchange, but wouldn't it be better if you had "Current value" field that is read-only and "Set to" field with button to set it? It would simplify the operation and would it make clearer that setting the value is not so straightforward. Also, I remember WPF checkbox doesn't like if you have this kind of "validation" under it. Eg. if you don't set the value that it sends. Commented Nov 21, 2017 at 14:08
  • I've considered this option. But do you think it's OK to flood ViewModel with lots of miscelaneous properties whose sole purpose it to make ViewModel being easier to use by View? I thought that ViewModel shoul only expose necessary minimum of API to View. Otherwise teoretically each significant upgrade of view layer will require updating ViewModel layer because what was convenient today may not be convenient tomorrow. This approach looks like a code smell (tight coupling perhaps). Commented Nov 21, 2017 at 14:28
  • 1
    I wouldn't consider it tight coupling. I would see it more as ViewModel clearly communicating that some property's setter might cause additional actions and that it might not be trully set if value is sent to it. This is Principle of Least Surprise in action. Commented Nov 21, 2017 at 15:01