Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

18. WPF Interactions > Hooking Up Commands

Hooking Up Commands

There are a lot of objects involved in the commanding process, but there are only three steps to the process. You can perform the steps in any order.

A SET THE COMMAND PROPERTY ON THE SOURCE

The ICommandSource interface exposes three properties: Command, CommandParameter and CommandTarget; any widget that can act as a control source will expose these as simple properties (they’re actually dependency properties) that can be set in XAML or code:

image

In most situations that’s all you’ll need to do, but you can also set the CommandParameter and CommandTarget properties if you need to. The syntax is identical.

B WRITE THE HANDLERS

You’ll need two. The handler for the CanExecute event needs to match the signature for the CanExecuteRoutedEventHandler, which is:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


 Â