<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: AttachedCommandBehavior aka ACB</title>
	<atom:link href="http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/feed/" rel="self" type="application/rss+xml" />
	<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/</link>
	<description>my life in Avalon ....</description>
	<lastBuildDate>Mon, 04 Jan 2010 23:11:44 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: somnambulist</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-3232</link>
		<dc:creator>somnambulist</dc:creator>
		<pubDate>Wed, 09 Dec 2009 16:35:56 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-3232</guid>
		<description>Ops I meant ... &quot; to trigger RoutedCommands&quot; ... not &quot; firing routed events&quot;

(well technical it is firing a RoutedEvent)</description>
		<content:encoded><![CDATA[<p>Ops I meant &#8230; &#8221; to trigger RoutedCommands&#8221; &#8230; not &#8221; firing routed events&#8221;</p>
<p>(well technical it is firing a RoutedEvent)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: somnambulist</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-3231</link>
		<dc:creator>somnambulist</dc:creator>
		<pubDate>Wed, 09 Dec 2009 16:34:13 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-3231</guid>
		<description>Hi,
I like it very much, finally a good way to bind my view to my ViewModel.

Since it was handy in my project I added the capability to fire routed events also.

Here the code:

class RoutedCommandExecutionStrategy : IExecutionStrategy
    {

        private static ExecutedRoutedEventArgs CreateExecutedRoutedEventArgs(ICommand command, object parameter)
        {
            var construktor = typeof(ExecutedRoutedEventArgs).GetConstructor(BindingFlags.NonPublic &#124; BindingFlags.Instance, null,
                new Type[] { typeof(ICommand), typeof(object) }, null);

            var argList = new object[] { command, parameter };
            ExecutedRoutedEventArgs foo = (ExecutedRoutedEventArgs)construktor.Invoke(BindingFlags.NonPublic, null, argList, Thread.CurrentThread.CurrentCulture);
            return foo;
        }


        #region IExecutionStrategy Member

        public CommandBehaviorBinding Behavior { get; set; }

        public void Execute(object parameter)
        {
            ExecutedRoutedEventArgs args = CreateExecutedRoutedEventArgs(Behavior.Command, parameter);
            args.RoutedEvent = CommandManager.ExecutedEvent;
            args.Source = Behavior.Owner;
            args.Handled = false;
            (Behavior.Owner as UIElement).RaiseEvent(args);
        }

        #endregion
    }

And than add the strategy in the CommandBehaviorBindings

        public ICommand Command
        {
            get { return command; }
            set
            {
                command = value;
                //set the execution strategy to execute the command or fire an ExecutionEvent
                if (command is RoutedCommand)
                    strategy = new RoutedCommandExecutionStrategy() { Behavior = this };
                else
                    strategy = new CommandExecutionStrategy { Behavior = this };                
            }
        }</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I like it very much, finally a good way to bind my view to my ViewModel.</p>
<p>Since it was handy in my project I added the capability to fire routed events also.</p>
<p>Here the code:</p>
<p>class RoutedCommandExecutionStrategy : IExecutionStrategy<br />
    {</p>
<p>        private static ExecutedRoutedEventArgs CreateExecutedRoutedEventArgs(ICommand command, object parameter)<br />
        {<br />
            var construktor = typeof(ExecutedRoutedEventArgs).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null,<br />
                new Type[] { typeof(ICommand), typeof(object) }, null);</p>
<p>            var argList = new object[] { command, parameter };<br />
            ExecutedRoutedEventArgs foo = (ExecutedRoutedEventArgs)construktor.Invoke(BindingFlags.NonPublic, null, argList, Thread.CurrentThread.CurrentCulture);<br />
            return foo;<br />
        }</p>
<p>        #region IExecutionStrategy Member</p>
<p>        public CommandBehaviorBinding Behavior { get; set; }</p>
<p>        public void Execute(object parameter)<br />
        {<br />
            ExecutedRoutedEventArgs args = CreateExecutedRoutedEventArgs(Behavior.Command, parameter);<br />
            args.RoutedEvent = CommandManager.ExecutedEvent;<br />
            args.Source = Behavior.Owner;<br />
            args.Handled = false;<br />
            (Behavior.Owner as UIElement).RaiseEvent(args);<br />
        }</p>
<p>        #endregion<br />
    }</p>
<p>And than add the strategy in the CommandBehaviorBindings</p>
<p>        public ICommand Command<br />
        {<br />
            get { return command; }<br />
            set<br />
            {<br />
                command = value;<br />
                //set the execution strategy to execute the command or fire an ExecutionEvent<br />
                if (command is RoutedCommand)<br />
                    strategy = new RoutedCommandExecutionStrategy() { Behavior = this };<br />
                else<br />
                    strategy = new CommandExecutionStrategy { Behavior = this };<br />
            }<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrecarlucci</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-3222</link>
		<dc:creator>andrecarlucci</dc:creator>
		<pubDate>Thu, 03 Dec 2009 20:17:08 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-3222</guid>
		<description>Hi, nice work!

But I&#039;m having a problem, I&#039;m trying to fire MouseLeftButtonUp as a Command but I always get null exception at CommandBehaviorBinding line 99. It seems that strategy is null. Any thoughts?

André Carlucci</description>
		<content:encoded><![CDATA[<p>Hi, nice work!</p>
<p>But I&#8217;m having a problem, I&#8217;m trying to fire MouseLeftButtonUp as a Command but I always get null exception at CommandBehaviorBinding line 99. It seems that strategy is null. Any thoughts?</p>
<p>André Carlucci</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ipotpal</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-3181</link>
		<dc:creator>ipotpal</dc:creator>
		<pubDate>Wed, 28 Oct 2009 19:23:17 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-3181</guid>
		<description>Great commands</description>
		<content:encoded><![CDATA[<p>Great commands</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: marlongrech</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2992</link>
		<dc:creator>marlongrech</dc:creator>
		<pubDate>Fri, 03 Jul 2009 21:43:11 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2992</guid>
		<description>here you go ... I made a small blog post on how to do this... 
http://marlongrech.wordpress.com/2009/07/03/how-to-get-the-eventargs-as-a-commandparameter-using-the-attachedcommandbehaviour/</description>
		<content:encoded><![CDATA[<p>here you go &#8230; I made a small blog post on how to do this&#8230;<br />
<a href="http://marlongrech.wordpress.com/2009/07/03/how-to-get-the-eventargs-as-a-commandparameter-using-the-attachedcommandbehaviour/" rel="nofollow">http://marlongrech.wordpress.com/2009/07/03/how-to-get-the-eventargs-as-a-commandparameter-using-the-attachedcommandbehaviour/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to get the EventArgs as a CommandParameter using the AttachedCommandBehaviour &#171; C# Disciples</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2991</link>
		<dc:creator>How to get the EventArgs as a CommandParameter using the AttachedCommandBehaviour &#171; C# Disciples</dc:creator>
		<pubDate>Fri, 03 Jul 2009 21:42:31 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2991</guid>
		<description>[...] How to get the EventArgs as a CommandParameter using the&#160;AttachedCommandBehaviour I have been asked many times how can I get the event args as a command parameter when using the AttachedCommandBehaviour. [...]</description>
		<content:encoded><![CDATA[<p>[...] How to get the EventArgs as a CommandParameter using the&nbsp;AttachedCommandBehaviour I have been asked many times how can I get the event args as a command parameter when using the AttachedCommandBehaviour. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergi Díaz</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2985</link>
		<dc:creator>Sergi Díaz</dc:creator>
		<pubDate>Thu, 02 Jul 2009 13:36:51 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2985</guid>
		<description>Actually no, I don&#039;t get it. I don&#039;t see how I can &quot;link&quot; the event delegate to an attached property... As far as I know, you can only assign a method to an event in XAML. Even if I make an attached property of type delegate I fail to see how I could assign that to an event :?
Unless... of course! I could globally subscribe to ListBoxItem.MouseDoubleClick, check if the ListBoxItem has an attached property (which would be a command in my case) and in case it has it, mark the event as handled and execute the command. Was that your idea?</description>
		<content:encoded><![CDATA[<p>Actually no, I don&#8217;t get it. I don&#8217;t see how I can &#8220;link&#8221; the event delegate to an attached property&#8230; As far as I know, you can only assign a method to an event in XAML. Even if I make an attached property of type delegate I fail to see how I could assign that to an event <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_confused.gif' alt=':?' class='wp-smiley' /><br />
Unless&#8230; of course! I could globally subscribe to ListBoxItem.MouseDoubleClick, check if the ListBoxItem has an attached property (which would be a command in my case) and in case it has it, mark the event as handled and execute the command. Was that your idea?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: marlongrech</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2984</link>
		<dc:creator>marlongrech</dc:creator>
		<pubDate>Thu, 02 Jul 2009 09:18:46 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2984</guid>
		<description>The attached property would do exactly what you are doing in code behind but in a more generic manner so that you can re use it. 

Are you getting it? if you want I can write up a small code sample for you...</description>
		<content:encoded><![CDATA[<p>The attached property would do exactly what you are doing in code behind but in a more generic manner so that you can re use it. </p>
<p>Are you getting it? if you want I can write up a small code sample for you&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergi Díaz</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2982</link>
		<dc:creator>Sergi Díaz</dc:creator>
		<pubDate>Thu, 02 Jul 2009 07:26:25 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2982</guid>
		<description>And how would I do that with an attached property? I don&#039;t have access to the EventArgs of an event on the ViewModel, and I don&#039;t really want to, that would break any design.
Actually, it makes sense to mark the event as handled once it executes a command, don&#039;t you think so?
I&#039;ve solved my problem with an &quot;old school&quot; approach - subscribing to a ListBox MouseDoubleClick event and getting the ListBoxItem that fired the event from e.OriginalSource, from there I can execute the command in its ViewModel object, and of course I can mark the event as handled. Not an elegant solution, mind you, but it works.
Don&#039;t take me wrong, I love what you&#039;ve done here, that&#039;s why I try to use this approach as much as possible! :D.</description>
		<content:encoded><![CDATA[<p>And how would I do that with an attached property? I don&#8217;t have access to the EventArgs of an event on the ViewModel, and I don&#8217;t really want to, that would break any design.<br />
Actually, it makes sense to mark the event as handled once it executes a command, don&#8217;t you think so?<br />
I&#8217;ve solved my problem with an &#8220;old school&#8221; approach &#8211; subscribing to a ListBox MouseDoubleClick event and getting the ListBoxItem that fired the event from e.OriginalSource, from there I can execute the command in its ViewModel object, and of course I can mark the event as handled. Not an elegant solution, mind you, but it works.<br />
Don&#8217;t take me wrong, I love what you&#8217;ve done here, that&#8217;s why I try to use this approach as much as possible! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: marlongrech</title>
		<link>http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2974</link>
		<dc:creator>marlongrech</dc:creator>
		<pubDate>Wed, 01 Jul 2009 20:29:45 +0000</pubDate>
		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/#comment-2974</guid>
		<description>by an attached behaviour I mean an attached property</description>
		<content:encoded><![CDATA[<p>by an attached behaviour I mean an attached property</p>
]]></content:encoded>
	</item>
</channel>
</rss>
