Prev | Current Page 541 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

[New].Execute(Nothing, targetElement)
The target element is simply the element where WPF begins looking for the command
binding. You can use the containing window (which has the command binding) or a nested
element (such as the actual element that fired the event).
Incidentally, you can also go through the Execute() method in the associated Command-
Binding object. In this case, you don??™t need to supply the target element, because it??™s automatically
set to the element that exposes the CommandBindings collection that you??™re using.
Me.CommandBindings(0).Command.Execute(Nothing)
This approach uses only half the command model. It allows you to trigger the command, but
it doesn??™t give you a way to respond to the command??™s state change. If you want this feature, you
may also want to handle the RoutedCommand.CanExecuteChanged to react when the command
becomes disabled or enabled. When the CanExecuteChanged event fires, you need to call the
RoutedCommand.CanExecute() method to check whether the commands are in a usable state.
If not, you can disable or change the content in a portion of your user interface.
COMMAND SUPPORT IN CUSTOM CONTROLS
WPF includes a number of controls that implement ICommandSupport and have the ability to raise commands.
(It also includes some controls that have the ability to handle commands, as you??™ll see shortly in the
section ???Controls with Built-in Commands.


Pages:
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553