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

Hosting a ContextMenu in a ListBoxItem

Sometimes the need arises to provide a context menu for dynamically generated elements, such as those presented using a data bound ItemsControl. The following example demonstrates how to host a context menu for each item in a ListBox.

The ContextMenuViewModel contains an ObservableCollection of strings, declared as shown:

readonly ObservableCollection<string> items                  = new ObservableCollection<string>();public IEnumerable<string> Items{    get    {        return items;    }}

The items collection is populated within the viewmodel constructor. In addition, a new command, named DeleteCommand, is placed in the viewmodel. When the command is executed, it removes the ...

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