O'Reilly logo

Windows® Phone 8 Unleashed by Daniel Vaughan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ContextMenu and MVVM

So far you have seen the ContextMenu employed with hardwired MenuItems and Click events. This approach is adequate for simple apps. Yet, the MenuItem class supports ICommands out of the box. And, with this, you can bind a viewmodel’s ICommand to a MenuItem, removing the need for Click event handlers in the code-beside.

To demonstrate, we bind a viewmodel command to a MenuItem, which displays a message to the user. The ContextMenuViewModel class, in the downloadable sample code, contains a ShowMessageCommand property, declared as shown:

readonly DelegateCommand showMessageCommand;public ICommand ShowMessageCommand{    get    {        return showMessageCommand;    }}

The task of the ShowMessageCommand ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required