Commands in WPF rock, they provide a very nice abstraction from the implementation and invocation of what you would consider a command in an application. I have been learning about WPF over the last few weeks and I have found many subjects in that technology that I really like; but commands were not something that I groked immediately.
The reason being I read about them first in Chris Andersons book Essential Windows Presentation Foundation (an excellent book), at the time I read it I liked the idea and moved on – until I read about them in Chris Sells and Ian Griffiths book Programming Windows Presentation Foundation, here I was introduced to the fact that WPF provides a whole bunch of commands. This was the point I missed in Chris A’s book, as he presents the topic by getting you to build a command, slowly taking you one step at a time – but he never does the big reveal, he seemed to save that for Chris S!
What I’m going to do here is show the simple XAML required to use a command in a couple places, like a menu and a button and then how to wire those up to a piece of code. For all the gory details on commands in WPF I’ll refer you to Chris and Chris. However, what I think is lacking is a simple example of how these ideas come together in a simple example (more...)