<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JAPF &#187; command</title>
	<atom:link href="http://www.japf.fr/tag/command/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.japf.fr</link>
	<description>Jeremy Alles Presentation Foundation: WPF, .Net and modern software development</description>
	<lastBuildDate>Thu, 29 Jul 2010 07:29:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A quick tour of existing MVVM frameworks</title>
		<link>http://www.japf.fr/2009/10/a-quick-tour-of-existing-mvvm-frameworks/</link>
		<comments>http://www.japf.fr/2009/10/a-quick-tour-of-existing-mvvm-frameworks/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 09:00:27 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[icommand]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[mvvm]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=259</guid>
		<description><![CDATA[[Article updated november, 26th: see my latest blog post for a better experience browsing the frameworks] One year ago MVVM wasn’t very famous. I remember the first article I read about it, about using MVVM to simplify the management of treeview controls. In the last six months, MVVM has been quickly promoted to THE methodology [...]]]></description>
			<content:encoded><![CDATA[<p><strong>[Article updated november, 26th: see <a href="http://www.japf.fr/2009/11/discover-compare-existing-mvvm-frameworks/">my latest blog post</a> for a better experience browsing the frameworks]</strong></p>
<p><span id="more-259"></span></p>
<p>One year ago MVVM wasn’t very famous. I remember the first article I read about it, about <a href="http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx">using MVVM to simplify the management of treeview controls</a>. In the last six months, MVVM has been quickly promoted to THE methodology to use when developing WPF applications. During this amount of time, famous WPF developers started to merge their existing MVVM classes into libraries. Those libraries are now known as MVVM frameworks and contain classes designed to help developers to use MVVM in their projects.</p>
<p>In this article, I’m going to make a quick tour of the available MVVM frameworks.</p>
<p><strong>If your own framework is not in this list or if I made a mistake while describing your work, please let me know using the contact form (available at the top of this page).</strong></p>
<p>Common features:</p>
<ul>
<li>ViewModelBase class (for the implementation of the INotifyPropertyChanged interface)</li>
<li>RelayCommand like class to link UI command to ViewModel’s handlers</li>
<li>Unit tests comes with the framework</li>
</ul>
<p><a href="http://sachabarber.net/?page_id=523">Cinch</a></p>
<ul>
<li>Author: <a href="http://sachabarber.net">Sacha Barber</a></li>
<li>Silverlight support: no</li>
<li>Documentation: excellent, 6 articles published on CodeProject</li>
<li>Hosting : <a href="http://cinch.codeplex.com/">CodePlex</a></li>
<li>License:  Code Project Open License</li>
<li>Features:
<ul>
<li>attached behaviors</li>
<li>validation suing IDataErrorInfo</li>
<li>support for IEditableObject</li>
<li>weak events creation and subscription</li>
<li>mediator messaging using weak events</li>
<li>IOC/DI support (using Unity)</li>
<li>services: event logger, message box, open save dialog, popup</li>
<li>threading helpers</li>
<li>support for menu items</li>
<li>closeable viewmodels</li>
<li>MVVM code generator</li>
</ul>
</li>
</ul>
<p><a href="http://www.galasoft.ch/mvvm/getstarted/">MVVM Light Toolkit </a></p>
<ul>
<li>Author: <a href="http://www.galasoft.ch/index.html">Laurent Bugnion</a></li>
<li>Silverlight support: yes</li>
<li>Documentation: many articles available on Laurent’s blog + other developers as well</li>
<li>Hosting: <a href="http://mvvmlight.codeplex.com/">CodePlex</a></li>
<li>License: MIT license</li>
<li>Features:
<ul>
<li>MSI installer</li>
<li>VS project and item template</li>
<li>VS code snippets</li>
<li>Messenger system for inter-viewmodel communication</li>
</ul>
</li>
</ul>
<p><a href="http://www.julmar.com/blog/mark/2009/08/04/MVVMHelpersV103.aspx">MVVM Helpers</a></p>
<ul>
<li>Author: <a href="http://www.julmar.com/blog/mark/">Mark Smith</a></li>
<li>Silverlight support: no</li>
<li>Documentation: some articles on Mark’s blog</li>
<li>Hosting: personal website</li>
<li>License: not defined</li>
<li>Features:
<ul>
<li>attached behaviors</li>
<li>viewmodel creation using markup extension</li>
<li>attributes based validation</li>
<li>IOC/DI using ServiceProvider approach</li>
<li>closeable viewmodel</li>
<li>wait cursor (using new WaitCursor() { // your code here })</li>
</ul>
</li>
</ul>
<p><a href="http://mvvmfoundation.codeplex.com/">MVVM Foundation</a></p>
<ul>
<li>Author: <a href="http://joshsmithonwpf.wordpress.com/">Josh Smith</a></li>
<li>Silverlight support: no</li>
<li>Documentation: articles about the Messenger implementation on Josh or Marlon Grech’s blog</li>
<li>Hosting: <a href="http://mvvmfoundation.codeplex.com/">CodePlex</a></li>
<li>License: MS-PL</li>
<li>Features:
<ul>
<li>Messenger system for inter-viewmodel communication</li>
<li>PropertyChanged event monitor</li>
</ul>
</li>
</ul>
<p><a href="http://www.caliburnproject.org/">Caliburn</a></p>
<ul>
<li>Author: <a href="http://robeisenberg.com/Work.aspx">Rob Eisenberg</a></li>
<li>Silverlight support: yes</li>
<li>Documentation: complete <a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=Table%20Of%20Contents">online documentation</a> available</li>
<li>Hosting: CodePlex http://www.codeplex.com/caliburn</li>
<li>License: MIT license</li>
<li>Features:
<ul>
<li> commands are built on top of Actions and thus share many of the same features, including multiple input parameters, filters and automatic asynchronous execution</li>
<li>presenters that handles UI lifecycle issue such as handling activation, deactivation and shutdown semantics for various UI components</li>
<li>Caliburn applications are fully testable</li>
<li>various utilities such as a background task manager</li>
<li>supports various UI pattern (not MVVM only)</li>
<li>dependency injection container</li>
</ul>
</li>
</ul>
<p><a href="http://wpfonyx.codeplex.com/">Onyx</a></p>
<ul>
<li>Author: William e Kempf</li>
<li>Silverlight support: no</li>
<li>Documentation: basic <a href="http://wpfonyx.codeplex.com/Wiki/View.aspx?title=Introduction">introduction</a> available on CodePlex</li>
<li>Hosting: <a href="http://wpfonyx.codeplex.com/">CodePlex</a></li>
<li>License: not specified</li>
<li>Features:
<ul>
<li> ServiceLocator pattern</li>
<li>ViewModel creation using a custom markup extension</li>
<li>UI related services such as IDisplayMessage</li>
</ul>
</li>
</ul>
<p><a href="http://calcium.codeplex.com/">Calcium</a></p>
<ul>
<li>Author: <a href="http://danielvaughan.orpius.com/">Daniel Vaughan</a></li>
<li>Silverlight support: no</li>
<li>Documentation: 2 very detailed articles on CodeProject (<a href="http://www.codeproject.com/KB/WPF/CalciumPart01.aspx">part1</a> and <a href="http://www.codeproject.com/KB/WPF/CalciumPart02.aspx">part2</a>)</li>
<li>Hosting: <a href="http://calcium.codeplex.com/">CodePlex</a></li>
<li>License: use, copy, modify, and/or distribute and keep the copyright!</li>
<li>Features:
<ul>
<li> Module Manager for enabling or disabling of modules at runtime</li>
<li>messaging services for interacting with the user from the client or server using the same API</li>
<li>Command Service to associate WPF ICommands with content interfaces that only become active when an active view or viewmodel implements the interface</li>
<li>Region Adapters for ToolBars and Menus</li>
<li>Client-server logging ready to work out-of-the-box</li>
<li>Includes modules, such as a Web Browser, Text Editor, Output Window, and many more</li>
<li>Tabbed interface with dirty file indication (reusable across modules)</li>
</ul>
</li>
</ul>
<p><a href="http://www.orktane.com/Blog/">nRoute</a></p>
<ul>
<li>Author: <a href="http://www.orktane.com/Blog/">Rishi</a></li>
<li>Silverlight support: yes</li>
<li>Documentation: many articles available on author&#8217;s blog (see CodePlex project home page for the links)</li>
<li>Hosting: <a href="http://nroute.codeplex.com/">CodePlex</a></li>
<li>License: MS-PL</li>
<li>Features:
<ul>
<li> support Blend3 behaviors and triggers models</li>
<li>resource locator framework</li>
<li>view services: OpenFileDialog, ShowMessage&#8230;</li>
<li>uses attributes to map View and ViewModel together</li>
</ul>
</li>
</ul>
<p><a href="http://nitomvvm.codeplex.com/">Nito MVVM</a></p>
<ul>
<li>Author: Shammah</li>
<li>Silverlight support: no</li>
<li>Documentation: no</li>
<li>Hosting: <a href="http://nitomvvm.codeplex.com/">CodePlex</a></li>
<li>License: not specified</li>
<li>Features:
<ul>
<li> various MVVM friendly implementations of the ICommand interface</li>
</ul>
</li>
</ul>
<p><a href="http://karlshifflett.wordpress.com/">Ocean</a></p>
<ul>
<li>Author: <a href="http://karlshifflett.wordpress.com/">Karl Shifflet</a></li>
<li> Silverlight support: no</li>
<li>Documentation: articles available on Karl&#8217;s blog</li>
<li>Hosting: personal website</li>
<li>License: not specified</li>
<li>Features:
<ul>
<li> written in VB.Net</li>
<li>attribute based validation</li>
<li>viewmodel base classes: relaycommand, closeableviewmodel&#8230;</li>
<li>SQL server data access layer</li>
</ul>
</li>
</ul>
<p><a href="http://coremvvm.codeplex.com/">Basic MVVM framework</a></p>
<ul>
<li>Author: <a href="http://blogs.msdn.com/llobo/default.aspx">Lester Lobo</a></li>
<li> Silverlight support: no</li>
<li>Documentation: sample application available with the library</li>
<li>Hosting: <a href="http://coremvvm.codeplex.com/">CodePlex</a></li>
<li>License: MS-PL</li>
<li>Features:
<ul>
<li> delegating Commands\Keybinding</li>
<li>messaging between VM&#8217;s</li>
<li>handling events as commands with attached behaviors</li>
<li>handling dialogs (and more) as services</li>
<li>VS code snippets</li>
</ul>
</li>
</ul>
<p><a href="http://goldlight.codeplex.com/">GoodLight</a></p>
<ul>
<li>Author: <a href="http://peteohanlon.wordpress.com/">Peter O&#8217;Hanlon</a><em> </em><em></em></li>
<li> Silverlight support: yes</li>
<li>Documentation: sample application available with the library</li>
<li>Hosting: <a href="http://goldlight.codeplex.com/">CodePlex</a></li>
<li>License: MS-PL</li>
<li>Features:
<ul>
<li> &#8220;workspace&#8221; management (set of document that can be closed)</li>
<li>skin support</li>
<li>messaging between VM&#8217;s</li>
</ul>
</li>
</ul>
<p>As you can see, each frameworks has its pros and cons. If you want a light Silverlight-compatible framework, Laurent&#8217;s framework is very nice. If you want a very rich framework, Sacha&#8217;s one is excellent. Whatever what your requirements are, each framework is very interesting and browsing the source code is a good way to understrand how stuff works and find cool ideas for your own needs.</p>
<p>To conclude, I&#8217;d like to thanks all those people who work very hard for the community ! An interesting discussion started a couple of days ago on the <a href="http://groups.google.com/group/wpf-disciples">WPF disciples Google group</a> about the creation of a common framework. Have a look <a href="http://groups.google.com/group/wpf-disciples/browse_thread/thread/6b6c60b835cfd8f2">here</a>.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.japf.fr%2f2009%2f10%2fa-quick-tour-of-existing-mvvm-frameworks%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.japf.fr%2f2009%2f10%2fa-quick-tour-of-existing-mvvm-frameworks%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/10/a-quick-tour-of-existing-mvvm-frameworks/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Model-View-ViewModel, Commands and InputBindings</title>
		<link>http://www.japf.fr/2009/01/model-view-viewmodel-commands-and-inputbindings/</link>
		<comments>http://www.japf.fr/2009/01/model-view-viewmodel-commands-and-inputbindings/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 14:50:19 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[mvvm]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=114</guid>
		<description><![CDATA[Article updated ! I find out that the Command property of the KeyBinding class is not a DependencyProperty&#8230; This prevent using the syntax I wanted (binding to an ICommand exposed in the ViewModel). There are several workarounds you can find across the web (using a MarkupExtension, an attached properies&#8230;) but because I didn&#8217;t have much [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Article updated !</strong> I find out that the Command property of the KeyBinding class is not a DependencyProperty&#8230; This prevent using the syntax I wanted (binding to an ICommand exposed in the ViewModel). There are several workarounds you can find across the web (using a MarkupExtension, an attached properies&#8230;) but because I didn&#8217;t have much time, I finally put some glue in my code-behind ;(</p>
<p>I&#8217;m still playing with MVVM those days and today, I needed a simple behavior I didn&#8217;t know how to do with MVVM. I finally found a simple solution and as I love them, it&#8217;s 100% XAML :p</p>
<p>The problem is simple, I have a ListBox where the user can type date in it.<br />
When the User Validate his input, I need to process the text entered and return another value.<br />
The User can validate the input by pressing the Enter key while the TextBox has the focus.</p>
<p>My first attempt was the subscribe to the KeyUp event, and in the code-behind, delegate the work to the associated ViewModel class. I don&#8217;t like that solution a lot (events handler in code-behind are sort of ugly&#8230;).</p>
<p>I know I could define an ICommand in my ViewModel and do the work directly there (using the excellent RelayCommand class written by Josh Smith). The problem was how to trigger this command when the Enter key is pressed. well, actually it&#8217;s pretty simple:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p114code2'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1142"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p114code2"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Hello world&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;40&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox.InputBindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #808080; font-style: italic;">&lt;!-- update: we cannot use Binding to the Command property as it's not a DP --&gt;</span>
            <span style="color: #808080; font-style: italic;">&lt;!-- workarounds exist such a MarkupExtension, AttachedProperty... -&gt;</span>
<span style="color: #808080; font-style: italic;">            &lt;!-- personally, I did that in the code behind to make it works :( --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;KeyBinding</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;{Binding ProcessInput}&quot;</span> <span style="color: #000066;">Key</span>=<span style="color: #ff0000;">&quot;Enter&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TextBox.InputBindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>            
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TextBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>As I updated the article (because Command is not a DP), I finally did the same thing in C# in the code-behind&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/01/model-view-viewmodel-commands-and-inputbindings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to attach commands to any UIElement ?</title>
		<link>http://www.japf.fr/2008/12/how-to-attach-commands-to-any-uielement/</link>
		<comments>http://www.japf.fr/2008/12/how-to-attach-commands-to-any-uielement/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 12:12:39 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[attached behavior]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[icommand]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=22</guid>
		<description><![CDATA[In this blog, I already wrote 2 posts about attached properties. The more I play with this new WPF concept, the more I like it. Today at work, I found one new nice use of attached properties, and because it is this time reusable, I decided to share my experience here. If you&#8217;re familiar with [...]]]></description>
			<content:encoded><![CDATA[<p>In this blog, I already wrote 2 posts about attached properties. The more I play with this new WPF concept, the more I like it. Today at work, I found one new nice use of attached properties, and because it is this time reusable, I decided to share my experience here.</p>
<p>If you&#8217;re familiar with WPF, then you&#8217;re probably familiar with Commands. Commands are a new concept in WPF, here is the introduction from <a href="http://msdn.microsoft.com/en-us/library/ms752308.aspx">MSDN</a> documentation:</p>
<p><em>Commanding is an input mechanism in Windows Presentation Foundation (WPF) which provides input handling at a more semantic level than device input. Examples of commands are the Copy, Cut, and Paste operations found on many applications. </em></p>
<p>Commands help you to decouple your UI from its execution logic and also simplify the process of enabling and disabling controls regarding the state of the command. If you want more details about Commands, you can check out <a href="http://marlongrech.wordpress.com/2007/11/11/wpf-commands/">this nice post</a> from <a href="http://marlongrech.wordpress.com">Marlon Grech</a>.</p>
<p>You can attach a command to a Button using its Command property (you might also use CommandParameter and CommandTarget properties in some cases). To be more precise, elements that support Command must implement the <em>ICommandSource </em>interface:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p22code5'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p225"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p22code5"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">interface</span> ICommandSource
<span style="color: #008000;">&#123;</span>
ICommand Command <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #6666cc; font-weight: bold;">object</span> CommandParameter <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
IInputElement CommandTarget <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>If you open <a href="http://reflector.red-gate.com/">Reflector</a> and lookup for this interface, you&#8217;ll discover that 3 controls implement this interface:</p>
<ul>
<li>MenuItem</li>
<li>ButtonBase</li>
<li>Hyperlink</li>
</ul>
<p>In the project I&#8217;m working on at work, I had to find out a way to surpass 2 limitations:</p>
<ul>
<li>Defining commands on other controls than MenuItem, ButtonBase and Hyperlink</li>
<li>Defining commands that could be triggered on other event than MouseLeftButtonUp</li>
</ul>
<p>As you can imagine, I found a way to do that using&#8230; attached properties ! Basically I defined an attached property that I called MouseDoubleClickCommandProperty. This command enables you to attach a ICommand to <strong>ANY </strong>UIElement that will be triggered when the control is double clicked.</p>
<p>The MouseDoubleClickCommandProperty register a PropertyChangedCallback so that when the target changes, I can register on the UIElement.MouseDownEvent event. By looking the ClickCount property of the MouseButtonEventArgs parameter, I can check the MouseDownEvent comes from a DoubleClick event, and then trigger the associated command.</p>
<p>A nice example of this concept can be found in a TreeView. Imagine you want to start an action when a particular node in your TreeView is double clicked. The basic way to do that is to register the MouseDoubleClick event on the control. The new way to do the same thing is to use the MouseDoubleClickCommandProperty attached propery. Here is an example that shows how to do that in a hierarchical data template:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p22code6'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p226"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p22code6"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;HierarchicalDataTemplate</span></span>
<span style="color: #009900;">  <span style="color: #000066;">DataType</span>=<span style="color: #ff0000;">&quot;{x:Type treeViewModel:Node}&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding Path=Children}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">attached:ClickBehavior.MouseDoubleClickCommand</span>=<span style="color: #ff0000;">&quot;{Binding Path=Command}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;image&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;3,0&quot;</span> <span style="color: #000066;">Source</span>=<span style="color: #ff0000;">&quot;..\Resources\Icons\Treeview\Default16.png&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=Name}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/HierarchicalDataTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>As you can see, by using the MouseDoubleClickCommand attached property is becomes possible to attach the command to a StackPanel ! Moreoever, because we might need to pass parameter to the ICommand, I also defined another attached properties that can hold any parameter you want, this is the MouseEventParameterProperty. </p>
<p>Similarly, we can imagine to trigger Commands when a RightClick occurs (we would just have to define a new attached property to do so).</p>
<p>I did <a href="http://www.japf.fr/download/ClickCommandDemo.zip">a sample application</a> that demonstrates the concept of this article. Because I didn&#8217;t have too much time, I used a ListBox instead of a TreeView. but the concepts are equivalent. Please feel free to comment <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2008/12/how-to-attach-commands-to-any-uielement/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
