[WPF]DataGrid C#添加右键弹出选择菜单

private void dataGrid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            ContextMenu context = new ContextMenu();
            MenuItem item = new MenuItem();
            item.Header = "点击删除该行数据";
            item.Click += new RoutedEventHandler(item_Click);
            context.Items.Add(item);
            context.IsOpen = true;
        }
        void item_Click(object sender, RoutedEventArgs e)
        {
            // do something  
        }
//方法2
private void ContextMenuLoad() { ContextMenu context = new ContextMenu(); MenuItem item = new MenuItem(); item.Header = "点击删除该行数据"; item.Click += new RoutedEventHandler(item_Click); context.Items.Add(item); context.IsOpen = true; ContextMenuService.SetContextMenu(datagrid, context); }

 

posted @ 2014-07-16 14:21  iEvent  阅读(1890)  评论(0编辑  收藏  举报