日期:2014-05-18 浏览次数:20772 次
<ContextMenu x:Key="AddMenu"> <MenuItem Header="新建文件夹" Command="ApplicationCommands.New"> </MenuItem> <MenuItem Header="新建文本文件" Command="ApplicationCommands.New"> </MenuItem> <MenuItem Header="新建word" Command="ApplicationCommands.New"> </MenuItem> </ContextMenu>
<Window.CommandBindings> <CommandBinding Command="ApplicationCommands.New" CanExecute="FolderCanAdd" Executed="AddFolder" /> <CommandBinding Command="ApplicationCommands.New" CanExecute="TxtCanAdd" Executed="AddTxt" /> <CommandBinding Command="ApplicationCommands.New" CanExecute="WordCanAdd" Executed="AddWord" /> </Window.CommandBindings>
public MainWindow() { InitializeComponent(); ContextMenu menu = this.Resources["AddMenu"] as ContextMenu; menu.ContextMenuOpening += (s, e) => { //to do }; }