15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Workflows ❘ 1335<br />

}<br />

vm.InitializeViewModel(new Sequence());<br />

this.DataContext = vm;<br />

Here, we construct the view model, <strong>and</strong>, by default, add in a Sequence activity so that something is<br />

displayed onscreen when the application runs. Figure 44-15 shows what the screen looks like if you run the<br />

application at this point.<br />

figure 44-15<br />

The only part missing now is some comm<strong>and</strong>s. We use a DelegateComm<strong>and</strong> class to write IComm<strong>and</strong>-based<br />

comm<strong>and</strong>s for WPF, as then we find the code in the view model is easy to underst<strong>and</strong>. The comm<strong>and</strong>s are<br />

fairly trivial to implement, as is evident by the New comm<strong>and</strong> shown here:<br />

public IComm<strong>and</strong> New<br />

{<br />

get<br />

{<br />

return new DelegateComm<strong>and</strong>(unused =><br />

{<br />

InitializeViewModel(new Sequence());<br />

});<br />

}<br />

}<br />

This comm<strong>and</strong> is bound to the New menu item, so when that is clicked the delegate is executed, <strong>and</strong> in<br />

this instance that simply calls the InitializeViewModel method with a new Sequence activity. Because<br />

this method also raises the property change notification for the designer <strong>and</strong> the property grid, these are<br />

updated, too.<br />

The Open comm<strong>and</strong> is a little more involved but not much:<br />

public IComm<strong>and</strong> Open<br />

{<br />

get<br />

{<br />

return new DelegateComm<strong>and</strong>(unused =><br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!