ContextMenu cm =new ContextMenu();//新建右键菜单
MenuItem mi =new MenuItem();//新建右键菜单项
mi.Header ="菜单项";
mi.Click += MenuItem_Click;//为菜单项注册事件
cm.Items.Add(mi);
ContextMenuService.SetContextMenu(btnRight, cm);//为控件绑定右键菜单