
Routed Events have three main routing strategies: Direct Event, Bubbling Event, Tunneling Event. Direct Event: A direct event is similar to events in Windows forms which are raised by the element in which the event is originated. Unlike a standard CLR event, direct routed events support class handling and they can be used in Event Setters and Event Triggers within your style of your Custom Control. A good example of a direct event would be the MouseEnter event. Bubbling Event: A bubbling event begins with the element where the event is originated. Then it travels up the visual tree to the topmost element in the visual tree. As you probably have guessed, in WPF, the topmost element is most likely a window. Tunnel Event: The direction of Tunneling event is opposite to the Bubbling event. Here the event handlers on the element tree root are invoked and then the event travels down the visual tree to all the children nodes until it reaches the element in which the event originated. The difference between a bubbling and a tunneling event (apart from the direction) is that a tunneling event name will always start with a ‘preview’.
ICommand provide a mechanism for the view to update the model in the MVVM architecture. The ICommand interface is defined inside the System.Windows.Input namespace. It has two methods: bool CanExecute (object parameter) which determinate if the command can be executed or not. void Execute (object parameter) which tells the command what to do when fired. we will “hook” the command into a button, instead of creating a Click event
More topics covered:
- Routed Events – source, has-handled
- ICommand RelayCommand wrapper
- ICommand ActionCommand
- Prism.WPF – nugget
- DelegateCommand – RaiseCanExecuteChanged
Links:
- Class code: Homework solution
- Class code: Routed Events
- Class code: ICommand
- Home Work!
- Lesson Summary Video!
