2 Replies - 2133 Views - Last Post: 08 May 2014 - 11:09 PM

#1 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3459
  • View blog
  • Posts: 11,711
  • Joined: 12-December 12

WPF Commands clarity

Posted 07 May 2014 - 02:28 PM

I'm trying to find some clarity about the use of Commands in WPF. Specifically:

Are they a good thing?
Why are they good?


The last answer at this SO topic says:

Quote

commands are not linked to the caller, so same command is not dependent and can be called from menu item, toolbar button, keyboard, etc.

This seems a bit woolly to me. I agree that CanExecute is cool but this alone may not be enough to justify their use.

Also, how do you use them? We can create Commands, implement ICommand, use a static class or a RelayCommand (and more).

Is This A Good Question/Topic? 0
  • +

Replies To: WPF Commands clarity

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5507
  • View blog
  • Posts: 11,808
  • Joined: 02-June 10

Re: WPF Commands clarity

Posted 08 May 2014 - 05:45 PM

Commands are VERY good. Not only for the CanExecute feature, but they tend to keep people coding cleanly. They keep people from putting all their work inside a button.click handler method for example.

As computers become more user friendly they become more complex for the developer. There are so many ways to do the same thing: You can have a button that calls Print(), a keystroke, a touchscreen gesture, maybe a hardwired controller through some I.O. port, and a TCP/ip command, a game controller connected to the PC, [...] <catch my breath>

So you simply wire each of these input methods to raise the Print command. From there, your Window, menubar, code behind, widget, whatever is done. Virtually no work in the Window itself. Then you have one class/file that handles the actual execution of the Print command. Everything neat and tidy. And, if you are providing extensibility for other developers to write plug-ins for your program, they don't have to know anything other than to call the Print command.

The graphic designer making the Window doesn't need to know jack about the code that does the printing, and the coder writing the Print logic doesn't care at all about what initiates it.
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3459
  • View blog
  • Posts: 11,711
  • Joined: 12-December 12

Re: WPF Commands clarity

Posted 08 May 2014 - 11:09 PM

cool, thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1