I am new in MVVM. I just learn this pattern and want to use it in my project. I am already understand working principle of this pattern and learned how to use Commands. But I have question how to handle events of another controls for example ListBox SelectionChanged event. ListBox haven’t Command attribute
Share
You often don’t need to. For example, you can just bind the
ListBox‘sSelectedItemproperty to a property on your view model:Not only does this give you access to the selected customer in your view model, it also allows your view model to dictate the selected customer by setting the property itself.
There are other techniques to “avoid” direct handling of events in your code-behind, too. For example, attached behaviors. However, you shouldn’t be scared of handling events directly if the code is solely concerned with the view and makes your code simpler.