<?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>Notes on Software</title>
	<atom:link href="http://softnotes.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://softnotes.wordpress.com</link>
	<description></description>
	<lastBuildDate>Tue, 06 Dec 2011 20:24:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='softnotes.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Notes on Software</title>
		<link>http://softnotes.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://softnotes.wordpress.com/osd.xml" title="Notes on Software" />
	<atom:link rel='hub' href='http://softnotes.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Shared ResourceDictionary for Silverlight</title>
		<link>http://softnotes.wordpress.com/2011/04/05/shared-resourcedictionary-for-silverlight/</link>
		<comments>http://softnotes.wordpress.com/2011/04/05/shared-resourcedictionary-for-silverlight/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 18:51:34 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[ResourceDictionary]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=43</guid>
		<description><![CDATA[The problem: Both WPF and Silverlight support merged ResourceDictionary usage via the MergedDictionaries property.  Typically this is done with markup similar to the following in App.xaml     &#60;Application.Resources&#62;         &#60;ResourceDictionary&#62;             &#60;ResourceDictionary.MergedDictionaries&#62;                 &#60;ResourceDictionary Source="Resources/Shared.xaml"/&#62;                 &#60;ResourceDictionary Source="Resources/Views1.xaml"/&#62;                 &#60;ResourceDictionary Source="Resources/Views2.xaml"/&#62;                 &#60;ResourceDictionary Source="Resources/Views3.xaml"/&#62;             &#60;/ResourceDictionary.MergedDictionaries&#62;         &#60;/ResourceDictionary&#62;     &#60;/Application.Resources&#62; In WPF any resources defined within Shared.xaml are accessible by a StaticResource reference from any of the other dictionaries because of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=43&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>The problem:</h3>
<p>Both WPF and Silverlight support merged ResourceDictionary usage via the MergedDictionaries property.  Typically this is done with markup similar to the following in App.xaml</p>
<pre style="font-family:Consolas;font-size:11px;color:black;background:white;"><span style="color:#a31515;">    </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">Application.Resources</span><span style="color:blue;">&gt;</span>
<span style="color:#a31515;">        </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">ResourceDictionary</span><span style="color:blue;">&gt;</span>
<span style="color:#a31515;">            </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">ResourceDictionary.MergedDictionaries</span><span style="color:blue;">&gt;</span>
<span style="color:#a31515;">                </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">ResourceDictionary</span><span style="color:red;"> Source</span><span style="color:blue;">="Resources/Shared.xaml"/&gt;</span>
<span style="color:#a31515;">                </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">ResourceDictionary</span><span style="color:red;"> Source</span><span style="color:blue;">="Resources/Views1.xaml"/&gt;</span>
<span style="color:#a31515;">                </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">ResourceDictionary</span><span style="color:red;"> Source</span><span style="color:blue;">="Resources/Views2.xaml"/&gt;</span>
<span style="color:#a31515;">                </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">ResourceDictionary</span><span style="color:red;"> Source</span><span style="color:blue;">="Resources/Views3.xaml"/&gt;</span>
<span style="color:#a31515;">            </span><span style="color:blue;">&lt;/</span><span style="color:#a31515;">ResourceDictionary.MergedDictionaries</span><span style="color:blue;">&gt;</span>
<span style="color:#a31515;">        </span><span style="color:blue;">&lt;/</span><span style="color:#a31515;">ResourceDictionary</span><span style="color:blue;">&gt;</span>
<span style="color:#a31515;">    </span><span style="color:blue;">&lt;/</span><span style="color:#a31515;">Application.Resources</span><span style="color:blue;">&gt;</span></pre>
<p>In WPF any resources defined within Shared.xaml are accessible by a StaticResource reference from any of the other dictionaries because of the order in which they are merged into App.xaml. In Silverlight, all the dictionaries are loaded independently and StaticResource references across dictionaries do not work. To get the references to work, Shared.xaml has to be merged into each of the other dictionaries. However, this means that the contents of Shared.xaml will be loaded and duplicated at each place where it is merged in. This is clearly bad. While searching for a solution I came across <a href="http://www.wpftutorial.net/MergedDictionaryPerformance.html">this post</a> by Christian Mosers. Mosers defines a SharedResourceDictionary class deriving from ResourceDictionary and redefines the Source property where he uses some caching logic to avoid reloading the dictionary. Unfortunately this solution does not work in Silverlight. For some reason, Silverlight does not allow the same dictionary instance to be merged into multiple dictionaries. Additionally, the Visual Studio designer throws an exception in the setter of the Source property. Apparantly Visual Studio does not like derived classes.</p>
<h3>The solution:</h3>
<p>The following class solves both the problems detailed above</p>
<p><pre class="brush: csharp;">
public class SharedResourceDictionary : ResourceDictionary
{
    public static Dictionary&lt;Uri, ResourceDictionary&gt; _sharedDictionaries =
       new Dictionary&lt;Uri, ResourceDictionary&gt;();

    private Uri _sourceUri;
    public new Uri Source
    {
        get { return _sourceUri; }
        set
        {
            _sourceUri = value;
            if (!_sharedDictionaries.ContainsKey(value))
            {
#if SILVERLIGHT
                var dict = new ResourceDictionary();
                Application.LoadComponent(dict, value);
#else
                var dict = (ResourceDictionary)Application.LoadComponent(value);
#endif
                _sharedDictionaries.Add(value, dict);
            }
            CopyInto(this, _sharedDictionaries[value]);
        }
    }

    private static void CopyInto(ResourceDictionary copy, ResourceDictionary original)
    {
        foreach (var dictionary in original.MergedDictionaries)
        {
            var mergedCopy = new ResourceDictionary();
            CopyInto(mergedCopy, dictionary);
            copy.MergedDictionaries.Add(mergedCopy);
        }
        foreach (DictionaryEntry pair in original)
        {
            copy.Add(pair.Key, pair.Value);
        }
    }
}
</pre></p>
<p>    This bypasses the ResourceDictionary.Source property entirely by using Application.LoadComponent directly, thus keeping the Visual Studio designer happy. It copies the cached ResourceDictionary to keep Silverlight happy. This is slightly less efficient than merging in the same cached instance everywhere but it is certainly much better than reloading every resource multiple times. The only catch is that the Source property must be set in a way that Application.LoadComponent can resolve it correctly. I use this with absolute URIs.</p>
<h3>Sample usage:</h3>
<p>Markup similar to the following can be used at the beginning of each resource dictionary that needs to reference resources in Shared.xaml</p>
<pre style="font-family:Consolas;font-size:11px;color:black;background:white;"><span style="color:#a31515;">    </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">ResourceDictionary.MergedDictionaries</span><span style="color:blue;">&gt;</span>
<span style="color:#a31515;">        </span><span style="color:blue;">&lt;</span><span style="color:#a31515;">ui</span><span style="color:blue;">:</span><span style="color:#a31515;">SharedResourceDictionary</span><span style="color:red;"> Source</span><span style="color:blue;">="/my_assembly_name;component/Resources/Shared.xaml"/&gt;</span>
<span style="color:#a31515;">    </span><span style="color:blue;">&lt;/</span><span style="color:#a31515;">ResourceDictionary.MergedDictionaries</span><span style="color:blue;">&gt;</span></pre>
<br />Filed under: <a href='http://softnotes.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://softnotes.wordpress.com/category/wpf/'>WPF</a> Tagged: <a href='http://softnotes.wordpress.com/tag/resourcedictionary/'>ResourceDictionary</a>, <a href='http://softnotes.wordpress.com/tag/silverlight/'>Silverlight</a>, <a href='http://softnotes.wordpress.com/tag/wpf/'>WPF</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=43&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2011/04/05/shared-resourcedictionary-for-silverlight/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>Differences between WPF and Silverlight &#8211; 1</title>
		<link>http://softnotes.wordpress.com/2011/02/25/wpf-silverlight-1/</link>
		<comments>http://softnotes.wordpress.com/2011/02/25/wpf-silverlight-1/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 19:43:34 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[DataTemplate]]></category>
		<category><![CDATA[ItemsControl]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=39</guid>
		<description><![CDATA[This is the first post in a series documenting the differences between WPF (v3.5+) and Silverlight (v4). DataTemplates in an ItemsControl in bound mode (when ItemsSource is set): An ItemsControl generates a container for each item in the ItemsSource. The container typically displays the item via a ContentPresenter (either directly or through a ControlTemplate for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=39&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the first post in a series documenting the differences between WPF (v3.5+) and Silverlight (v4).</p>
<h2>DataTemplates in an ItemsControl in bound mode (when ItemsSource is set):</h2>
<p>An ItemsControl generates a container for each item in the ItemsSource. The container typically displays the item via a ContentPresenter (either directly or through a ControlTemplate for the container).</p>
<h3>WPF:</h3>
<p>The logic in the PrepareContainerForItemOverride method sets the ContentTemplate of the container to the ItemTemplate property <strong>if it is not null</strong> and the ContentTemplateSelector to the ItemTemplateSelector if it is not null. Additionally, the ItemContainerStyle gets applied to the container. This results in the following order of precedence for the data template</p>
<ol>
<li>ItemsControl.ItemTemplate</li>
<li>ContentTemplate from ItemsControl.ItemContainerStyle</li>
<li>ItemsControl.ItemTemplateSelector</li>
<li>ContentTemplateSelector from ItemsControl.ItemContainerStyle</li>
</ol>
<h3>Silverlight:</h3>
<p>There is no DataTemplateSelector. Also the logic in the PrepareContainerForItemOverride method sets the ContentTemplate of the container to the ItemTemplate property <strong>even if it is null</strong>. This results in the ItemsControl always using the ItemTemplate property for the data template. <strong>The ContentTemplate from ItemsControl.ItemContainerStyle is always ignored</strong>.</p>
<h4>My comments:</h4>
<p>The silverlight implementation is broken and fixing it will mean a breaking change. So I doubt if it will ever be fixed. It seems that the developers who implemented this either did not understand the concept of dependency property precedence or did not care to compare the implementation with the WPF one. Bad.</p>
<br />Filed under: <a href='http://softnotes.wordpress.com/category/net/'>.NET</a>, <a href='http://softnotes.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://softnotes.wordpress.com/category/wpf/'>WPF</a> Tagged: <a href='http://softnotes.wordpress.com/tag/datatemplate/'>DataTemplate</a>, <a href='http://softnotes.wordpress.com/tag/itemscontrol/'>ItemsControl</a>, <a href='http://softnotes.wordpress.com/tag/silverlight/'>Silverlight</a>, <a href='http://softnotes.wordpress.com/tag/wpf/'>WPF</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=39&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2011/02/25/wpf-silverlight-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>Productivity tip for Windows Explorer</title>
		<link>http://softnotes.wordpress.com/2011/01/02/productivity-tip-for-windows-explorer/</link>
		<comments>http://softnotes.wordpress.com/2011/01/02/productivity-tip-for-windows-explorer/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 15:28:14 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=36</guid>
		<description><![CDATA[To set the focus on the list view in the windows explorer, press Ctrl+E (takes you to the search box) and then the down key (takes you down to the list view). No more pressing tab until the focus is at the desired place. Note: This will not work on XP since there is no [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=36&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To set the focus on the list view in the windows explorer, press Ctrl+E (takes you to the search box) and then the down key (takes you down to the list view). No more pressing tab until the focus is at the desired place.</p>
<p>Note: This will not work on XP since there is no search box on XP.</p>
<br />Filed under: <a href='http://softnotes.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=36&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2011/01/02/productivity-tip-for-windows-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>HeaderedScrollViewer in WPF</title>
		<link>http://softnotes.wordpress.com/2009/11/07/headeredscrollviewer-in-wpf/</link>
		<comments>http://softnotes.wordpress.com/2009/11/07/headeredscrollviewer-in-wpf/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 08:34:14 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[ScrollChanged]]></category>
		<category><![CDATA[ScrollViewer]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=32</guid>
		<description><![CDATA[I needed a scrollviewer with a header area on the top that does not scroll vertically but does scroll horizontally. It was pretty simple to derive from ScrollViewer, define a TopHeader property (and a LeftHeader property for good measure), modify the control template to contain ScrollViewers for the headers with hidden scrollbars and synchronize the horizontal and vertical [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=32&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I needed a scrollviewer with a header area on the top that does not scroll vertically but does scroll horizontally. It was pretty simple to derive from ScrollViewer, define a TopHeader property (and a LeftHeader property for good measure), modify the control template to contain ScrollViewers for the headers with hidden scrollbars and synchronize the horizontal and vertical offsets in code. This worked well until I put a ComboBox in the header. Suddenly the scroll position started getting reset to zero when the ComboBox was opened. I looked on the internet for a solution but didn&#8217;t find one. A little debugging revealed that when the ComboBox is opened, the ScrollViewer in the popup raises a ScrollChanged event which routes up to the ScrollViewer containing the header. To fix this problem all I needed to do was to ignore events not originating directly from the header ScrollViewers.</p>
<p>Here is the code</p>
<p><code></p>
<div style='font-family:Monospace;font-size:10pt;background-color:white;'>
&nbsp;&nbsp;&nbsp;&nbsp;[<span style='color:#2b91af;'>TemplatePart</span><span style='color:Black;'>(Name = </span><span style='color:#a31515;'>&quot;PART_TopHeaderScrollViewer&quot;</span><span style='color:Black;'>, Type = </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>ScrollViewer</span><span style='color:Black;'>))]<br />
&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style='color:#2b91af;'>TemplatePart</span><span style='color:Black;'>(Name = </span><span style='color:#a31515;'>&quot;PART_LeftHeaderScrollViewer&quot;</span><span style='color:Black;'>, Type = </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>ScrollViewer</span><span style='color:Black;'>))]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:Blue;'>class</span><span style='color:Black;'> </span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'> : </span><span style='color:#2b91af;'>ScrollViewer<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>static</span><span style='color:Black;'> HeaderedScrollViewer()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DefaultStyleKeyProperty.OverrideMetadata(</span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'>), </span><span style='color:Blue;'>new</span><span style='color:Black;'> </span><span style='color:#2b91af;'>FrameworkPropertyMetadata</span><span style='color:Black;'>(</span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'>)));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:Blue;'>object</span><span style='color:Black;'> TopHeader<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>get</span><span style='color:Black;'> { </span><span style='color:Blue;'>return</span><span style='color:Black;'> (</span><span style='color:Blue;'>object</span><span style='color:Black;'>)GetValue(TopHeaderProperty); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>set</span><span style='color:Black;'> { SetValue(TopHeaderProperty, </span><span style='color:Blue;'>value</span><span style='color:Black;'>); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:Blue;'>static</span><span style='color:Black;'> </span><span style='color:Blue;'>readonly</span><span style='color:Black;'> </span><span style='color:#2b91af;'>DependencyProperty</span><span style='color:Black;'> TopHeaderProperty =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:#2b91af;'>DependencyProperty</span><span style='color:Black;'>.Register(</span><span style='color:#a31515;'>&quot;TopHeader&quot;</span><span style='color:Black;'>, </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:Blue;'>object</span><span style='color:Black;'>), </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'>), </span><span style='color:Blue;'>new</span><span style='color:Black;'> </span><span style='color:#2b91af;'>UIPropertyMetadata</span><span style='color:Black;'>(TopHeader_PropertyChanged));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>private</span><span style='color:Black;'> </span><span style='color:Blue;'>static</span><span style='color:Black;'> </span><span style='color:Blue;'>void</span><span style='color:Black;'> TopHeader_PropertyChanged(</span><span style='color:#2b91af;'>DependencyObject</span><span style='color:Black;'> d, </span><span style='color:#2b91af;'>DependencyPropertyChangedEventArgs</span><span style='color:Black;'> e)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'> instance = (</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'>)d;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (e.OldValue != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance.RemoveLogicalChild(e.OldValue);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (e.NewValue != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance.AddLogicalChild(e.NewValue);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:#2b91af;'>DataTemplate</span><span style='color:Black;'> TopHeaderTemplate<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>get</span><span style='color:Black;'> { </span><span style='color:Blue;'>return</span><span style='color:Black;'> (</span><span style='color:#2b91af;'>DataTemplate</span><span style='color:Black;'>)GetValue(TopHeaderTemplateProperty); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>set</span><span style='color:Black;'> { SetValue(TopHeaderTemplateProperty, </span><span style='color:Blue;'>value</span><span style='color:Black;'>); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:Blue;'>static</span><span style='color:Black;'> </span><span style='color:Blue;'>readonly</span><span style='color:Black;'> </span><span style='color:#2b91af;'>DependencyProperty</span><span style='color:Black;'> TopHeaderTemplateProperty =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:#2b91af;'>DependencyProperty</span><span style='color:Black;'>.Register(</span><span style='color:#a31515;'>&quot;TopHeaderTemplate&quot;</span><span style='color:Black;'>, </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>DataTemplate</span><span style='color:Black;'>), </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'>), </span><span style='color:Blue;'>new</span><span style='color:Black;'> </span><span style='color:#2b91af;'>UIPropertyMetadata</span><span style='color:Black;'>());</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:Blue;'>object</span><span style='color:Black;'> LeftHeader<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>get</span><span style='color:Black;'> { </span><span style='color:Blue;'>return</span><span style='color:Black;'> (</span><span style='color:Blue;'>object</span><span style='color:Black;'>)GetValue(LeftHeaderProperty); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>set</span><span style='color:Black;'> { SetValue(LeftHeaderProperty, </span><span style='color:Blue;'>value</span><span style='color:Black;'>); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:Blue;'>static</span><span style='color:Black;'> </span><span style='color:Blue;'>readonly</span><span style='color:Black;'> </span><span style='color:#2b91af;'>DependencyProperty</span><span style='color:Black;'> LeftHeaderProperty =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:#2b91af;'>DependencyProperty</span><span style='color:Black;'>.Register(</span><span style='color:#a31515;'>&quot;LeftHeader&quot;</span><span style='color:Black;'>, </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:Blue;'>object</span><span style='color:Black;'>), </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'>), </span><span style='color:Blue;'>new</span><span style='color:Black;'> </span><span style='color:#2b91af;'>UIPropertyMetadata</span><span style='color:Black;'>(LeftHeader_PropertyChanged));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>private</span><span style='color:Black;'> </span><span style='color:Blue;'>static</span><span style='color:Black;'> </span><span style='color:Blue;'>void</span><span style='color:Black;'> LeftHeader_PropertyChanged(</span><span style='color:#2b91af;'>DependencyObject</span><span style='color:Black;'> d, </span><span style='color:#2b91af;'>DependencyPropertyChangedEventArgs</span><span style='color:Black;'> e)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'> instance = (</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'>)d;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (e.OldValue != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance.RemoveLogicalChild(e.OldValue);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (e.NewValue != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance.AddLogicalChild(e.NewValue);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:#2b91af;'>DataTemplate</span><span style='color:Black;'> LeftHeaderTemplate<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>get</span><span style='color:Black;'> { </span><span style='color:Blue;'>return</span><span style='color:Black;'> (</span><span style='color:#2b91af;'>DataTemplate</span><span style='color:Black;'>)GetValue(LeftHeaderTemplateProperty); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>set</span><span style='color:Black;'> { SetValue(LeftHeaderTemplateProperty, </span><span style='color:Blue;'>value</span><span style='color:Black;'>); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:Blue;'>static</span><span style='color:Black;'> </span><span style='color:Blue;'>readonly</span><span style='color:Black;'> </span><span style='color:#2b91af;'>DependencyProperty</span><span style='color:Black;'> LeftHeaderTemplateProperty =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:#2b91af;'>DependencyProperty</span><span style='color:Black;'>.Register(</span><span style='color:#a31515;'>&quot;LeftHeaderTemplate&quot;</span><span style='color:Black;'>, </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>DataTemplate</span><span style='color:Black;'>), </span><span style='color:Blue;'>typeof</span><span style='color:Black;'>(</span><span style='color:#2b91af;'>HeaderedScrollViewer</span><span style='color:Black;'>), </span><span style='color:Blue;'>new</span><span style='color:Black;'> </span><span style='color:#2b91af;'>UIPropertyMetadata</span><span style='color:Black;'>());</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>protected</span><span style='color:Black;'> </span><span style='color:Blue;'>override</span><span style='color:Black;'> System.Collections.</span><span style='color:#2b91af;'>IEnumerator</span><span style='color:Black;'> LogicalChildren<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>get<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (TopHeader != </span><span style='color:Blue;'>null</span><span style='color:Black;'> || LeftHeader != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Collections.</span><span style='color:#2b91af;'>ArrayList</span><span style='color:Black;'> children = </span><span style='color:Blue;'>new</span><span style='color:Black;'> System.Collections.</span><span style='color:#2b91af;'>ArrayList</span><span style='color:Black;'>();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Collections.</span><span style='color:#2b91af;'>IEnumerator</span><span style='color:Black;'> baseEnumerator = </span><span style='color:Blue;'>base</span><span style='color:Black;'>.LogicalChildren;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>while</span><span style='color:Black;'> (baseEnumerator.MoveNext())<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;children.Add(baseEnumerator.Current);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (TopHeader != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;children.Add(TopHeader);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (LeftHeader != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;children.Add(LeftHeader);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>return</span><span style='color:Black;'> children.GetEnumerator();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>return</span><span style='color:Black;'> </span><span style='color:Blue;'>base</span><span style='color:Black;'>.LogicalChildren;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>private</span><span style='color:Black;'> </span><span style='color:#2b91af;'>ScrollViewer</span><span style='color:Black;'> topHeaderScrollViewer;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>private</span><span style='color:Black;'> </span><span style='color:#2b91af;'>ScrollViewer</span><span style='color:Black;'> leftHeaderScrollViewer;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>public</span><span style='color:Black;'> </span><span style='color:Blue;'>override</span><span style='color:Black;'> </span><span style='color:Blue;'>void</span><span style='color:Black;'> OnApplyTemplate()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>base</span><span style='color:Black;'>.OnApplyTemplate();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;topHeaderScrollViewer = </span><span style='color:Blue;'>base</span><span style='color:Black;'>.GetTemplateChild(</span><span style='color:#a31515;'>&quot;PART_TopHeaderScrollViewer&quot;</span><span style='color:Black;'>) </span><span style='color:Blue;'>as</span><span style='color:Black;'> </span><span style='color:#2b91af;'>ScrollViewer</span><span style='color:Black;'>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (topHeaderScrollViewer != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;topHeaderScrollViewer.ScrollChanged += topHeaderScrollViewer_ScrollChanged;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;leftHeaderScrollViewer = </span><span style='color:Blue;'>base</span><span style='color:Black;'>.GetTemplateChild(</span><span style='color:#a31515;'>&quot;PART_LeftHeaderScrollViewer&quot;</span><span style='color:Black;'>) </span><span style='color:Blue;'>as</span><span style='color:Black;'> </span><span style='color:#2b91af;'>ScrollViewer</span><span style='color:Black;'>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (leftHeaderScrollViewer != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;leftHeaderScrollViewer.ScrollChanged += leftHeaderScrollViewer_ScrollChanged;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>private</span><span style='color:Black;'> </span><span style='color:Blue;'>void</span><span style='color:Black;'> leftHeaderScrollViewer_ScrollChanged(</span><span style='color:Blue;'>object</span><span style='color:Black;'> sender, </span><span style='color:#2b91af;'>ScrollChangedEventArgs</span><span style='color:Black;'> e)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (e.OriginalSource == leftHeaderScrollViewer)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScrollToVerticalOffset(e.VerticalOffset);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>private</span><span style='color:Black;'> </span><span style='color:Blue;'>void</span><span style='color:Black;'> topHeaderScrollViewer_ScrollChanged(</span><span style='color:Blue;'>object</span><span style='color:Black;'> sender, </span><span style='color:#2b91af;'>ScrollChangedEventArgs</span><span style='color:Black;'> e)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (e.OriginalSource == topHeaderScrollViewer)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScrollToHorizontalOffset(e.HorizontalOffset);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>protected</span><span style='color:Black;'> </span><span style='color:Blue;'>override</span><span style='color:Black;'> </span><span style='color:Blue;'>void</span><span style='color:Black;'> OnScrollChanged(</span><span style='color:#2b91af;'>ScrollChangedEventArgs</span><span style='color:Black;'> e)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>base</span><span style='color:Black;'>.OnScrollChanged(e);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (topHeaderScrollViewer != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;topHeaderScrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>if</span><span style='color:Black;'> (leftHeaderScrollViewer != </span><span style='color:Blue;'>null</span><span style='color:Black;'>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;leftHeaderScrollViewer.ScrollToVerticalOffset(e.VerticalOffset);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</span>
</div>
<div style='font-family:Monospace;font-size:10pt;background-color:white;'>
<span style='color:#a31515;'></span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Style</span><span style='color:Red;'> TargetType</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>x</span><span style='color:Blue;'>:</span><span style='color:#a31515;'>Type</span><span style='color:Red;'> local</span><span style='color:Blue;'>:</span><span style='color:Red;'>HeaderedScrollViewer</span><span style='color:Blue;'>}&quot;&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Setter</span><span style='color:Red;'> Property</span><span style='color:Blue;'>=&quot;IsTabStop&quot;</span><span style='color:Red;'> Value</span><span style='color:Blue;'>=&quot;False&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Setter</span><span style='color:Red;'> Property</span><span style='color:Blue;'>=&quot;Focusable&quot;</span><span style='color:Red;'> Value</span><span style='color:Blue;'>=&quot;False&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Setter</span><span style='color:Red;'> Property</span><span style='color:Blue;'>=&quot;Template&quot;&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Setter.Value</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ControlTemplate</span><span style='color:Red;'> TargetType</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>x</span><span style='color:Blue;'>:</span><span style='color:#a31515;'>Type</span><span style='color:Red;'> local</span><span style='color:Blue;'>:</span><span style='color:Red;'>HeaderedScrollViewer</span><span style='color:Blue;'>}&quot;&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Grid</span><span style='color:Red;'> Margin</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> Padding</span><span style='color:Blue;'>}&quot;</span><span style='color:Red;'> Background</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> Background</span><span style='color:Blue;'>}&quot;</span><span style='color:Red;'> SnapsToDevicePixels</span><span style='color:Blue;'>=&quot;true&quot;&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Grid.ColumnDefinitions</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ColumnDefinition</span><span style='color:Red;'> Width</span><span style='color:Blue;'>=&quot;Auto&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ColumnDefinition</span><span style='color:Red;'> Width</span><span style='color:Blue;'>=&quot;*&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ColumnDefinition</span><span style='color:Red;'> Width</span><span style='color:Blue;'>=&quot;Auto&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>Grid.ColumnDefinitions</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Grid.RowDefinitions</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>RowDefinition</span><span style='color:Red;'> Height</span><span style='color:Blue;'>=&quot;Auto&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>RowDefinition</span><span style='color:Red;'> Height</span><span style='color:Blue;'>=&quot;*&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>RowDefinition</span><span style='color:Red;'> Height</span><span style='color:Blue;'>=&quot;Auto&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>Grid.RowDefinitions</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ScrollViewer</span><span style='color:Red;'> Name</span><span style='color:Blue;'>=&quot;PART_TopHeaderScrollViewer&quot;</span><span style='color:Red;'> Grid.Column</span><span style='color:Blue;'>=&quot;1&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> HorizontalScrollBarVisibility</span><span style='color:Blue;'>=&quot;Hidden&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> VerticalScrollBarVisibility</span><span style='color:Blue;'>=&quot;Hidden&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> Focusable</span><span style='color:Blue;'>=&quot;false&quot;&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ContentPresenter</span><span style='color:Red;'> Content</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> TopHeader</span><span style='color:Blue;'>}&quot;</span><span style='color:Red;'> MinWidth</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ExtentWidth</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> ContentTemplate</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> TopHeaderTemplate</span><span style='color:Blue;'>}&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>ScrollViewer</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ScrollViewer</span><span style='color:Red;'> Name</span><span style='color:Blue;'>=&quot;PART_LeftHeaderScrollViewer&quot;</span><span style='color:Red;'> Grid.Row</span><span style='color:Blue;'>=&quot;1&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> HorizontalScrollBarVisibility</span><span style='color:Blue;'>=&quot;Hidden&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> VerticalScrollBarVisibility</span><span style='color:Blue;'>=&quot;Hidden&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> Focusable</span><span style='color:Blue;'>=&quot;false&quot;&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ContentPresenter</span><span style='color:Red;'> Content</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> LeftHeader</span><span style='color:Blue;'>}&quot;</span><span style='color:Red;'> MinHeight</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ExtentHeight</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> ContentTemplate</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> LeftHeaderTemplate</span><span style='color:Blue;'>}&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>ScrollViewer</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>AdornerDecorator</span><span style='color:Red;'> x</span><span style='color:Blue;'>:</span><span style='color:Red;'>Name</span><span style='color:Blue;'>=&quot;test&quot;</span><span style='color:Red;'> Grid.Row</span><span style='color:Blue;'>=&quot;1&quot;</span><span style='color:Red;'> Grid.Column</span><span style='color:Blue;'>=&quot;1&quot;&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ScrollContentPresenter</span><span style='color:Red;'> Name</span><span style='color:Blue;'>=&quot;PART_ScrollContentPresenter&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> KeyboardNavigation.DirectionalNavigation</span><span style='color:Blue;'>=&quot;Local&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> Content</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> Content</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> ContentTemplate</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ContentTemplate</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> CanContentScroll</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> CanContentScroll</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style='color:Red;'> SnapsToDevicePixels</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> SnapsToDevicePixels</span><span style='color:Blue;'>}&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>AdornerDecorator</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ScrollBar</span><span style='color:Red;'> Name</span><span style='color:Blue;'>=&quot;PART_HorizontalScrollBar&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Orientation</span><span style='color:Blue;'>=&quot;Horizontal&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Grid.Row</span><span style='color:Blue;'>=&quot;2&quot;</span><span style='color:Red;'> Grid.ColumnSpan</span><span style='color:Blue;'>=&quot;2&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Minimum</span><span style='color:Blue;'>=&quot;0.0&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Maximum</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ScrollableWidth</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> ViewportSize</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ViewportWidth</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Value</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>Binding</span><span style='color:Red;'> Path</span><span style='color:Blue;'>=HorizontalOffset,</span><span style='color:Red;'>RelativeSource</span><span style='color:Blue;'>={</span><span style='color:#a31515;'>RelativeSource</span><span style='color:Red;'> TemplatedParent</span><span style='color:Blue;'>},</span><span style='color:Red;'>Mode</span><span style='color:Blue;'>=OneWay}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Visibility</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ComputedHorizontalScrollBarVisibility</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Cursor</span><span style='color:Blue;'>=&quot;Arrow&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>ScrollBar</span><span style='color:Red;'> Name</span><span style='color:Blue;'>=&quot;PART_VerticalScrollBar&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Orientation</span><span style='color:Blue;'>=&quot;Vertical&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Grid.Column</span><span style='color:Blue;'>=&quot;2&quot;</span><span style='color:Red;'> Grid.RowSpan</span><span style='color:Blue;'>=&quot;2&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Minimum</span><span style='color:Blue;'>=&quot;0.0&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Maximum</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ScrollableHeight</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> ViewportSize</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ViewportHeight</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Value</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>Binding</span><span style='color:Red;'> Path</span><span style='color:Blue;'>=VerticalOffset,</span><span style='color:Red;'>RelativeSource</span><span style='color:Blue;'>={</span><span style='color:#a31515;'>RelativeSource</span><span style='color:Red;'> TemplatedParent</span><span style='color:Blue;'>},</span><span style='color:Red;'>Mode</span><span style='color:Blue;'>=OneWay}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Visibility</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ComputedVerticalScrollBarVisibility</span><span style='color:Blue;'>}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Cursor</span><span style='color:Blue;'>=&quot;Arrow&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>DockPanel</span><span style='color:Red;'> Grid.Column</span><span style='color:Blue;'>=&quot;2&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Grid.Row</span><span style='color:Blue;'>=&quot;2&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Background</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>Binding</span><span style='color:Red;'> Path</span><span style='color:Blue;'>=Background,</span><span style='color:Red;'>ElementName</span><span style='color:Blue;'>=PART_VerticalScrollBar}&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> LastChildFill</span><span style='color:Blue;'>=&quot;false&quot;&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Rectangle</span><span style='color:Red;'> DockPanel.Dock</span><span style='color:Blue;'>=&quot;Left&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Width</span><span style='color:Blue;'>=&quot;1&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Fill</span><span style='color:Blue;'>=&quot;White&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Visibility</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ComputedVerticalScrollBarVisibility</span><span style='color:Blue;'>}&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;</span><span style='color:#a31515;'>Rectangle</span><span style='color:Red;'> DockPanel.Dock</span><span style='color:Blue;'>=&quot;Top&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Height</span><span style='color:Blue;'>=&quot;1&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Fill</span><span style='color:Blue;'>=&quot;White&quot;<br />
</span><span style='color:Black;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Red;'> Visibility</span><span style='color:Blue;'>=&quot;{</span><span style='color:#a31515;'>TemplateBinding</span><span style='color:Red;'> ComputedHorizontalScrollBarVisibility</span><span style='color:Blue;'>}&quot;/&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>DockPanel</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>Grid</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>ControlTemplate</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>Setter.Value</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>Setter</span><span style='color:Blue;'>&gt;<br />
</span><span style='color:#a31515;'></span><span style='color:Blue;'>&lt;/</span><span style='color:#a31515;'>Style</span><span style='color:Blue;'>&gt;</span>
</div>
<p></code></p>
<br />Posted in WPF Tagged: ComboBox, ScrollChanged, ScrollViewer, WPF <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=32&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2009/11/07/headeredscrollviewer-in-wpf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>Improve XAML editing experience in Visual Studio</title>
		<link>http://softnotes.wordpress.com/2009/02/21/improve-xaml-editing-experience-in-visual-studio/</link>
		<comments>http://softnotes.wordpress.com/2009/02/21/improve-xaml-editing-experience-in-visual-studio/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 19:17:48 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=29</guid>
		<description><![CDATA[I have been quite busy for some time to put up any posts but this XAML tip (thanks to Fabrice) just needs to be &#8220;out there&#8221; Right-click on a XAML file in the Solution Explorer Select &#8220;Open With&#8230;&#8221; Select &#8220;Source Code (Text) Editor&#8221; Click on &#8220;Set as Default&#8221; Click OK You&#8217;re done! This completely eliminates [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=29&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been quite busy for some time to put up any posts but <a href="http://weblogs.asp.net/fmarguerie/archive/2009/01/29/life-changer-xaml-tip-for-visual-studio.aspx" target="_blank">this XAML tip</a> (thanks to <a href="http://weblogs.asp.net/fmarguerie/" target="_blank">Fabrice</a>) just needs to be &#8220;out there&#8221;</p>
<ol>
<li><strong>Right-click on a XAML file in the Solution Explorer</strong></li>
<li><strong>Select &#8220;Open With&#8230;&#8221;</strong></li>
<li><strong>Select &#8220;Source Code (Text) Editor&#8221;</strong></li>
<li><strong>Click on &#8220;Set as Default&#8221;</strong></li>
<li><strong>Click OK</strong></li>
<li><strong>You&#8217;re done!</strong></li>
</ol>
<p>This completely eliminates the useless XAML designer while still providing intellisense and tag collapsing.</p>
<br />Posted in Uncategorized, WPF Tagged: Visual Studio, WPF, XAML <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=29&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2009/02/21/improve-xaml-editing-experience-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>Using BindingGroup in custom controls</title>
		<link>http://softnotes.wordpress.com/2008/09/25/using-bindinggroup-in-custom-controls/</link>
		<comments>http://softnotes.wordpress.com/2008/09/25/using-bindinggroup-in-custom-controls/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 20:10:42 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=24</guid>
		<description><![CDATA[I have a WPF custom control to display and edit a double value. The control exposes a dependency property called Value, along with a Format, Converter and ConverterParameter properties. The control template has a TextBox whose Text property is bound to the Value property with a custom converter. private void SetValueBinding() {     if (textbox == null) return;     textbox.SetBinding(TextBox.TextProperty, new Binding(&#8220;Value&#8221;) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=24&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have a WPF custom control to display and edit a double value. The control exposes a dependency property called <code>Value</code>, along with a <code>Format</code>, <code>Converter</code> and <code>ConverterParameter</code> properties. The control template has a <code>TextBox</code> whose <code>Text</code> property is bound to the <code>Value</code> property with a custom converter.</p>
<div style="font-size:10pt;font-family:Monospace;background-color:white;">
<div style="font-size:10pt;font-family:Monospace;background-color:white;">
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> SetValueBinding()<br />
{<br />
    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (textbox == </span><span style="color:#0000ff;">null</span><span style="color:#000000;">) </span><span style="color:#0000ff;">return</span><span style="color:#000000;">;<br />
    </span><span style="color:#000000;">textbox.SetBinding(</span><span style="color:#2b91af;">TextBox</span><span style="color:#000000;">.TextProperty, </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">Binding</span><span style="color:#000000;">(</span><span style="color:#a31515;">&#8220;Value&#8221;</span><span style="color:#000000;">)<br />
    {<br />
        Source = </span><span style="color:#0000ff;">this</span><span style="color:#000000;">,<br />
        Converter = </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">CustomConverter</span><span style="color:#000000;">() { Converter = Converter, Format = Format },<br />
        ConverterParameter = ConverterParameter,<br />
        Mode = </span><span style="color:#2b91af;">BindingMode</span><span style="color:#000000;">.TwoWay,<br />
        ValidatesOnExceptions = </span><span style="color:#0000ff;">true<br />
</span><span style="color:#000000;">    });<br />
</span><span style="color:#000000;">}</span></div>
</div>
</div>
<p>(Here textbox is the instance of the <code>TextBox</code> that must be a part of the <code>ControlTemplate</code>, and the <code>SetValueBinding</code> method is called in the <code>OnApplyTemplate</code> override after obtaining the textbox instance)<br />
This works well except for validation. If the user types in some text in the custom control that cannot be converted to a double, the <code>Binding</code> shown above fails. But this binding error does not participate in the validation mechanism (look at my <a href="http://softnotes.wordpress.com/2008/08/20/validation-in-wpf-with-net-35-sp1/" target="_blank">earlier post</a> on validation for a pattern for implementing validation). The solution is to find a <code>BindingGroup</code> on a parent of the custom control and add the <code>BindingExpression</code> to the <code>BindingGroup</code>.</p>
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#2b91af;">BindingGroup</span><span style="color:#000000;"> GetParentBindingGroup()<br />
{<br />
    </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:#000000;"> element = </span><span style="color:#0000ff;">this</span><span style="color:#000000;">;<br />
    </span><span style="color:#0000ff;">while</span><span style="color:#000000;"> (element != </span><span style="color:#0000ff;">null</span><span style="color:#000000;">)<br />
    {<br />
        </span><span style="color:#2b91af;">BindingGroup</span><span style="color:#000000;"> grp = element.BindingGroup;<br />
        </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (grp != </span><span style="color:#0000ff;">null</span><span style="color:#000000;">)<br />
            </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> grp;<br />
        element = </span><span style="color:#2b91af;">VisualTreeHelper</span><span style="color:#000000;">.GetParent(element) </span><span style="color:#0000ff;">as</span><span style="color:#000000;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:#000000;">;<br />
    }<br />
    </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">null</span><span style="color:#000000;">;<br />
}</span></div>
<p>This can now be used in the <code>SetValueBinding</code> method</p>
<div style="font-size:10pt;font-family:Monospace;background-color:white;">
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> SetValueBinding()<br />
{<br />
    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (textbox == </span><span style="color:#0000ff;">null</span><span style="color:#000000;">) </span><span style="color:#0000ff;">return</span><span style="color:#000000;">;<br />
    </span><span style="color:#2b91af;">BindingGroup</span><span style="color:#000000;"> group = GetParentBindingGroup();<br />
    </span><span style="color:#2b91af;">BindingExpressionBase</span><span style="color:#000000;"> expr =<br />
        </span><span style="color:#2b91af;">BindingOperations</span><span style="color:#000000;">.GetBindingExpressionBase(textbox, </span><span style="color:#2b91af;">TextBox</span><span style="color:#000000;">.TextProperty);<br />
    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (group != </span><span style="color:#0000ff;">null</span><span style="color:#000000;"> &amp;&amp; expr != </span><span style="color:#0000ff;">null</span><span style="color:#000000;">)<br />
        group.BindingExpressions.Remove(expr);<br />
    textbox.SetBinding(</span><span style="color:#2b91af;">TextBox</span><span style="color:#000000;">.TextProperty, </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">Binding</span><span style="color:#000000;">(</span><span style="color:#a31515;">&#8220;Value&#8221;</span><span style="color:#000000;">)<br />
    {<br />
        Source = </span><span style="color:#0000ff;">this</span><span style="color:#000000;">,<br />
        Converter = </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">CustomConverter</span><span style="color:#000000;">() { Converter = Converter, Format = Format },<br />
        ConverterParameter = ConverterParameter,<br />
        Mode = </span><span style="color:#2b91af;">BindingMode</span><span style="color:#000000;">.TwoWay,<br />
        ValidatesOnExceptions = </span><span style="color:#0000ff;">true<br />
</span><span style="color:#000000;">    });<br />
    expr = </span><span style="color:#2b91af;">BindingOperations</span><span style="color:#000000;">.GetBindingExpressionBase(textbox, </span><span style="color:#2b91af;">TextBox</span><span style="color:#000000;">.TextProperty);<br />
    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (group != </span><span style="color:#0000ff;">null</span><span style="color:#000000;">)<br />
        group.BindingExpressions.Add(expr);<br />
}</span></div>
</div>
<br />Posted in WPF Tagged: Validation, WPF <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=24&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2008/09/25/using-bindinggroup-in-custom-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>JPEG Images in WPF</title>
		<link>http://softnotes.wordpress.com/2008/09/01/jpeg-images-in-wpf/</link>
		<comments>http://softnotes.wordpress.com/2008/09/01/jpeg-images-in-wpf/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 18:01:15 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[Images]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=21</guid>
		<description><![CDATA[I recently implemented a very simple help system for a WPF application consisting of showing an image in a help window with the selection of the image based on the application state. The images were all jpegs. The system worked well on Vista &#8211; my development machine &#8211; but on an XP test machine, loading the first [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=21&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently implemented a very simple help system for a WPF application consisting of showing an image in a help window with the selection of the image based on the application state. The images were all jpegs. The system worked well on Vista &#8211; my development machine &#8211; but on an XP test machine, loading the first image took inordinately long - around a minute. The subsequent images loaded instantaneously. For the moment, I have solved the issue by converting all images to PNG. It looks like some problem with loading the JPEG decoder. Need to investigate this further.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/softnotes.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/softnotes.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=21&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2008/09/01/jpeg-images-in-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>Validation in WPF with .NET 3.5 SP1</title>
		<link>http://softnotes.wordpress.com/2008/08/20/validation-in-wpf-with-net-35-sp1/</link>
		<comments>http://softnotes.wordpress.com/2008/08/20/validation-in-wpf-with-net-35-sp1/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 18:56:45 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=15</guid>
		<description><![CDATA[With the new BindingGroup support in WPF, validation in WPF can be handled much more cleanly than it was possible in the past. Here is a pattern that I believe I will be using fairly often. In the data layer: Make all domain objects implement IEditableObject and IDataErrorInfo and INotifyPropertyChanged. Apply property level validation logic in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=15&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With the new <code>BindingGroup</code> support in WPF, validation in WPF can be handled much more cleanly than it was possible in the past. Here is a pattern that I believe I will be using fairly often.</p>
<p>In the data layer:</p>
<p>Make all domain objects implement <code>IEditableObject</code> and <code>IDataErrorInfo</code> and <code>INotifyPropertyChanged</code>.</p>
<p>Apply property level validation logic in the property setters of the domain objects. Throw exceptions when the logic is violated. (Example: Throw an exception if a name is null or empty or too long, Throw an exception if a number is negative etc.)</p>
<p>Apply object level validation logic in the implementation of <code>IDataErrorInfo.Error</code>. Do not throw exceptions when object level validation logic is violated.</p>
<p>Return null in the implementation of <code>IDataErrorInfo.this[string ColumnName]</code>.</p>
<p>In the WPF layer:</p>
<p>Use a <code>BindingGroup</code> on the container that contains the editable UI elements</p>
<p>Use an instance of the following ValidationRule on the BindingGroup</p>
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">class</span><span style="color:#000000;"> </span><span style="color:#2b91af;">DataErrorValidationRule</span><span style="color:#000000;"> : </span><span style="color:#2b91af;">ValidationRule<br />
</span><span style="color:#000000;">{<br />
    </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">override</span><span style="color:#000000;"> </span><span style="color:#2b91af;">ValidationResult</span><span style="color:#000000;"> Validate(</span><span style="color:#0000ff;">object</span><span style="color:#000000;"> value,<br />
        System.Globalization.</span><span style="color:#2b91af;">CultureInfo</span><span style="color:#000000;"> cultureInfo)<br />
    {<br />
        </span><span style="color:#2b91af;">BindingGroup</span><span style="color:#000000;"> group = (</span><span style="color:#2b91af;">BindingGroup</span><span style="color:#000000;">)value;<br />
        </span><span style="color:#008000;">// if any expression is in error, the object level validation<br />
</span><span style="color:#000000;">        </span><span style="color:#008000;">// cannot be trusted, since atleast some properties have not been<br />
</span><span style="color:#000000;">        </span><span style="color:#008000;">// set. Better to skip object level validation than report<br />
</span><span style="color:#000000;">        </span><span style="color:#008000;">// spurious errors<br />
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (group.BindingExpressions.Any(be =&gt; be.HasError))<br />
            </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#2b91af;">ValidationResult</span><span style="color:#000000;">.ValidResult;<br />
        </span><span style="color:#2b91af;">StringBuilder</span><span style="color:#000000;"> sb = </span><span style="color:#0000ff;">null</span><span style="color:#000000;">;<br />
        </span><span style="color:#0000ff;">foreach</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> item </span><span style="color:#0000ff;">in</span><span style="color:#000000;"> group.Items)<br />
        {</span><span style="color:#008000;">// Unlikely to have more than one item, but loop through anyway<br />
</span><span style="color:#000000;">            </span><span style="color:#2b91af;">IDataErrorInfo</span><span style="color:#000000;"> info = item </span><span style="color:#0000ff;">as</span><span style="color:#000000;"> </span><span style="color:#2b91af;">IDataErrorInfo</span><span style="color:#000000;">;<br />
            </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (info != </span><span style="color:#0000ff;">null</span><span style="color:#000000;">)<br />
            {<br />
                </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> error = info.Error;<br />
                </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (!</span><span style="color:#0000ff;">string</span><span style="color:#000000;">.IsNullOrEmpty(error))<br />
                {<br />
                    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (sb == </span><span style="color:#0000ff;">null</span><span style="color:#000000;">) sb = </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">StringBuilder</span><span style="color:#000000;">();<br />
                    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (sb.Length != 0) sb.AppendLine();<br />
                    sb.Append(error);<br />
                }<br />
            }<br />
        }<br />
        </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (sb != </span><span style="color:#0000ff;">null</span><span style="color:#000000;">)<br />
            </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">ValidationResult</span><span style="color:#000000;">(</span><span style="color:#0000ff;">false</span><span style="color:#000000;">, sb.ToString());<br />
        </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#2b91af;">ValidationResult</span><span style="color:#000000;">.ValidResult;<br />
    }<br />
}</span></div>
<p>Explicitly set <code>UpdateSourceTrigger</code> to <code>PropertyChanged</code> or <code>LostFocus</code> on all bindings in the <code>BindingGroup</code>.</p>
<p>Set <code>ValidatesOnExceptions</code> to <code>True</code> on all bindings in the <code>BindingGroup</code>.</p>
<p>Define <code>Edit</code>, <code>Accept</code> and <code>Cancel</code> <code>RoutedUICommands</code>. Call BeginEdit, CommitEdit and CancelEdit on the <code>BindingGroup</code> when the commands are executed. Call <code>ValidateWithoutUpdate</code> and set <code>CanExecuteRoutedEventArgs.CanExecute</code> to the <code>Validation.HasError</code> property on the container element in the CanExecute event handler for the Accept command.</p>
<p>Use the following code to extract the error message from a <code>ValidationError</code> for display in the UI.</p>
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:#0000ff;">internal</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> ExtractErrorMessage(</span><span style="color:#2b91af;">ValidationError</span><span style="color:#000000;"> error)<br />
{<br />
    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (error.Exception </span><span style="color:#0000ff;">is</span><span style="color:#000000;"> </span><span style="color:#2b91af;">TargetInvocationException</span><span style="color:#000000;"> &amp;&amp;<br />
        error.Exception.Message == (</span><span style="color:#0000ff;">string</span><span style="color:#000000;">)error.ErrorContent)<br />
        </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> error.Exception.InnerException.Message;<br />
    </span><span style="color:#0000ff;">else<br />
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> System.</span><span style="color:#2b91af;">Convert</span><span style="color:#000000;">.ToString(error.ErrorContent);<br />
}</span></div>
<p>The code for all the work in the WPF layer can be abstracted into a static class with attached properties for use in XAML. This class provides the following features</p>
<ul>
<li><code>IsEditableContainer</code> attached property (Set to <code>True</code> on the container containing all the editing UI) This can be set both on a stand alone container or a container in an <code>ItemsControl</code> such as a <code>ListBoxItem</code> via a <code>Style</code>. When used in an <code>ItemsControl</code>, the code calls <code>EditItem</code>, <code>CommitEdit</code> and <code>CancelEdit</code> on the <code>IEditableCollectionView</code> used by the <code>ItemsControl</code>.</li>
<li><code>IsEditingEnabled</code> attached property (Set to <code>False</code> to disable editing. Can be bound to <code>ListBoxItem.IsSelected</code> for example)</li>
<li><code>IsDeletingEnabled</code> attached property (Set to <code>True</code> to allow deleting the data item. Only relevant if the data item is in a collection and is being displayed in an <code>ItemsControl</code>)</li>
<li><code>EditGesture</code>, <code>AcceptGesture</code>, <code>CancelGesture </code>and <code>DeleteGesture</code> attached properties. Specify <code>KeyGesture</code>s for the <code>Edit</code>, <code>Accept</code>, <code>Cancel</code> and <code>Delete</code> commands</li>
<li><code>Deleting</code> routed event which bubbles up the element tree. Use to cancel (possibly with a confirm dialog box) the execution of the <code>Delete</code> command</li>
</ul>
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">class</span><span style="color:black;"> </span><span style="color:#2b91af;">DataEditing<br />
</span><span style="color:black;">{<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">bool</span><span style="color:black;"> GetIsEditableContainer(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj)<br />
    {<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> (</span><span style="color:blue;">bool</span><span style="color:black;">)obj.GetValue(IsEditableContainerProperty);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> SetIsEditableContainer(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj, </span><span style="color:blue;">bool</span><span style="color:black;"> value)<br />
    {<br />
        obj.SetValue(IsEditableContainerProperty, value);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> IsEditableContainerProperty =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.RegisterAttached(</span><span style="color:#a31515;">&#8220;IsEditableContainer&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:blue;">bool</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">),<br />
            </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkPropertyMetadata</span><span style="color:black;">(IsEditableContainer_PropertyChanged));<br />
    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> IsEditableContainer_PropertyChanged(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> d, </span><span style="color:#2b91af;">DependencyPropertyChangedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = d </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;<br />
        </span><span style="color:blue;">if</span><span style="color:black;"> (element == </span><span style="color:blue;">null</span><span style="color:black;">) </span><span style="color:blue;">return</span><span style="color:black;">;<br />
        </span><span style="color:blue;">bool</span><span style="color:black;"> editable = (</span><span style="color:blue;">bool</span><span style="color:black;">)e.NewValue;<br />
        </span><span style="color:blue;">if</span><span style="color:black;"> (editable)<br />
        {<br />
            </span><span style="color:#2b91af;">BindingGroup</span><span style="color:black;"> group = </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">BindingGroup</span><span style="color:black;">();<br />
            group.ValidationRules.Add(</span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">DataErrorValidationRule</span><span style="color:black;">());<br />
            element.BindingGroup = group;<br />
            element.CommandBindings.Add(</span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">CommandBinding</span><span style="color:black;">(Edit, OnExecuteEditCommand, CanExecuteEditCommand));<br />
            element.CommandBindings.Add(</span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">CommandBinding</span><span style="color:black;">(Accept, OnExecuteAcceptCommand, CanExecuteAcceptCommand));<br />
            element.CommandBindings.Add(</span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">CommandBinding</span><span style="color:black;">(Cancel, OnExecuteCancelCommand, CanExecuteCancelCommand));<br />
            element.CommandBindings.Add(</span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">CommandBinding</span><span style="color:black;">(Delete, OnExecuteDeleteCommand, CanExecuteDeleteCommand));<br />
        }<br />
        </span><span style="color:blue;">else<br />
</span><span style="color:black;">        {<br />
            element.BindingGroup = </span><span style="color:blue;">null</span><span style="color:black;">;<br />
            element.CommandBindings.Remove((</span><span style="color:#2b91af;">CommandBinding</span><span style="color:black;"> b) =&gt; b.Command == Edit);<br />
            element.CommandBindings.Remove((</span><span style="color:#2b91af;">CommandBinding</span><span style="color:black;"> b) =&gt; b.Command == Accept);<br />
            element.CommandBindings.Remove((</span><span style="color:#2b91af;">CommandBinding</span><span style="color:black;"> b) =&gt; b.Command == Cancel);<br />
            element.CommandBindings.Remove((</span><span style="color:#2b91af;">CommandBinding</span><span style="color:black;"> b) =&gt; b.Command == Delete);<br />
        }<br />
    }</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">bool</span><span style="color:black;"> GetIsEditingEnabled(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj)<br />
    {<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> (</span><span style="color:blue;">bool</span><span style="color:black;">)obj.GetValue(IsEditingEnabledProperty);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> SetIsEditingEnabled(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj, </span><span style="color:blue;">bool</span><span style="color:black;"> value)<br />
    {<br />
        obj.SetValue(IsEditingEnabledProperty, value);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> IsEditingEnabledProperty =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.RegisterAttached(</span><span style="color:#a31515;">&#8220;IsEditingEnabled&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:blue;">bool</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">),<br />
            </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkPropertyMetadata</span><span style="color:black;">(</span><span style="color:blue;">true</span><span style="color:black;">));</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">bool</span><span style="color:black;"> GetIsDeletingEnabled(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj)<br />
    {<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> (</span><span style="color:blue;">bool</span><span style="color:black;">)obj.GetValue(IsDeletingEnabledProperty);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> SetIsDeletingEnabled(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj, </span><span style="color:blue;">bool</span><span style="color:black;"> value)<br />
    {<br />
        obj.SetValue(IsDeletingEnabledProperty, value);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> IsDeletingEnabledProperty =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.RegisterAttached(</span><span style="color:#a31515;">&#8220;IsDeletingEnabled&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:blue;">bool</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">),<br />
            </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkPropertyMetadata</span><span style="color:black;">(</span><span style="color:blue;">false</span><span style="color:black;">));</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> GetEditGesture(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj)<br />
    {<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> (</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">)obj.GetValue(EditGestureProperty);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> SetEditGesture(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj, </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> value)<br />
    {<br />
        obj.SetValue(EditGestureProperty, value);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> EditGestureProperty =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.RegisterAttached(</span><span style="color:#a31515;">&#8220;EditGesture&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">),<br />
            </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkPropertyMetadata</span><span style="color:black;">(CommandGesture_PropertyChanged));</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> GetAcceptGesture(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj)<br />
    {<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> (</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">)obj.GetValue(AcceptGestureProperty);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> SetAcceptGesture(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj, </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> value)<br />
    {<br />
        obj.SetValue(AcceptGestureProperty, value);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> AcceptGestureProperty =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.RegisterAttached(</span><span style="color:#a31515;">&#8220;AcceptGesture&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">),<br />
            </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkPropertyMetadata</span><span style="color:black;">(CommandGesture_PropertyChanged));</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> GetCancelGesture(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj)<br />
    {<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> (</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">)obj.GetValue(CancelGestureProperty);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> SetCancelGesture(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj, </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> value)<br />
    {<br />
        obj.SetValue(CancelGestureProperty, value);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> CancelGestureProperty =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.RegisterAttached(</span><span style="color:#a31515;">&#8220;CancelGesture&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">),<br />
            </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkPropertyMetadata</span><span style="color:black;">(CommandGesture_PropertyChanged));</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> GetDeleteGesture(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj)<br />
    {<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> (</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">)obj.GetValue(DeleteGestureProperty);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> SetDeleteGesture(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj, </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> value)<br />
    {<br />
        obj.SetValue(DeleteGestureProperty, value);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> DeleteGestureProperty =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.RegisterAttached(</span><span style="color:#a31515;">&#8220;DeleteGesture&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">),<br />
            </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkPropertyMetadata</span><span style="color:black;">(CommandGesture_PropertyChanged));</p>
<p>    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> CommandGesture_PropertyChanged(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> d, </span><span style="color:#2b91af;">DependencyPropertyChangedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> dp = e.Property;<br />
        </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;"> command =<br />
            dp == EditGestureProperty ? Edit :<br />
            dp == AcceptGestureProperty ? Accept :<br />
            dp == CancelGestureProperty ? Cancel :<br />
            dp == DeleteGestureProperty ? Delete :<br />
            </span><span style="color:blue;">null</span><span style="color:black;">;<br />
        </span><span style="color:blue;">if</span><span style="color:black;"> (command != </span><span style="color:blue;">null</span><span style="color:black;">)<br />
        {<br />
            </span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;"> gesture = (</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">)e.OldValue;<br />
            </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = (</span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">)d;<br />
            </span><span style="color:blue;">if</span><span style="color:black;"> (gesture != </span><span style="color:blue;">null</span><span style="color:black;">)<br />
                element.InputBindings.Remove((</span><span style="color:#2b91af;">InputBinding</span><span style="color:black;"> ib) =&gt; ib.Command == command &amp;&amp; ib.Gesture == gesture);<br />
            gesture = (</span><span style="color:#2b91af;">KeyGesture</span><span style="color:black;">)e.NewValue;<br />
            </span><span style="color:blue;">if</span><span style="color:black;"> (gesture != </span><span style="color:blue;">null</span><span style="color:black;">)<br />
                element.InputBindings.Add(</span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">InputBinding</span><span style="color:black;">(command, gesture));<br />
        }<br />
    }</p>
<p>    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">bool</span><span style="color:black;"> GetViewAndItem(</span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element, </span><span style="color:blue;">out</span><span style="color:black;"> </span><span style="color:#2b91af;">IEditableCollectionView</span><span style="color:black;"> view, </span><span style="color:blue;">out</span><span style="color:black;"> </span><span style="color:blue;">object</span><span style="color:black;"> dataItem)<br />
    {<br />
        </span><span style="color:#2b91af;">ItemsControl</span><span style="color:black;"> ic = </span><span style="color:#2b91af;">ItemsControl</span><span style="color:black;">.ItemsControlFromItemContainer(element);<br />
        </span><span style="color:blue;">if</span><span style="color:black;"> (ic != </span><span style="color:blue;">null</span><span style="color:black;">)<br />
        {<br />
            </span><span style="color:blue;">object</span><span style="color:black;"> item = ic.ItemContainerGenerator.ItemFromContainer(element);<br />
            </span><span style="color:blue;">if</span><span style="color:black;"> (item != </span><span style="color:blue;">null</span><span style="color:black;"> &amp;&amp; item != </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.UnsetValue)<br />
            {<br />
                view = (</span><span style="color:#2b91af;">IEditableCollectionView</span><span style="color:black;">)ic.Items;<br />
                dataItem = item;<br />
                </span><span style="color:blue;">return</span><span style="color:black;"> </span><span style="color:blue;">true</span><span style="color:black;">;<br />
            }<br />
        }<br />
        view = </span><span style="color:blue;">null</span><span style="color:black;">;<br />
        dataItem = </span><span style="color:blue;">null</span><span style="color:black;">;<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> </span><span style="color:blue;">false</span><span style="color:black;">;<br />
    }</p>
<p>    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> CanExecuteEditCommand(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">CanExecuteRoutedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = sender </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;<br />
        e.CanExecute = GetIsEditingEnabled(element) &amp;&amp; GetIsReadOnly(element);<br />
    }<br />
    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> OnExecuteEditCommand(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">ExecutedRoutedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = sender </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;</p>
<p>        </span><span style="color:#2b91af;">IEditableCollectionView</span><span style="color:black;"> view;<br />
        </span><span style="color:blue;">object</span><span style="color:black;"> item;<br />
        </span><span style="color:blue;">if</span><span style="color:black;"> (GetViewAndItem(element, </span><span style="color:blue;">out</span><span style="color:black;"> view, </span><span style="color:blue;">out</span><span style="color:black;"> item))<br />
            view.EditItem(item);<br />
        element.BindingGroup.BeginEdit();</p>
<p>        SetIsReadOnly(element, </span><span style="color:blue;">false</span><span style="color:black;">);<br />
    }</p>
<p>    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> CanExecuteAcceptCommand(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">CanExecuteRoutedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = sender </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;<br />
        element.BindingGroup.ValidateWithoutUpdate();<br />
        e.CanExecute = !GetIsReadOnly(element) &amp;&amp; !</span><span style="color:#2b91af;">Validation</span><span style="color:black;">.GetHasError(element);<br />
    }<br />
    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> OnExecuteAcceptCommand(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">ExecutedRoutedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = sender </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;<br />
        element.BindingGroup.CommitEdit();</p>
<p>        </span><span style="color:#2b91af;">IEditableCollectionView</span><span style="color:black;"> view;<br />
        </span><span style="color:blue;">object</span><span style="color:black;"> item;<br />
        </span><span style="color:blue;">if</span><span style="color:black;"> (GetViewAndItem(element, </span><span style="color:blue;">out</span><span style="color:black;"> view, </span><span style="color:blue;">out</span><span style="color:black;"> item))<br />
            view.CommitEdit();</p>
<p>        SetIsReadOnly(element, </span><span style="color:blue;">true</span><span style="color:black;">);<br />
    }</p>
<p>    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> CanExecuteCancelCommand(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">CanExecuteRoutedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = sender </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;<br />
        e.CanExecute = !GetIsReadOnly(element);<br />
    }<br />
    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> OnExecuteCancelCommand(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">ExecutedRoutedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = sender </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;<br />
        element.BindingGroup.CancelEdit();</p>
<p>        </span><span style="color:#2b91af;">IEditableCollectionView</span><span style="color:black;"> view;<br />
        </span><span style="color:blue;">object</span><span style="color:black;"> item;<br />
        </span><span style="color:blue;">if</span><span style="color:black;"> (GetViewAndItem(element, </span><span style="color:blue;">out</span><span style="color:black;"> view, </span><span style="color:blue;">out</span><span style="color:black;"> item))<br />
            view.CancelEdit();</p>
<p>        SetIsReadOnly(element, </span><span style="color:blue;">true</span><span style="color:black;">);<br />
    }</p>
<p>    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> CanExecuteDeleteCommand(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">CanExecuteRoutedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = sender </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;<br />
        e.CanExecute = GetIsDeletingEnabled(element);<br />
    }<br />
    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> OnExecuteDeleteCommand(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">ExecutedRoutedEventArgs</span><span style="color:black;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;"> element = sender </span><span style="color:blue;">as</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">;</p>
<p>        </span><span style="color:#2b91af;">IEditableCollectionView</span><span style="color:black;"> view;<br />
        </span><span style="color:blue;">object</span><span style="color:black;"> item;<br />
        </span><span style="color:blue;">if</span><span style="color:black;"> (GetViewAndItem(element, </span><span style="color:blue;">out</span><span style="color:black;"> view, </span><span style="color:blue;">out</span><span style="color:black;"> item))<br />
        {<br />
            </span><span style="color:#2b91af;">CancelRoutedEventArgs</span><span style="color:black;"> cancelArgs = </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">CancelRoutedEventArgs</span><span style="color:black;">() { RoutedEvent = DeletingEvent, Source = element };<br />
            element.RaiseEvent(cancelArgs);<br />
            </span><span style="color:blue;">if</span><span style="color:black;"> (!cancelArgs.Cancel)<br />
                view.Remove(item);<br />
        }<br />
    }</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">bool</span><span style="color:black;"> GetIsReadOnly(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj)<br />
    {<br />
        </span><span style="color:blue;">return</span><span style="color:black;"> (</span><span style="color:blue;">bool</span><span style="color:black;">)obj.GetValue(IsReadOnlyProperty);<br />
    }<br />
    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> SetIsReadOnly(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> obj, </span><span style="color:blue;">bool</span><span style="color:black;"> value)<br />
    {<br />
        obj.SetValue(IsReadOnlyPropertyKey, value);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyPropertyKey</span><span style="color:black;"> IsReadOnlyPropertyKey =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;">.RegisterAttachedReadOnly(</span><span style="color:#a31515;">&#8220;IsReadOnly&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:blue;">bool</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">),<br />
        </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">FrameworkPropertyMetadata</span><span style="color:black;">(</span><span style="color:blue;">true</span><span style="color:black;">, </span><span style="color:#2b91af;">FrameworkPropertyMetadataOptions</span><span style="color:black;">.Inherits));<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:black;"> IsReadOnlyProperty = IsReadOnlyPropertyKey.DependencyProperty;</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;"> Edit = </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;">(</span><span style="color:#a31515;">&#8220;Edit&#8221;</span><span style="color:black;">, </span><span style="color:#a31515;">&#8220;Edit&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">));<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;"> Accept = </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;">(</span><span style="color:#a31515;">&#8220;Accept&#8221;</span><span style="color:black;">, </span><span style="color:#a31515;">&#8220;Accept&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">));<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;"> Cancel = </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;">(</span><span style="color:#a31515;">&#8220;Cancel&#8221;</span><span style="color:black;">, </span><span style="color:#a31515;">&#8220;Cancel&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">));<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;"> Delete = </span><span style="color:blue;">new</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedUICommand</span><span style="color:black;">(</span><span style="color:#a31515;">&#8220;Delete&#8221;</span><span style="color:black;">, </span><span style="color:#a31515;">&#8220;Delete&#8221;</span><span style="color:black;">, </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">));</p>
<p>    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> AddDeletingHandler(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> element, </span><span style="color:#2b91af;">CancelRoutedEventHandler</span><span style="color:black;"> handler)<br />
    {<br />
        ((</span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">)element).AddHandler(DeletingEvent, handler);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> RemoveDeletingHandler(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:black;"> element, </span><span style="color:#2b91af;">CancelRoutedEventHandler</span><span style="color:black;"> handler)<br />
    {<br />
        ((</span><span style="color:#2b91af;">FrameworkElement</span><span style="color:black;">)element).RemoveHandler(DeletingEvent, handler);<br />
    }<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">readonly</span><span style="color:black;"> </span><span style="color:#2b91af;">RoutedEvent</span><span style="color:black;"> DeletingEvent =<br />
        </span><span style="color:#2b91af;">EventManager</span><span style="color:black;">.RegisterRoutedEvent(</span><span style="color:#a31515;">&#8220;Deleting&#8221;</span><span style="color:black;">, </span><span style="color:#2b91af;">RoutingStrategy</span><span style="color:black;">.Bubble,<br />
            </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">CancelRoutedEventHandler</span><span style="color:black;">), </span><span style="color:blue;">typeof</span><span style="color:black;">(</span><span style="color:#2b91af;">DataEditing</span><span style="color:black;">));</p>
<p>    </span><span style="color:blue;">private</span><span style="color:black;"> </span><span style="color:blue;">static</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> Remove&lt;T&gt;(</span><span style="color:blue;">this</span><span style="color:black;"> System.Collections.</span><span style="color:#2b91af;">IList</span><span style="color:black;"> list, </span><span style="color:#2b91af;">Func</span><span style="color:black;">&lt;T, </span><span style="color:blue;">bool</span><span style="color:black;">&gt; predicate)<br />
    {<br />
        T item = list.OfType&lt;T&gt;().FirstOrDefault(predicate);<br />
        list.Remove(item);<br />
    }<br />
}</p>
<p></span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">delegate</span><span style="color:black;"> </span><span style="color:blue;">void</span><span style="color:black;"> </span><span style="color:#2b91af;">CancelRoutedEventHandler</span><span style="color:black;">(</span><span style="color:blue;">object</span><span style="color:black;"> sender, </span><span style="color:#2b91af;">CancelRoutedEventArgs</span><span style="color:black;"> e);</p>
<p></span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">class</span><span style="color:black;"> </span><span style="color:#2b91af;">CancelRoutedEventArgs</span><span style="color:black;"> : </span><span style="color:#2b91af;">RoutedEventArgs<br />
</span><span style="color:black;">{<br />
    </span><span style="color:blue;">public</span><span style="color:black;"> </span><span style="color:blue;">bool</span><span style="color:black;"> Cancel{</span><span style="color:blue;">get</span><span style="color:black;">; </span><span style="color:blue;">set</span><span style="color:black;">;}<br />
}</span></div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/softnotes.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/softnotes.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=15&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2008/08/20/validation-in-wpf-with-net-35-sp1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>Connection pooling is good</title>
		<link>http://softnotes.wordpress.com/2008/08/09/connection-pooling-is-good/</link>
		<comments>http://softnotes.wordpress.com/2008/08/09/connection-pooling-is-good/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 17:45:01 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=13</guid>
		<description><![CDATA[I was writing a project which involved accessing user instances of a SQL Server database from two separate processes in turn. This failed with &#8220;Login failed&#8221; error messages. Connection pooling meant that the process which attached the database first did not close its connection even after its use of the database was over. A simple [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=13&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was writing a project which involved accessing user instances of a SQL Server database from two separate processes in turn. This failed with &#8220;Login failed&#8221; error messages. Connection pooling meant that the process which attached the database first did not close its connection even after its use of the database was over. A simple solution seemed to be to disable connection pooling on both processes. This worked in the sense that there were no exceptions. But performance took a huge hit. Finally I changed the design so that all the work was done in a single process. I could afford to do it since there was not much code involved. This is something to keep in mind when using user instances in SQL Server. <em>Disabling connection pooling is an unacceptable solution.</em></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/softnotes.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/softnotes.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=13&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2008/08/09/connection-pooling-is-good/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>Routed Events in WPF</title>
		<link>http://softnotes.wordpress.com/2008/08/09/routed-events-in-wpf/</link>
		<comments>http://softnotes.wordpress.com/2008/08/09/routed-events-in-wpf/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 16:41:17 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=10</guid>
		<description><![CDATA[Unlike the concept of dependency properties, the concept of routed events is a little difficult to understand. It is clear what purposes dependency properties serve. But routed events? Why would anyone want events to route up or down the element tree? There is a common example given of a Panel with multiple Buttons in it where [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=10&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Unlike the concept of dependency properties, the concept of routed events is a little difficult to understand. It is clear what purposes dependency properties serve. But routed events? Why would anyone want events to route up or down the element tree? There is a common example given of a <code>Panel</code> with multiple <code>Button</code>s in it where one can attach an event handler for <code>Button.Click</code> on the <code>Panel</code> instead of on the <code>Button</code>s and have it called when any <code>Button</code> is clicked. But that does not seem to be a good enough reason to architect an entire feature. And indeed it is not. Event routing becomes much more useful in the context of commands and control templating. It would be much more difficult to write controls like the <code>ScrollBar</code> or the <code>Slider</code> without routed commands (which work via routed events) while allowing them to be easily templatable. The real purpose of routed events is not to attach handlers on some node of a static tree of elements to handle events on the children. It is to enable parent elements to define behavior when a particular event occurs on a child element that it does not statically know of.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/softnotes.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/softnotes.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=10&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2008/08/09/routed-events-in-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
		<item>
		<title>Checkboxes in WPF TreeView</title>
		<link>http://softnotes.wordpress.com/2008/08/03/checkboxes-in-wpf-treeview/</link>
		<comments>http://softnotes.wordpress.com/2008/08/03/checkboxes-in-wpf-treeview/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 11:41:26 +0000</pubDate>
		<dc:creator>K. M.</dc:creator>
				<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://softnotes.wordpress.com/?p=5</guid>
		<description><![CDATA[Josh Smith recently posted an interesting article on CodeProject about using CheckBoxes in a WPF TreeView. &#8220;The fundamental problem is that as you navigate the tree via arrow keys, a TreeViewItem will first take input focus, and then the CheckBox it contains will take focus upon the next keystroke. Both the TreeViewItem and CheckBox controls [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=5&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://joshsmithonwpf.wordpress.com/" target="_blank">Josh Smith</a> recently posted an <a href="http://www.codeproject.com/KB/WPF/TreeViewWithCheckBoxes.aspx" target="_blank">interesting article</a> on CodeProject about using CheckBoxes in a WPF TreeView.</p>
<p><em>&#8220;The fundamental problem is that as you navigate the tree via arrow keys, a <code>TreeViewItem</code> will first take input focus, and then the <code>CheckBox</code> it contains will take focus upon the next keystroke. Both the <code>TreeViewItem</code> and <code>CheckBox</code> controls are focusable. The result is that you must press an arrow key twice to navigate from item to item in the tree.&#8221;</em></p>
<p>His solution is to set <code>Focusable</code> to false on the <code>CheckBox</code> and make the <code>TreeViewItem</code> a &#8220;virtual <code>ToggleButton</code>&#8221; by applying attached properties.</p>
<p>Since the problem has to do with focus, it can also be solved by setting focus on the <code>CheckBox</code> when the <code>TreeViewItem</code> receives focus. The class shown below defines an attached property &#8211; <code>FocusedChildName</code> &#8211; that sets focus on a named element in the visual tree of the target element. Adding a <code>Setter</code> to the <code>Style</code> for the <code>TreeViewItem</code></p>
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Setter</span><span style="color:#ff0000;"> Property</span><span style="color:#0000ff;">=&#8221;local:FocusHelper.FocusedChildName&#8221;</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">=&#8221;checkbox&#8221;/&gt;</span></div>
<p>and setting up a binding on the Focusable property of the <code>CheckBox</code></p>
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">CheckBox</span><span style="color:#ff0000;"> x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&#8221;checkbox&#8221;<br />
</span><span style="color:#ff0000;">    Focusable</span><span style="color:#0000ff;">=&#8221;{</span><span style="color:#a31515;">Binding</span><span style="color:#ff0000;"> RelativeSource</span><span style="color:#0000ff;">={</span><span style="color:#a31515;">RelativeSource</span><span style="color:#ff0000;"> FindAncestor</span><span style="color:#0000ff;">,</span><span style="color:#ff0000;"> AncestorType</span><span style="color:#0000ff;">={</span><span style="color:#a31515;">x</span><span style="color:#0000ff;">:</span><span style="color:#a31515;">Type</span><span style="color:#ff0000;"> TreeViewItem</span><span style="color:#0000ff;">}},</span><span style="color:#ff0000;"> Path</span><span style="color:#0000ff;">=IsSelected}&#8221;</span></div>
<p>produces the desired behavior</p>
<div style="font-size:10pt;font-family:Monospace;background-color:white;"><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#0000ff;">class</span><span style="color:#000000;"> </span><span style="color:#2b91af;">FocusHelper<br />
</span><span style="color:#000000;">{<br />
    </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> GetFocusedChildName(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:#000000;"> obj)<br />
    {<br />
        </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">string</span><span style="color:#000000;">)obj.GetValue(FocusedChildNameProperty);<br />
    }</p>
<p>    </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> SetFocusedChildName(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:#000000;"> obj, </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> value)<br />
    {<br />
        obj.SetValue(FocusedChildNameProperty, value);<br />
    }<br />
    </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#0000ff;">readonly</span><span style="color:#000000;"> </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:#000000;"> FocusedChildNameProperty =<br />
        </span><span style="color:#2b91af;">DependencyProperty</span><span style="color:#000000;">.RegisterAttached(</span><span style="color:#a31515;">&#8220;FocusedChildName&#8221;</span><span style="color:#000000;">, </span><span style="color:#0000ff;">typeof</span><span style="color:#000000;">(</span><span style="color:#0000ff;">string</span><span style="color:#000000;">), </span><span style="color:#0000ff;">typeof</span><span style="color:#000000;">(</span><span style="color:#2b91af;">FocusHelper</span><span style="color:#000000;">),<br />
            </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">UIPropertyMetadata</span><span style="color:#000000;">(FocusedChildName_PropertyChanged));</p>
<p>    </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> FocusedChildName_PropertyChanged(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:#000000;"> d, </span><span style="color:#2b91af;">DependencyPropertyChangedEventArgs</span><span style="color:#000000;"> e)<br />
    {<br />
        </span><span style="color:#2b91af;">UIElement</span><span style="color:#000000;"> element = d </span><span style="color:#0000ff;">as</span><span style="color:#000000;"> </span><span style="color:#2b91af;">UIElement</span><span style="color:#000000;">;<br />
        </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (element != </span><span style="color:#0000ff;">null</span><span style="color:#000000;"> &amp;&amp; !</span><span style="color:#0000ff;">string</span><span style="color:#000000;">.IsNullOrEmpty((</span><span style="color:#0000ff;">string</span><span style="color:#000000;">)e.NewValue))<br />
            element.GotKeyboardFocus += element_GotKeyboardFocus;<br />
        </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (element != </span><span style="color:#0000ff;">null</span><span style="color:#000000;"> &amp;&amp; </span><span style="color:#0000ff;">string</span><span style="color:#000000;">.IsNullOrEmpty((</span><span style="color:#0000ff;">string</span><span style="color:#000000;">)e.NewValue))<br />
            element.GotKeyboardFocus -= element_GotKeyboardFocus;<br />
    }</p>
<p>    </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> element_GotKeyboardFocus(</span><span style="color:#0000ff;">object</span><span style="color:#000000;"> sender, </span><span style="color:#2b91af;">KeyboardFocusChangedEventArgs</span><span style="color:#000000;"> e)<br />
    {<br />
        </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (e.OriginalSource == sender)<br />
        {<br />
            (sender </span><span style="color:#0000ff;">as</span><span style="color:#000000;"> </span><span style="color:#2b91af;">DispatcherObject</span><span style="color:#000000;">).Dispatcher.BeginInvoke(</span><span style="color:#2b91af;">DispatcherPriority</span><span style="color:#000000;">.Input,<br />
                </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">Action</span><span style="color:#000000;">(() =&gt;<br />
                {<br />
                    </span><span style="color:#2b91af;">DependencyObject</span><span style="color:#000000;"> obj = sender </span><span style="color:#0000ff;">as</span><span style="color:#000000;"> </span><span style="color:#2b91af;">DependencyObject</span><span style="color:#000000;">;<br />
                    </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> name = (</span><span style="color:#0000ff;">string</span><span style="color:#000000;">)obj.GetValue(</span><span style="color:#2b91af;">FocusHelper</span><span style="color:#000000;">.FocusedChildNameProperty);<br />
                    </span><span style="color:#2b91af;">IInputElement</span><span style="color:#000000;"> element = FindNamedElementInVisualTree(obj, name) </span><span style="color:#0000ff;">as</span><span style="color:#000000;"> </span><span style="color:#2b91af;">IInputElement</span><span style="color:#000000;">;<br />
                    </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (element != </span><span style="color:#0000ff;">null</span><span style="color:#000000;">)<br />
                        element.Focus();<br />
                }));<br />
        }<br />
    }</p>
<p>    </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#2b91af;">DependencyObject</span><span style="color:#000000;"> FindNamedElementInVisualTree(</span><span style="color:#2b91af;">DependencyObject</span><span style="color:#000000;"> parent, </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> name)<br />
    {<br />
        </span><span style="color:#0000ff;">int</span><span style="color:#000000;"> count = </span><span style="color:#2b91af;">VisualTreeHelper</span><span style="color:#000000;">.GetChildrenCount(parent);<br />
        </span><span style="color:#0000ff;">for</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">int</span><span style="color:#000000;"> i = 0; i &lt; count; i++)<br />
        {<br />
            </span><span style="color:#2b91af;">DependencyObject</span><span style="color:#000000;"> child = </span><span style="color:#2b91af;">VisualTreeHelper</span><span style="color:#000000;">.GetChild(parent, i);<br />
            </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> ((</span><span style="color:#0000ff;">string</span><span style="color:#000000;">)child.GetValue(</span><span style="color:#2b91af;">FrameworkElement</span><span style="color:#000000;">.NameProperty) == name) </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> child;<br />
            child = FindNamedElementInVisualTree(child, name);<br />
            </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (child != </span><span style="color:#0000ff;">null</span><span style="color:#000000;">) </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> child;<br />
        }<br />
        </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">null</span><span style="color:#000000;">;<br />
    }<br />
}</span></div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/softnotes.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/softnotes.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/softnotes.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/softnotes.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/softnotes.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/softnotes.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/softnotes.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/softnotes.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/softnotes.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/softnotes.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/softnotes.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/softnotes.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/softnotes.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/softnotes.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/softnotes.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/softnotes.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=softnotes.wordpress.com&amp;blog=4402517&amp;post=5&amp;subd=softnotes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://softnotes.wordpress.com/2008/08/03/checkboxes-in-wpf-treeview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">K. M.</media:title>
		</media:content>
	</item>
	</channel>
</rss>
