WPF ICommand RoutedCommand

WPF ICommand全部綁定的命令都必須實現ICommand. windows

該接口定義了一個execute方法, 一個canExecute方法,還有一個CanExecuteChanged事件屬性。 app

RoutedCommand是WPF中惟一繼承ICommand的類,它不包含任何應用程序邏輯,只表明了一個命令。 ide

As you have noticed the RoutedCommand class is an implementation of the ICommand interface, its main distinction if that its function is similar to that of a RoutedEvent: wordpress

The Execute and CanExecute methods on a RoutedCommand do not contain the application logic for the command as is the case with a typical ICommand, but rather, these methods raise events that traverse the element tree looking for an object with a CommandBinding. The event handlers attached to the CommandBinding contain the command logic. this

The Execute method raises the PreviewExecuted and Executed events. The CanExecute method raises the PreviewCanExecute and CanExecute events. spa

In a case when you don't want the behavior of the RoutedCommand you'll be looking at your own implementation of ICommand. As for the MVVM pattern I can't say that one solution, it seems that everyone has their own methodology. However, here are a few approaches to this problem that I've come across: code

相關文章
相關標籤/搜索