wp7 >> 通过后台代码给ListBoxItem添加ContextMenu 属性

//创建ListBoxItem

ListBoxItem li = new ListBoxItem();
 li.Content = "test";

//创建ContextMenu
            ContextMenu menu = new ContextMenu();

            MenuItem menuItem1 = new MenuItem();
            menuItem1.Header = "This is Menu Item 1";
            menuItem1.Click += new RoutedEventHandler(MenuItem_Click);
            menu.Items.Add(menuItem1);

            MenuItem menuItem2 = new MenuItem();
            menuItem2.Header = "This is Menu Item 2";
            menuItem2.Click += new RoutedEventHandler(MenuItem_Click);
            menu.Items.Add(menuItem2);

//将ContextMenu 绑定到ListBoxItem

ContextMenuService.SetContextMenu(li, menu);

你可能感兴趣的:(contextMenu)