<?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/"
	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>Elad's WPF Blog</title>
	<atom:link href="http://eladm.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://eladm.wordpress.com</link>
	<description>WPF Thoughts &#38; Experiences</description>
	<lastBuildDate>Sat, 21 Jan 2012 15:22:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='eladm.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Elad's WPF Blog</title>
		<link>http://eladm.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://eladm.wordpress.com/osd.xml" title="Elad&#039;s WPF Blog" />
	<atom:link rel='hub' href='http://eladm.wordpress.com/?pushpress=hub'/>
		<item>
		<title>DataBinding Tips &amp; Tricks</title>
		<link>http://eladm.wordpress.com/2009/04/08/databinding-tips-tricks/</link>
		<comments>http://eladm.wordpress.com/2009/04/08/databinding-tips-tricks/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 10:40:11 +0000</pubDate>
		<dc:creator>Elad Malki</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Data Binding]]></category>

		<guid isPermaLink="false">http://eladm.wordpress.com/2009/04/08/databinding-tips-tricks/</guid>
		<description><![CDATA[Since DataBinding is one of the most important and useful features of WPF, here are some Tips &#38; Tricks regarding it: DataBinding CheatSheat  &#8211; This is a nice pdf summarizing most of DataBinding properties and options (via NBD Tech post) Debugging Tips- Look at the Visual Studio output window – It provides high level details [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=eladm.wordpress.com&amp;blog=6945660&amp;post=65&amp;subd=eladm&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since DataBinding is one of the most important and useful features of WPF, here are some Tips &amp; Tricks regarding it:</p>
<ul>
<li>DataBinding CheatSheat  &#8211; This is a nice <a href="http://www.nbdtech.com/Free/WpfBinding.pdf" target="_blank">pdf</a> summarizing most of DataBinding properties and options (via <a href="http://www.nbdtech.com/blog/archive/2009/02/02/wpf-xaml-data-binding-cheat-sheet.aspx" target="_blank">NBD Tech post</a>)</li>
<li>Debugging Tips-
<ul>
<li>Look at the Visual Studio output window – It provides high level details about the binding and is sufficient to “easy” problems like naming mismatch: If we want to bind to this Person class:</li>
</ul>
<pre class="code"><span style="color:blue;">      class </span><span style="color:#2b91af;">Person
</span>      {
<span style="color:blue;">           public string </span>FirstName { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
           <span style="color:blue;">public string </span>LastName { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
      }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>and have this XMAL:</li>
</ul>
<pre class="code"><span style="color:blue;">           &lt;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Text</span><span style="color:blue;">="{</span><span style="color:#a31515;">Binding </span><span style="color:red;">Path</span><span style="color:blue;">=Name, </span><span style="color:red;">Mode</span><span style="color:blue;">=OneWay}"/&gt;</span></pre>
<p>you will see the following error in the output window:</p>
<blockquote>
<pre class="code">System.Windows.Data Error: 39 : BindingExpression path error: Name' property not found on 'object' ''Person' (HashCode=1056119)'. BindingExpression:Path=Name; DataItem='Person' (HashCode=1056119); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')</pre>
</blockquote>
<ul>
<li>
<ul>
<li>Use <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.presentationtracesources.tracelevel.aspx" target="_blank">TraceLevel</a></li>
</ul>
</li>
</ul>
<p>TraceLevel is an <a href="http://msdn.microsoft.com/en-us/library/ms749011.aspx" target="_blank">AttachedProperty</a> introduced on .net 3.5, which adds trace information to the VS output window. In order to use it, you first need to add this xml namespace:</p>
<pre class="code"><span style="color:red;">           xmlns</span><span style="color:blue;">:</span><span style="color:red;">diag</span><span style="color:blue;">="clr-namespace:System.Diagnostics;assembly=WindowsBase"</span></pre>
<p>and then add the TraceLevel to the appropriate binding:</p>
<pre class="code"><span style="color:blue;">           &lt;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Text</span><span style="color:blue;">="{</span><span style="color:#a31515;">Binding </span><span style="color:red;">Path</span><span style="color:blue;">=Name, </span><span style="color:red;">Mode</span><span style="color:blue;">=OneWay,</span><span style="color:red;"> diag</span><span style="color:blue;">:</span><span style="color:blue;">PresentationTraceSources.TraceLevel=High}"/&gt;</span></pre>
<p>The output window will contain a detailed trace:</p>
<blockquote><p>System.Windows.Data Warning: 52 : Created BindingExpression (hash=35885827) for Binding (hash=37710717)</p>
<p>System.Windows.Data Warning: 54 :   Path: &#8216;Name&#8217;</p>
<p>System.Windows.Data Warning: 57 : BindingExpression (hash=35885827): Default update trigger resolved to PropertyChanged</p>
<p>System.Windows.Data Warning: 58 : BindingExpression (hash=35885827): Attach to System.Windows.Controls.TextBlock.Text (hash=13575069)</p>
<p>System.Windows.Data Warning: 63 : BindingExpression (hash=35885827): Resolving source</p>
<p>System.Windows.Data Warning: 66 : BindingExpression (hash=35885827): Found data context element: TextBlock (hash=13575069) (OK)</p>
<p>System.Windows.Data Warning: 67 : BindingExpression (hash=35885827): DataContext is null</p>
<p>System.Windows.Data Warning: 61 : BindingExpression (hash=35885827): Resolve source deferred</p>
<p>&#8216;BindingSample.vshost.exe&#8217; (Managed): Loaded &#8216;C:\WINDOWS\assembly\GAC_MSIL\PresentationFramework.Luna\3.0.0.0__31bf3856ad364e35\PresentationFramework.Luna.dll&#8217;, Skipped loading symbols. Module is optimized and the debugger option &#8216;Just My Code&#8217; is enabled.</p>
<p>System.Windows.Data Warning: 63 : BindingExpression (hash=35885827): Resolving source</p>
<p>System.Windows.Data Warning: 66 : BindingExpression (hash=35885827): Found data context element: TextBlock (hash=13575069) (OK)</p>
<p>System.Windows.Data Warning: 74 : BindingExpression (hash=35885827): Activate with root item Person (hash=21577349)</p>
<p>System.Windows.Data Warning: 104 : BindingExpression (hash=35885827):   At level 0 &#8211; for Person.Name found accessor &lt;null&gt;</p>
<p>System.Windows.Data Error: 39 : BindingExpression path error: &#8216;Name&#8217; property not found on &#8216;object&#8217; &#8221;Person&#8217; (HashCode=21577349)&#8217;. BindingExpression:Path=Name; DataItem=&#8217;Person&#8217; (HashCode=21577349); target element is &#8216;TextBlock&#8217; (Name=&#8221;); target property is &#8216;Text&#8217; (type &#8216;String&#8217;)</p>
<p>System.Windows.Data Warning: 76 : BindingExpression (hash=35885827): TransferValue &#8211; got raw value {DependencyProperty.UnsetValue}</p>
<p>System.Windows.Data Warning: 84 : BindingExpression (hash=35885827): TransferValue &#8211; using fallback/default value &#8221;</p>
<p>System.Windows.Data Warning: 85 : BindingExpression (hash=35885827): TransferValue &#8211; using final value &#8221;</p></blockquote>
<ul>
<li>Use an empty converter – You can set a converter on your binding, and set a breakpoint in the Convert\ConvertBack function. you can find a nice implementation of this <a href="http://marlongrech.wordpress.com/2007/12/18/debugging-wpf-databinding/" target="_blank">in this post</a></li>
</ul>
<ul></ul>
<ul>
<li>Snoop it – Using <a href="http://blois.us/Snoop/" target="_blank">Snoop</a> is always a good option for getting info about your app.
<ul>
<li>The “Binding Errors” column can provide binding related info.</li>
<li>The DataContext DP can provide info about the binding source.</li>
</ul>
</li>
</ul>
<ul>
<li><a href="http://11011.net/software/vspaste"></a>Strings Formatting -</li>
</ul>
<p><a href="http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.stringformat.aspx" target="_blank">StringFormat</a> is a .NET 3.5 SP1 property which may be used for formatting strings in binding. For example, instead of using this:</p>
<pre class="code"><span style="color:blue;">      &lt;</span><span style="color:#a31515;">WrapPanel</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Text</span><span style="color:blue;">="{</span><span style="color:#a31515;">Binding </span><span style="color:red;">Path</span><span style="color:blue;">=FirstName, </span><span style="color:red;">Mode</span><span style="color:blue;">=OneWay}"/&gt;
            &lt;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Text</span><span style="color:blue;">=" "/&gt;
            &lt;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Text</span><span style="color:blue;">="{</span><span style="color:#a31515;">Binding </span><span style="color:red;">Path</span><span style="color:blue;">=LastName, </span><span style="color:red;">Mode</span><span style="color:blue;">=OneWay}"/&gt;
      &lt;/</span><span style="color:#a31515;">WrapPanel</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>You may use this:</p>
<pre class="code"><span style="color:blue;">       &lt;</span><span style="color:#a31515;">WrapPanel</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">TextBlock</span><span style="color:blue;">&gt;
                &lt;</span><span style="color:#a31515;">TextBlock.Text</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">MultiBinding </span><span style="color:red;">StringFormat</span><span style="color:blue;">="{}{0} {1}"&gt;
                        &lt;</span><span style="color:#a31515;">Binding </span><span style="color:red;">Path</span><span style="color:blue;">="FirstName" </span><span style="color:red;">Mode</span><span style="color:blue;">="OneWay"/&gt;
                        &lt;</span><span style="color:#a31515;">Binding </span><span style="color:red;">Path</span><span style="color:blue;">="LastName" </span><span style="color:red;">Mode</span><span style="color:blue;">="OneWay"/&gt;
                    &lt;/</span><span style="color:#a31515;">MultiBinding</span><span style="color:blue;">&gt;
                &lt;/</span><span style="color:#a31515;">TextBlock.Text</span><span style="color:blue;">&gt;
            &lt;/</span><span style="color:#a31515;">TextBlock</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:#a31515;">WrapPanel</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The benefit here is double, there is only one binding instead of two, and only on TextBlock element instead of three. This may help performance especially when used as a DataTemplate of an ItemsControl with many items.</p>
<p>You may of course use the StringFormat for any other formatting you need (dates, currencies, etc.)</p>
<ul>
<li>Virtualizing -</li>
</ul>
<p>When binding to a large collection, consider using the following attached properties:</p>
<ul>
<li>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.isvirtualizing.aspx" target="_blank">VirtualizingStackPanel.IsVirtualizing</a>=Ture</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizationmode.aspx" target="_blank">VirtualizingStackPanel.VirtualizationMode</a>=&#8221;Recycling&#8221;</li>
</ul>
</li>
<li>Explicitly state the Binding Mode – The default binding mode is set by binding target property type, which might not always be what you imagine&#8230; Besides, it contributes to your XAML\code readability. Of course, preferring the OneTime mode (If appropriate to your scenario) is best for performance.</li>
<li>Try using less converters if performance is critical – Instead of using a converter which requires Boxing \ Unboxing, you can create a property in you ViewModel, do the converter in the getter, and bind to it.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.donothing.aspx" target="_blank">Binding.DoNothing</a> – May be useful as return value in a converter when you have a scenario where you don’t want to “interfere” in the binding process (and use the FallbackValue for example).</li>
<li>Binding in a non-visual tree element – Sometimes, a binding is needed in an element which does not inherit a context. most of the times, you will see the following error in this case:</li>
</ul>
<blockquote><p>System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element…</p></blockquote>
<p>There are several “tricks” to overcome this problem:</p>
<ul>
<li>
<ul>
<li><a href="http://www.codeproject.com/KB/WPF/AttachingVirtualBranches.aspx" target="_blank">Virtual Brunch</a></li>
<li><a href="http://www.drwpf.com/Blog/Default.aspx?tabid=36&amp;EntryID=36" target="_blank">Using Freezable</a> \ <a href="http://msdn.microsoft.com/en-us/library/aa346595.aspx" target="_blank">FreezableCollection&lt;T&gt;</a></li>
<li><a href="http://blogs.msdn.com/jaimer/archive/2008/11/22/forwarding-the-datagrid-s-datacontext-to-its-columns.aspx" target="_blank">Forwarding DataContext</a></li>
</ul>
</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/eladm.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/eladm.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/eladm.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/eladm.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/eladm.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/eladm.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/eladm.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/eladm.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/eladm.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/eladm.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/eladm.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/eladm.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/eladm.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/eladm.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=eladm.wordpress.com&amp;blog=6945660&amp;post=65&amp;subd=eladm&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://eladm.wordpress.com/2009/04/08/databinding-tips-tricks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d92e9f493894a5ed5abcf9bdd8740d66?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">emalki</media:title>
		</media:content>
	</item>
		<item>
		<title>Animated GIF Support Behavior</title>
		<link>http://eladm.wordpress.com/2009/04/02/animated-gif-support-behavior/</link>
		<comments>http://eladm.wordpress.com/2009/04/02/animated-gif-support-behavior/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 16:50:23 +0000</pubDate>
		<dc:creator>Elad Malki</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Animated GIF]]></category>
		<category><![CDATA[Attached Behavior]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://eladm.wordpress.com/2009/04/02/animated-gif-support-behavior/</guid>
		<description><![CDATA[After talking about Attached Behavior in the last post, this is an example of a behavior which adds an animated GIF support to regular WPF Image control. WPF does not support naturally displaying an animated GIF. There are couple of ways to overcome this problem, and using this behavior is one of them. Basically, the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=eladm.wordpress.com&amp;blog=6945660&amp;post=61&amp;subd=eladm&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After talking about Attached Behavior in the <a href="http://eladm.wordpress.com/2009/04/02/attached-behavior/" target="_blank">last post</a>, this is an example of a behavior which adds an animated GIF support to regular WPF Image control. </p>
<p>WPF does not support naturally displaying an animated GIF. There are couple of ways to overcome this problem, and using this behavior is one of them. Basically, the behavior creates an animation that loops over the animated gif frames, setting them as a source for the image.</p>
<p>you can download the source and sample <a href="http://www.box.net/shared/idzz2v9oi9" target="_blank">here</a></p>
<p>The usage example is:</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">Window </span><span style="color:red;">x</span><span style="color:blue;">:</span><span style="color:red;">Class</span><span style="color:blue;">=&quot;AnimatedGifBehaviorTest.Window2&quot;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:red;">x</span><span style="color:blue;">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:red;">local</span><span style="color:blue;">=&quot;clr-namespace:AnimatedGifBehaviorTest&quot;

    </span><span style="color:red;">Title</span><span style="color:blue;">=&quot;Window2&quot; </span><span style="color:red;">Height</span><span style="color:blue;">=&quot;300&quot; </span><span style="color:red;">Width</span><span style="color:blue;">=&quot;300&quot;&gt;
    &lt;</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&gt;
            &lt;</span><span style="color:#a31515;">Image </span><span style="color:red;">local</span><span style="color:blue;">:</span><span style="color:red;">SupportAnimatedGIFBehviour.SupportAnimatedGif</span><span style="color:blue;">=&quot;True&quot;
                   </span><span style="color:red;">Source</span><span style="color:blue;">=&quot;MyImage.gif&quot; </span><span style="color:red;">Width</span><span style="color:blue;">=&quot;32&quot; </span><span style="color:red;">Height</span><span style="color:blue;">=&quot;32&quot;/&gt;
    &lt;/</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">Window</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code">And the behavior implementation is:</pre>
<pre class="code"><span style="color:blue;">using </span>System.ComponentModel;
<span style="color:blue;">using </span>System.Windows;
<span style="color:blue;">using </span>System.Windows.Controls;
<span style="color:blue;">using </span>System.Windows.Data;
<span style="color:blue;">using </span>System.Windows.Media;
<span style="color:blue;">using </span>System.Windows.Media.Animation;
<span style="color:blue;">using </span>System.Windows.Media.Imaging;

<span style="color:blue;">namespace </span>AnimatedGifBehaviorTest
{
    <span style="color:blue;">public static class </span><span style="color:#2b91af;">SupportAnimatedGIFBehviour
    </span>{
        <span style="color:blue;">private static readonly int </span>MILLISCONDS_PER_FRAME = 75;

        <span style="color:blue;">#region </span>SupportAnimatedGif Attached Property

        [<span style="color:#2b91af;">AttachedPropertyBrowsableForType</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Image</span>))]
        <span style="color:blue;">public static bool </span>GetSupportAnimatedGif(<span style="color:#2b91af;">Image </span>image)
        {
            <span style="color:blue;">return </span>(<span style="color:blue;">bool</span>)image.GetValue(SupportAnimatedGifProperty);
        }

        <span style="color:blue;">public static void </span>SetSupportAnimatedGif(<span style="color:#2b91af;">Image </span>image, <span style="color:blue;">bool </span>value)
        {
            image.SetValue(SupportAnimatedGifProperty, value);
        }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">An Attached Property for Animated GIF support.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">public static readonly </span><span style="color:#2b91af;">DependencyProperty </span>SupportAnimatedGifProperty =
            <span style="color:#2b91af;">DependencyProperty</span>.RegisterAttached(
            <span style="color:#a31515;">&quot;SupportAnimatedGif&quot;</span>,
            <span style="color:blue;">typeof</span>(<span style="color:blue;">bool</span>),
            <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SupportAnimatedGIFBehviour</span>),
            <span style="color:blue;">new </span><span style="color:#2b91af;">UIPropertyMetadata</span>(<span style="color:blue;">false</span>, OnSupportAnimatedGifChanged));

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Register \ UnRegister to visibility changes and image source changes.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        /// &lt;param name=&quot;depObj&quot;&gt;</span><span style="color:green;">The image object.</span><span style="color:gray;">&lt;/param&gt;
        /// &lt;param name=&quot;e&quot;&gt;</span><span style="color:green;">The SupportAnimatedGif Property values.</span><span style="color:gray;">&lt;/param&gt;
        </span><span style="color:blue;">private static void </span>OnSupportAnimatedGifChanged(<span style="color:#2b91af;">DependencyObject </span>depObj, <span style="color:#2b91af;">DependencyPropertyChangedEventArgs </span>e)
        {
            <span style="color:blue;">bool </span>isSupportingAnimatedGIF = (<span style="color:blue;">bool</span>)e.NewValue;
            <span style="color:#2b91af;">Image </span>image = (<span style="color:#2b91af;">Image</span>)depObj;

            <span style="color:blue;">if </span>(isSupportingAnimatedGIF)
            {
                RegisterForRelevantImagePropertyChanges(image);

                <span style="color:blue;">if </span>(image.Visibility == <span style="color:#2b91af;">Visibility</span>.Visible)
                {
                    image.StartFramesAnimation();
                }
            }
            <span style="color:blue;">else
            </span>{
                UnRegisterForRelevantImagePropertyChanges(image);
                StopFramesAnimation(image);
            }
        }

        <span style="color:blue;">private static </span><span style="color:#2b91af;">DependencyPropertyDescriptor </span>VisibilityDPDescriptor
        {
            <span style="color:blue;">get
            </span>{
                <span style="color:blue;">return </span><span style="color:#2b91af;">DependencyPropertyDescriptor</span>.FromProperty(<span style="color:#2b91af;">UIElement</span>.VisibilityProperty, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">UIElement</span>));
            }
        }

        <span style="color:blue;">private static </span><span style="color:#2b91af;">DependencyPropertyDescriptor </span>ImageSourceDPDescriptor
        {
            <span style="color:blue;">get
            </span>{
                <span style="color:blue;">return </span><span style="color:#2b91af;">DependencyPropertyDescriptor</span>.FromProperty(<span style="color:#2b91af;">Image</span>.SourceProperty, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Image</span>));
            }
        }

        <span style="color:blue;">private static void </span>UnRegisterForRelevantImagePropertyChanges(<span style="color:#2b91af;">DependencyObject </span>depObj)
        {
            VisibilityDPDescriptor.RemoveValueChanged(depObj, OnVisibilityChanged);
            ImageSourceDPDescriptor.RemoveValueChanged(depObj, OnImageSourceChanged);
        }

        <span style="color:blue;">private static void </span>RegisterForRelevantImagePropertyChanges(<span style="color:#2b91af;">DependencyObject </span>depObj)
        {
            VisibilityDPDescriptor.AddValueChanged(depObj, OnVisibilityChanged);
            ImageSourceDPDescriptor.AddValueChanged(depObj, OnImageSourceChanged);
        }

        <span style="color:blue;">#endregion

        #region </span>CurrentFrameIndex Dependency Property

        <span style="color:blue;">private static readonly </span><span style="color:#2b91af;">DependencyProperty </span>CurrentFrameIndexProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(
            <span style="color:#a31515;">&quot;CurrentFrameIndex&quot;</span>,
            <span style="color:blue;">typeof</span>(<span style="color:blue;">int</span>),
            <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Image</span>),
            <span style="color:blue;">new </span><span style="color:#2b91af;">PropertyMetadata</span>(0, OnCurrentFrameIndexChanged));

        <span style="color:blue;">#endregion

        #region </span>IsAnimationChangingFrame Dependency Property

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">IsAnimationChangingFrame Dependency Property
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">private static readonly </span><span style="color:#2b91af;">DependencyProperty </span>IsAnimationChangingFrameProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(
            <span style="color:#a31515;">&quot;IsAnimationChangingFrame&quot;</span>,
            <span style="color:blue;">typeof</span>(<span style="color:blue;">bool</span>),
            <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Image</span>),
            <span style="color:blue;">new </span><span style="color:#2b91af;">PropertyMetadata</span>(<span style="color:blue;">false</span>));

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">DummyImage Dependency Property - for keeping the original source binding when animation is applied
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">private static readonly </span><span style="color:#2b91af;">DependencyProperty </span>DummyImageProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(
            <span style="color:#a31515;">&quot;DummyImage&quot;</span>,
            <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">ImageSource</span>),
            <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Image</span>),
            <span style="color:blue;">new </span><span style="color:#2b91af;">PropertyMetadata</span>(<span style="color:blue;">null</span>, OnDummyImagePropertyChanged));

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Gets or sets the IsAnimationChangingFrame property. This dependency property
        </span><span style="color:gray;">/// </span><span style="color:green;">indicates that the animation is currently changing the image source.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">private static bool </span>GetIsAnimationChangingFrame(<span style="color:blue;">this </span><span style="color:#2b91af;">Image </span>image)
        {
            <span style="color:blue;">return </span>(<span style="color:blue;">bool</span>)image.GetValue(IsAnimationChangingFrameProperty);
        }
        <span style="color:blue;">private static void </span>SetIsAnimationChangingFrame(<span style="color:blue;">this </span><span style="color:#2b91af;">Image </span>image, <span style="color:blue;">bool </span>isAnimationChangingFrame)
        {
            image.SetValue(IsAnimationChangingFrameProperty, isAnimationChangingFrame);
        }

        <span style="color:blue;">#endregion

        private static void </span>OnImageSourceChanged(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">EventArgs </span>e)
        {
            <span style="color:#2b91af;">Image </span>image = (<span style="color:#2b91af;">Image</span>)sender;

            <span style="color:blue;">if </span>(!image.GetIsAnimationChangingFrame())<span style="color:green;">//If the image source is changing by an outer source(not the animation).
            </span>{
                <span style="color:green;">//stop old animation
                </span>image.SetIsAnimationChangingFrame(<span style="color:blue;">true</span>);
                image.StopFramesAnimation();
                image.SetIsAnimationChangingFrame(<span style="color:blue;">false</span>);

                <span style="color:green;">//start new animation - only if frames count is bigger than one.
                </span>image.StartFramesAnimation();
            }
        }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Starts frame animation only if frames count is bigger than 1.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        /// &lt;param name=&quot;image&quot;&gt;&lt;/param&gt;
        </span><span style="color:blue;">private static void </span>StartFramesAnimation(<span style="color:blue;">this </span><span style="color:#2b91af;">Image </span>image)
        {
            <span style="color:#2b91af;">BitmapFrame </span>bitmapFrame = image.Source <span style="color:blue;">as </span><span style="color:#2b91af;">BitmapFrame</span>;
            <span style="color:blue;">if </span>(bitmapFrame != <span style="color:blue;">null</span>)
            {
                <span style="color:blue;">int </span>framesCount = bitmapFrame.Decoder.Frames.Count;

                <span style="color:blue;">if </span>(framesCount &gt; 1)
                {
                    <span style="color:#2b91af;">Int32Animation </span>gifAnimation =
                        <span style="color:blue;">new </span><span style="color:#2b91af;">Int32Animation</span>(
                            0, <span style="color:green;">// &quot;From&quot; value
                            </span>framesCount - 1, <span style="color:green;">// &quot;To&quot; value
                            </span><span style="color:blue;">new </span><span style="color:#2b91af;">Duration</span>(<span style="color:#2b91af;">TimeSpan</span>.FromMilliseconds(MILLISCONDS_PER_FRAME * framesCount))
                        );

                    gifAnimation.RepeatBehavior = <span style="color:#2b91af;">RepeatBehavior</span>.Forever;

                    image.BeginAnimation(CurrentFrameIndexProperty, gifAnimation, <span style="color:#2b91af;">HandoffBehavior</span>.SnapshotAndReplace);
                }
            }
        }

        <span style="color:blue;">private static void </span>StopFramesAnimation(<span style="color:blue;">this </span><span style="color:#2b91af;">Image </span>image)
        {
            image.BeginAnimation(CurrentFrameIndexProperty, <span style="color:blue;">null</span>);
        }

        <span style="color:blue;">private static void </span>OnVisibilityChanged(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">EventArgs </span>e)
        {
            <span style="color:#2b91af;">Image </span>image = (<span style="color:#2b91af;">Image</span>)sender;

            <span style="color:blue;">if </span>(image.Visibility != <span style="color:#2b91af;">Visibility</span>.Visible)
            {
                image.StopFramesAnimation();
            }
            <span style="color:blue;">else
            </span>{
                image.StartFramesAnimation();
            }
        }

        <span style="color:blue;">private static void </span>OnDummyImagePropertyChanged(<span style="color:#2b91af;">DependencyObject </span>dpo, <span style="color:#2b91af;">DependencyPropertyChangedEventArgs </span>e)
        {
            <span style="color:#2b91af;">Image </span>animatedImage = (<span style="color:#2b91af;">Image</span>)dpo;

            <span style="color:blue;">if </span>(!animatedImage.GetIsAnimationChangingFrame())
            {
                <span style="color:#2b91af;">BindingBase </span>originalBinding = <span style="color:#2b91af;">BindingOperations</span>.GetBindingBase(dpo, DummyImageProperty);
                <span style="color:blue;">if </span>(originalBinding != <span style="color:blue;">null</span>)
                {
                    <span style="color:#2b91af;">BindingOperations</span>.SetBinding(dpo, <span style="color:#2b91af;">Image</span>.SourceProperty, originalBinding);
                    <span style="color:#2b91af;">BindingOperations</span>.ClearBinding(animatedImage, DummyImageProperty);
                }
                animatedImage.SetIsAnimationChangingFrame(<span style="color:blue;">false</span>);
            }
            <span style="color:blue;">else
            </span>{
                animatedImage.SetIsAnimationChangingFrame(<span style="color:blue;">false</span>);
            }

            animatedImage.SetIsAnimationChangingFrame(<span style="color:blue;">false</span>);
        }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Update the current image source to the relevenat frame.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        /// &lt;param name=&quot;dpo&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;e&quot;&gt;&lt;/param&gt;
        </span><span style="color:blue;">private static void </span>OnCurrentFrameIndexChanged(<span style="color:#2b91af;">DependencyObject </span>dpo, <span style="color:#2b91af;">DependencyPropertyChangedEventArgs </span>e)
        {
            <span style="color:#2b91af;">Image </span>animatedImage = (<span style="color:#2b91af;">Image</span>)dpo;

            <span style="color:blue;">if </span>(!animatedImage.GetIsAnimationChangingFrame())
            {
                animatedImage.SetIsAnimationChangingFrame(<span style="color:blue;">true</span>);

                <span style="color:blue;">bool </span>hasBinding = <span style="color:#2b91af;">BindingOperations</span>.IsDataBound(animatedImage, <span style="color:#2b91af;">Image</span>.SourceProperty);
                <span style="color:blue;">if </span>(hasBinding)
                {
                    <span style="color:#2b91af;">BindingBase </span>originalBinding = <span style="color:#2b91af;">BindingOperations</span>.GetBindingBase(animatedImage, <span style="color:#2b91af;">Image</span>.SourceProperty);
                    <span style="color:#2b91af;">BindingOperations</span>.SetBinding(animatedImage, DummyImageProperty, originalBinding);
                }
                animatedImage.Source = ((<span style="color:#2b91af;">BitmapFrame</span>)animatedImage.Source).Decoder.Frames[(<span style="color:blue;">int</span>)e.NewValue];

                <span style="color:blue;">if </span>(!hasBinding)
                {
                    animatedImage.SetIsAnimationChangingFrame(<span style="color:blue;">false</span>);
                }
            }
        }
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/eladm.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/eladm.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/eladm.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/eladm.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/eladm.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/eladm.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/eladm.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/eladm.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/eladm.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/eladm.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/eladm.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/eladm.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/eladm.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/eladm.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=eladm.wordpress.com&amp;blog=6945660&amp;post=61&amp;subd=eladm&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://eladm.wordpress.com/2009/04/02/animated-gif-support-behavior/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d92e9f493894a5ed5abcf9bdd8740d66?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">emalki</media:title>
		</media:content>
	</item>
		<item>
		<title>Attached Behavior</title>
		<link>http://eladm.wordpress.com/2009/04/02/attached-behavior/</link>
		<comments>http://eladm.wordpress.com/2009/04/02/attached-behavior/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 08:04:33 +0000</pubDate>
		<dc:creator>Elad Malki</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Attached Behavior]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://eladm.wordpress.com/2009/04/02/attached-behavior/</guid>
		<description><![CDATA[WPF has a powerful concept of Attached Properties. Since a Dependency Object is a kind of a sophisticated property bag, it can contain its own properties and other properties. The traditional use of attached properties is by the object that declare it, for example, A grid has a Row and a Column attached properties. It [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=eladm.wordpress.com&amp;blog=6945660&amp;post=52&amp;subd=eladm&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">WPF has a powerful concept of <a href="http://msdn.microsoft.com/en-us/library/ms749011.aspx" target="_blank">Attached Properties</a>. Since a Dependency Object is a kind of a sophisticated property bag, it can contain its own properties and other properties. The traditional use of attached properties is by the object that declare it, for example, A grid has a Row and a Column attached properties. It looks up these properties on every child of his, and use their values to arrange the children:</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Grid.RowDefinitions</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">RowDefinition</span><span style="color:blue;">/&gt;
    &lt;</span><span style="color:#a31515;">RowDefinition</span><span style="color:blue;">/&gt;
  &lt;/</span><span style="color:#a31515;">Grid.RowDefinitions</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Button </span><span style="color:red;">Grid.Row</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">0</span>&quot;<span style="color:blue;">&gt;</span>Button 1<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Button</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Button </span><span style="color:red;">Grid.Row</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">1</span>&quot;<span style="color:blue;">&gt;</span>Button 2<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Button</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a><span style="background:yellow;color:#8b008b;"><a href="http://11011.net/software/vspaste"></a></span></p>
<p align="justify">A more advanced way of using attached properties is Attached Behaviors. An attached behavior is a way of extending or adding functionality of a dependency object (you can find more about it in <a href="http://www.codeproject.com/KB/WPF/AttachedBehaviors.aspx" target="_blank">Josh Smith&#8217;s article</a>). For example, we might have a scenario in which we want to select the text of a TextBox when it gets the focus. A solution for this scenario could be hooking to the appropriate events in the code behind \ ViewModel of the TextBox and selecting the text when needed. There are two problems with this solution:</p>
<p align="justify">1. It requires writing code in an &quot;inappropriate&quot; WPF places such as code behind (which is always better to leave empty) or a ViewModel (which should contain info and logic of the view rather than technical stuff).</p>
<p align="justify">2. It requires writing a lot of code many times if we have more than one textbox, or several textboxes in different windows that needs this behavior.</p>
<p align="justify">A better solution would be writing an attached behavior. An attached behavior in WPF is normally a static class with one or more attached properties. The trick in this class is to listen to the change event of one of the properties, and to act upon it. This is an example of the Textbox &quot;text selection on focus&quot; behavior (Based on <a href="http://eric.burke.name/dotnetmania/2009/03/17/19.30.27" target="_blank">Eric Burke&#8217;s Post</a>):</p>
<pre class="code"><span style="color:blue;">public static class </span><span style="color:#2b91af;">SelectAllOnFocusBehaviour
</span>{
        <span style="color:gray;">/// </span><span style="color:green;">1. This is the boolean attached property with its getter and setter:
        </span><span style="color:blue;">public static readonly </span><span style="color:#2b91af;">DependencyProperty </span>SelectAllOnFocusProperty =
            <span style="color:#2b91af;">DependencyProperty</span>.RegisterAttached
            (
                <span style="color:#a31515;">&quot;SelectAllOnFocus&quot;</span>,
                <span style="color:blue;">typeof</span>(<span style="color:blue;">bool</span>),
                <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SelectAllOnFocusBehaviour</span>),
                <span style="color:blue;">new </span><span style="color:#2b91af;">UIPropertyMetadata</span>(<span style="color:blue;">false</span>, OnSelectAllOnFocusPropertyChanged)
            );
        <span style="color:blue;">public static bool </span>GetSelectAllOnFocus(<span style="color:#2b91af;">DependencyObject </span>obj)
        {
            <span style="color:blue;">return </span>(<span style="color:blue;">bool</span>)obj.GetValue(SelectAllOnFocusProperty);
        }
        <span style="color:blue;">public static void </span>SetSelectAllOnFocus(<span style="color:#2b91af;">DependencyObject </span>obj, <span style="color:blue;">bool </span>value)
        {
            obj.SetValue(SelectAllOnFocusProperty, value);
        }

        <span style="color:gray;">/// </span><span style="color:green;">2. This is the change event of our attached property value:
        </span><span style="color:gray;">///     </span><span style="color:green;">* We get in the first parameter the dependency object to which the attached behavior was attached
        </span><span style="color:gray;">///     </span><span style="color:green;">* We get in the second parameter the value of the attached behavior.
        </span><span style="color:gray;">///     </span><span style="color:green;">* The implementation of the behavior is to check if we are attached to a textBox, and if so and the value of the behavior
        </span><span style="color:gray;">///       </span><span style="color:green;">is true, hook to the PreviewGotKeyboardFocus of the textbox.
        </span><span style="color:blue;">private static void </span>OnSelectAllOnFocusPropertyChanged(<span style="color:#2b91af;">DependencyObject </span>dpo, <span style="color:#2b91af;">DependencyPropertyChangedEventArgs </span>args)
        {
            <span style="color:#2b91af;">TextBoxBase </span>textBox = dpo <span style="color:blue;">as </span><span style="color:#2b91af;">TextBoxBase</span>;
            <span style="color:blue;">if </span>(textBox != <span style="color:blue;">null</span>)
            {
                <span style="color:#2b91af;">TextBoxBase </span>tbb = dpo <span style="color:blue;">as </span><span style="color:#2b91af;">TextBoxBase</span>;
                <span style="color:blue;">if </span>((<span style="color:blue;">bool</span>)args.NewValue)
                {
                    textBox.PreviewGotKeyboardFocus += OnTextBoxPreviewGotKeyboardFocus;
                }
                <span style="color:blue;">else
                </span>{
                    textBox.PreviewGotKeyboardFocus -= OnTextBoxPreviewGotKeyboardFocus;
                }
            }
        }

        <span style="color:gray;">/// </span><span style="color:green;">3. The actual implementation: Whenever the textbox gets the keyboard focus, we select its text
        </span><span style="color:blue;">private static void </span>OnTextBoxPreviewGotKeyboardFocus(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">KeyboardFocusChangedEventArgs </span>e)
        {
            <span style="color:#2b91af;">TextBoxBase </span>txtBox = (<span style="color:#2b91af;">TextBoxBase</span>)sender;
            <span style="color:#2b91af;">Action </span>action = () =&gt; { txtBox.SelectAll(); };
            txtBox.Dispatcher.BeginInvoke(action, <span style="color:#2b91af;">DispatcherPriority</span>.ContextIdle);
        }
    }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>And this is an example of the behavior usage:</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">Page
  </span><span style="color:red;">xmlns</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">http://schemas.microsoft.com/winfx/2006/xaml/presentation</span>&quot;
  <span style="color:red;">xmlns:x</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">http://schemas.microsoft.com/winfx/2006/xaml</span>&quot;
  <span style="color:red;">xmlns:behaviors</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">your behavior xmlns path</span>&quot;<span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">TextBox </span><span style="color:red;">Text</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Some Text</span>&quot; <span style="color:red;">behaviors:SelectAllOnFocusBehaviour.SelectAllOnFocus</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">True</span>&quot;<span style="color:blue;">/&gt;
  &lt;/</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">Page</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The result is a much declarative, maintainable and shorter code. You can find many useful behaviors on the web.</p>
<p>In Silverlight 3.0 there is a built in <a href="http://blog.kirupa.com/?p=351" target="_blank">behaviors infrastructure</a>, by using the Behaviors (and\or Triggers) attached property which contains a collection of behaviors (or Triggers). </p>
<p>Elad.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/eladm.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/eladm.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/eladm.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/eladm.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/eladm.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/eladm.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/eladm.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/eladm.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/eladm.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/eladm.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/eladm.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/eladm.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/eladm.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/eladm.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=eladm.wordpress.com&amp;blog=6945660&amp;post=52&amp;subd=eladm&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://eladm.wordpress.com/2009/04/02/attached-behavior/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d92e9f493894a5ed5abcf9bdd8740d66?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">emalki</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF Tools</title>
		<link>http://eladm.wordpress.com/2009/03/30/wpf-tools/</link>
		<comments>http://eladm.wordpress.com/2009/03/30/wpf-tools/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 13:31:10 +0000</pubDate>
		<dc:creator>Elad Malki</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://eladm.wordpress.com/?p=5</guid>
		<description><![CDATA[This is the first post of my new WPF Blog !! It describes the list of WPF tools I normally use.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=eladm.wordpress.com&amp;blog=6945660&amp;post=5&amp;subd=eladm&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>My name is Elad Malki and I&#8217;m a software developer at HP Software IL. This is the first post of my first blog, which will be mostly dealing with WPF.</p>
<p>Now that <a title="Expression Blend 3.0 Preview" href="http://www.microsoft.com/expression/try-it/blendpreview.aspx" target="_blank">Expression Blend 3.0 Preview</a> is out, it is time to update my list of <strong>WPF dev tools</strong>:</p>
<ul class="unIndentedList">
<li> <a title="KAXAML" href="http://www.kaxaml.com/" target="_blank"><strong><span style="text-decoration:underline;">KAXAML</span></strong></a> &#8211; A XAML Parser for quick visualization of the basic built-in WPF UI elements</li>
</ul>
<ul class="unIndentedList">
<li> <strong><span style="text-decoration:underline;"><a title="Reflector" href="http://www.red-gate.com/products/reflector/" target="_blank">Reflector</a></span>+<a title="BAML Viewer add-in" href="http://reflectoraddins.codeplex.com/Wiki/View.aspx?title=BamlViewer&amp;referringTitle=Home" target="_blank">BAML</a></strong><a title="BAML Viewer add-in" href="http://reflectoraddins.codeplex.com/Wiki/View.aspx?title=BamlViewer&amp;referringTitle=Home" target="_blank"> </a>Viewer add-in &#8211; An Add-in for the reflector that loads BAML from an assembly and display it XAML Syntax</li>
</ul>
<ul class="unIndentedList">
<li> <a title="Pistachio" href="http://www.granthinkson.com/2007/11/08/announcing-pistachio-wpf-resource-visualizer/" target="_blank"><strong><span style="text-decoration:underline;">Pistachio</span></strong></a> &#8211; A WPF Resource Visualizer for identifying non-usable resources</li>
</ul>
<ul class="unIndentedList">
<li> <a title="Expression Blend 3.0 Preview" href="http://expression.microsoft.com/en-us/dd565875.aspx" target="_blank"><strong><span style="text-decoration:underline;">Expression Blend 3.0 Preview </span></strong></a>- The WPF &amp; Silverlight(3.0 !) Graphical Design tool</li>
</ul>
<ul class="unIndentedList">
<li> <strong><span style="text-decoration:underline;"><a title="Snoop" href="http://blois.us/Snoop/" target="_blank">Snoop</a></span> &amp; <a title="Mole" href="http://www.codeproject.com/KB/macros/MoleForVisualStudioEdit.aspx" target="_blank"><span style="text-decoration:underline;">Mole</span></a></strong> &#8211; Visual Tree Explorer &#8211; Snoop is a standalone app, while mole is a VS debugger visualizer (I just use snoop actually&#8230;)</li>
</ul>
<ul class="unIndentedList">
<li><a title="WPF Perf Tools" href="http://windowsclient.net/wpf/perf/wpf-perf-tool.aspx" target="_blank"><strong><span style="text-decoration:underline;">WPF Perf tools</span></strong></a> &#8211; A Performance Profiling tool suite for WPF</li>
</ul>
<ul class="unIndentedList">
<li> <strong><span style="text-decoration:underline;"><a title="MO" href="http://peteohanlon.wordpress.com/2008/10/07/moxaml-20-released/" target="_blank">MO</a></span>\<a title="XAML Power Toys" href="http://karlshifflett.wordpress.com/xaml-power-toys/" target="_blank"><span style="text-decoration:underline;">XAML PowerTyos</span></a></strong> &#8211; Two visual studio add-ins that helps handling XAML</li>
</ul>
<p>You can find some additional tools here: <a href="http://wpf-resources.com/wpftools.aspx">http://wpf-resources.com/wpftools.aspx</a> If you know about other useful tools, please share !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/eladm.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/eladm.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/eladm.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/eladm.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/eladm.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/eladm.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/eladm.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/eladm.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/eladm.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/eladm.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/eladm.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/eladm.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/eladm.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/eladm.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=eladm.wordpress.com&amp;blog=6945660&amp;post=5&amp;subd=eladm&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://eladm.wordpress.com/2009/03/30/wpf-tools/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d92e9f493894a5ed5abcf9bdd8740d66?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">emalki</media:title>
		</media:content>
	</item>
	</channel>
</rss>
