Developing Mobile Apps — Question 6

You are developing a Universal Windows Platform (UWP) app that uses XAML and C#. The app must use the Model-View-ViewModel (MVVM) pattern.
The user interface (UI) triggers an event.
You need to bind the event to a view model method.
What should you do?

Answer options

Correct answer:

Explanation

The correct answer is A because creating a custom behavior allows you to attach event triggers to UI elements in a way that adheres to the MVVM pattern, enabling separation of concerns. Options B, C, and D do not follow the MVVM principles as effectively; B involves using an attached property which is less common for commands, C focuses on data binding rather than event handling, and D involves code-behind, which violates the MVVM principle of keeping logic out of the view.