怎样在后台代码中实现自定义命令绑定

搜索引擎搜 wpf commamd binding code behind 跳出来的答案,我猜差不多、就是把command加到window里,在绑定控件的command属性 CommandBinding cb = new CommandBinding(); cb.Command = MyAppCommands.MyCommand; cb.Executed += new ExecutedRoutedEventHandler(cb_Executed); //将要执行的命令对象添加到窗体的命令对象集合中 this.CommandBindings.Add(cb); //设定菜单项和按钮都执行MyCommand命令 btn.Command = MyAppCommands.MyCommand;


    推荐阅读