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);

posted @ 2011-12-19 11:33  xiaofoyuan  阅读(464)  评论(0编辑  收藏  举报