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

<channel>
	<title>CheckPointe Development &#187; WPF</title>
	<atom:link href="http://chkpointedev.com/category/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://chkpointedev.com</link>
	<description>Optimizing Automation Through .NET</description>
	<lastBuildDate>Thu, 20 Jan 2011 18:04:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>WPF Tidbits</title>
		<link>http://chkpointedev.com/2009/10/wpf-tidbits/</link>
		<comments>http://chkpointedev.com/2009/10/wpf-tidbits/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 22:03:27 +0000</pubDate>
		<dc:creator>Al Alberto</dc:creator>
				<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://chkpointedev.com/?p=204</guid>
		<description><![CDATA[Here&#8217;s a couple of &#8216;how do you that in wpf?&#8217; that may save you an hour or two. There&#8217;s nothing particularly astounding in any of them but implementation is different enough from the WinForm counterparts that it may not be intuitive enough. Modal Dialog There is no option for a dialog from the &#8216;Add&#8230; New [...]]]></description>
			<content:encoded><![CDATA[<p>Here&rsquo;s a couple of &lsquo;how do you that in wpf?&rsquo; that may save you an hour or two. There&rsquo;s nothing particularly astounding in any of them but implementation is different enough from the WinForm counterparts that it may not be intuitive enough.</p>
<h2>Modal Dialog</h2>
<div style="margin: 0in 0in 10pt">There is no option for a dialog from the &lsquo;Add&hellip; New Item&rsquo; using the solution explorer in Visual Studio. Instead you have to remember that a dialog is nothing more than a window. And there is an option for &lsquo;Window(WPF)&rsquo;. You create a dialog the same way you would create a User Control and then invoke it as was done under WinForm, using the <i>ShowDialog</i> method.</div>
<div style="margin: 0in 0in 10pt">The sample code (found in the downloads page) provides a handler for the <b>OK </b>button and you can set the <i>&lsquo;IsCancel&rsquo;</i> property for the <b>Cancel</b> button so that no handler is required. The only other thing to note is that there is no equivalence to <i>DialogResult</i> that was used in WinForms. There is a DialogResult parameter but it is not the same. Here, the DialogResult is a nullable bool parameter which essentially translates to OK or Cancel from the dialog. Of course you can implement your own custom version of DialogResult by using a property if you needed to .</div>
<p style="text-align: left"><img alt="wpfdialog" height="303" src="http://chkpointedev.com/wp-content/uploads/wpfdialog.PNG" width="304" /></p>
<p style="text-align: left">&nbsp;</p>
<div style="margin: 0in 0in 10pt">The sample project provides all the details you&rsquo;ll need but here is the XAML for the dialog.</div>
<pre><code>&nbsp;</code><code><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Window</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Class</span><span style="color: blue; font-size: 10pt">=&quot;WpfDialogTestApp.WpfDialog&quot;</span></code>
<code><span style="font-size: 10pt">&nbsp;&nbsp; <span style="color: red">&nbsp;xmlns</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span></code>
<code><span style="font-size: 10pt">&nbsp;&nbsp; <span style="color: red">&nbsp;xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span></code>
<code><span style="font-size: 10pt">&nbsp;&nbsp; <span style="color: red">&nbsp;Title</span><span style="color: blue">=&quot;Wpf Dialog&quot;</span><span style="color: red"> Height</span><span style="color: blue">=&quot;103&quot;</span><span style="color: red"> Width</span><span style="color: blue">=&quot;257&quot;&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid.RowDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: red; font-size: 10pt"> Height</span><span style="color: blue; font-size: 10pt">=&quot;30&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid.RowDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid.ColumnDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid.ColumnDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: red; font-size: 10pt"> VerticalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;&gt;</span><span style="color: #a31515; font-size: 10pt">Enter#</span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">TextBox</span><span style="color: red; font-size: 10pt"> Name</span><span style="color: blue; font-size: 10pt">=&quot;textNumber&quot;</span><span style="color: red; font-size: 10pt"> Grid.Column</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">TextBox</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Button</span><span style="color: red; font-size: 10pt"> Grid.Row</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> Name</span><span style="color: blue; font-size: 10pt">=&quot;buttonOK&quot;</span><span style="color: red; font-size: 10pt"> Click</span><span style="color: blue; font-size: 10pt">=&quot;buttonOK_Click&quot;&gt;</span><span style="color: #a31515; font-size: 10pt">OK</span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Button</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Button</span><span style="color: red; font-size: 10pt"> Grid.Column</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> Grid.Row</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> IsCancel</span><span style="color: blue; font-size: 10pt">=&quot;True&quot;&gt;</span><span style="color: #a31515; font-size: 10pt">Cancel</span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Button</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="line-height: 115%; color: blue; font-size: 10pt">&lt;/</span><span style="line-height: 115%; color: #a31515; font-size: 10pt">Window</span><span style="line-height: 115%; color: blue; font-size: 10pt">&gt;</span></code>&nbsp;</pre>
<h2>&nbsp;Horizontal Listbox</h2>
<div style="margin: 0in 0in 10pt">It may not be the usual case but sometimes it will be just what&rsquo;s required. It may simply be that the layout is more pleasing displaying the items horizontally or that what you are trying to display is more intuitive if it were laid out horizontally. Well at least that was the case for me. So here it is.</div>
<div style="margin: 0in 0in 10pt">There is nothing magical, the magic is already built in to WPF and the fact that each item in a listbox can be a custom User Control. &nbsp;Obviously the requirements will dictate if it&rsquo;s appropriate, but I can see a lot of opportunities if we look at things from a different angle.</div>
<div style="margin: 0in 0in 10pt">The sample project provides all the source code for the implementation. The code is also implemented following the MVVM pattern which fits the bill very nicely. Each listbox item could very easily be self contained, initializing itself and responding to user actions. The sample project utilizes event delegates for communication but a looser approach would be to use an event aggregator as provided with CAL.</div>
<p style="text-align: left"><img alt="" height="115" src="http://chkpointedev.com/wp-content/uploads/HorzListbox.PNG" width="627" /></p>
<pre><code><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">UserControl</span>
<span style="font-size: 10pt"><span style="color: red">    xmlns</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span style="font-size: 10pt">   <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">v</span><span style="color: blue">=&quot;clr-namespace:HorzListboxTestApp.Views&quot;</span></span>
<span style="font-size: 10pt">   <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span style="font-size: 10pt">   <span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;HorzListboxTestApp.Views.MainWindowView&quot;</span></span>
<span style="font-size: 10pt">&nbsp;&nbsp; <span style="color: red">&nbsp;MinHeight</span><span style="color: blue">=&quot;70&quot;</span><span style="color: red"> MinWidth</span><span style="color: blue">=&quot;300&quot;&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">UserControl.Resources</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: red; font-size: 10pt"> TargetType</span><span style="color: blue; font-size: 10pt">=&quot;ListBox&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;ItemsPanel&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter.Value</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ItemsPanelTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">StackPanel</span><span style="color: red; font-size: 10pt"> Orientation</span><span style="color: blue; font-size: 10pt">=&quot;Horizontal&quot;</span></code>
<code><span style="font-size: 10pt">                         <span style="color: red"> VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;</span></span></code>
<code><span style="font-size: 10pt">                         <span style="color: red"> HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">ItemsPanelTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Setter.Value</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: red; font-size: 10pt"> TargetType</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">Type</span><span style="color: red; font-size: 10pt"> ListBoxItem</span><span style="color: blue; font-size: 10pt">}&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;HorizontalContentAlignment&quot;</span><span style="color: red; font-size: 10pt"> Value</span><span style="color: blue; font-size: 10pt">=&quot;Stretch&quot; /&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;ContentTemplate&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter.Value</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Border</span><span style="color: red; font-size: 10pt"> BorderThickness</span><span style="color: blue; font-size: 10pt">=&quot;2&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">StackPanel</span><span style="color: red; font-size: 10pt"> HorizontalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> VerticalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">v</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">LBItemView</span><span style="color: blue; font-size: 10pt">/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">StackPanel</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Border</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Setter.Value</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">UserControl.Resources</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid.RowDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid.RowDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid.ColumnDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: red; font-size: 10pt"> Width</span><span style="color: blue; font-size: 10pt">=&quot;80&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid.ColumnDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ListBox</span><span style="color: red; font-size: 10pt"> Grid.Column</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> Grid.RowSpan</span><span style="color: blue; font-size: 10pt">=&quot;2&quot;</span><span style="color: red; font-size: 10pt"> ItemsSource</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=Items}&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">ListBox</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Label</span><span style="color: red; font-size: 10pt"> Background</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> ContentBrush</span><span style="color: blue; font-size: 10pt">}&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">Label</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: red; font-size: 10pt"> Grid.Row</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> VerticalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> HorizontalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> Text</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=SelectedItem}&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid</span><span style="color: blue; font-size: 10pt">&gt;</span></code></pre>
<h2>&nbsp;MVVM Context Menu</h2>
<p style="text-align: left"><img alt="" height="113" src="http://chkpointedev.com/wp-content/uploads/ContextMenu.PNG" width="628" /></p>
<p style="text-align: left">&nbsp;</p>
<div style="margin: 0in 0in 10pt">As you can see, the listbox can provide a lot information to the user in a very compact format. The key of course is that each item is itself an independent control. Suppose in the above example we had placed a combo box to the left of the listbox and allowed the user to select categories of colors. We would have multiplied the amount of information without losing usability.</div>
<div style="margin: 0in 0in 10pt">As mentioned above, whatever the listbox item represents, its logic is contained within the control and the code does not become more convoluted with the number of items. Let&rsquo;s take that two steps further.</div>
<div style="margin: 0in 0in 10pt">In this sample project we&rsquo;re using the same project from the previous section and adding two features to it. One is a simple tooltip and the other is a dynamically generated context menu, again, following the MVVM pattern. Here&rsquo;s the XAML for the listbox item.</div>
<pre><code> <span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">UserControl</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Class</span><span style="color: blue; font-size: 10pt">=&quot;HorzListboxTestApp.Views.LBItemView&quot;</span></code>
<code><span style="font-size: 10pt">   <span style="color: red"> xmlns</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span></code>
<code><span style="font-size: 10pt">   <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span></code>
<code><span style="font-size: 10pt">   <span style="color: red"> Height</span><span style="color: blue">=&quot;50&quot;</span><span style="color: red"> Width</span><span style="color: blue">=&quot;40&quot;&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">UserControl.Resources</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Key</span><span style="color: blue; font-size: 10pt">=&quot;buttonWithTip&quot;</span><span style="color: red; font-size: 10pt"> TargetType</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">Type</span><span style="color: red; font-size: 10pt"> Button</span><span style="color: blue; font-size: 10pt">}&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Style.Triggers</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Trigger</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;IsMouseOver&quot;</span><span style="color: red; font-size: 10pt"> Value</span><span style="color: blue; font-size: 10pt">=&quot;true&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;ToolTip&quot;</span></code>
<code><span style="font-size: 10pt">               <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">=GetTip}&quot;/&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Trigger</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Style.Triggers</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Key</span><span style="color: blue; font-size: 10pt">=&quot;ContextMenuItemStyle&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;MenuItem.Header&quot;</span><span style="color: red; font-size: 10pt"> Value</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=OptionText}&quot;/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;MenuItem.Command&quot;</span><span style="color: red; font-size: 10pt"> Value</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=OptionCommand}&quot; /&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">UserControl.Resources</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid.RowDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: red; font-size: 10pt"> Height</span><span style="color: blue; font-size: 10pt">=&quot;*&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: red; font-size: 10pt"> Height</span><span style="color: blue; font-size: 10pt">=&quot;20&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">RowDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid.RowDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid.ColumnDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">ColumnDefinition</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid.ColumnDefinitions</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Button</span><span style="color: red; font-size: 10pt"> Background</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> ContentBrush</span><span style="color: blue; font-size: 10pt">}&quot;</span><span style="color: red; font-size: 10pt"> Grid.ColumnSpan</span><span style="color: blue; font-size: 10pt">=&quot;2&quot;</span><span style="color: red; font-size: 10pt"> Command</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=SelectedCommand}&quot;</span><span style="color: red; font-size: 10pt"> Style</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">StaticResource</span><span style="color: red; font-size: 10pt"> buttonWithTip</span><span style="color: blue; font-size: 10pt">}&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Button.ContextMenu</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ContextMenu</span><span style="color: red; font-size: 10pt"> ItemContainerStyle</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">StaticResource</span><span style="color: red; font-size: 10pt"> ContextMenuItemStyle</span><span style="color: blue; font-size: 10pt">}&quot;</span><span style="color: red; font-size: 10pt"> ItemsSource</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=MenuOptions}&quot; /&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Button.ContextMenu</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Button</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: red; font-size: 10pt"> Grid.Row</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> VerticalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> HorizontalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> Text</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> ItemNumber</span><span style="color: blue; font-size: 10pt">}&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">CheckBox</span><span style="color: red; font-size: 10pt"> Grid.Column</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> Grid.Row</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> VerticalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> HorizontalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> IsChecked</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=ItemChecked,</span><span style="color: red; font-size: 10pt"> Mode</span><span style="color: blue; font-size: 10pt">=TwoWay}&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">CheckBox</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="line-height: 115%; color: blue; font-size: 10pt">&lt;/</span><span style="line-height: 115%; color: #a31515; font-size: 10pt">UserControl</span><span style="line-height: 115%; color: blue; font-size: 10pt">&gt;</span></code></pre>
<p>Two points will provide all the clarity we need. ContextMenu has an <i>ItemsSource</i>&nbsp;same as a listbox so we can bind to it and provide the list of items to display. The more important part is the whole point of the context menu, to provide the user with a mechanism to make a selection. So we need a way to identify which item the user selected.&nbsp;Well, if we use the same approach we used for the listbox then we can let each menu item be independent on to itself. In other words, provide&nbsp;a ViewModel for each context menu item. To provide the binding all that&rsquo;s needed is to define a style for the menu item. The style simply defines where the text for the menu item comes from and how to bind the command that will be executed when a user selects the item. The code above shows how both of these were implemented and the support class is shown below.</p>
<pre> <code> <span style="font-size: 10pt">    <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">MenuOptionItem</span></span></code>
<code><span style="font-size: 10pt">    {</span></code>
<code><span style="font-size: 10pt">        <span style="color: blue">public</span> <span style="color: blue">string</span> OptionText { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</span></code>
<code><span style="font-size: 10pt">        <span style="color: blue">public</span> <span style="color: #2b91af">ICommand</span> OptionCommand { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</span></code>
<code><span style="font-size: 10pt">        <span style="color: blue">public</span> MenuOptionItem(<span style="color: blue">string</span> optionText)</span></code>
<code><span style="font-size: 10pt">        {</span></code>
<code><span style="font-size: 10pt">            <span style="color: blue">this</span>.OptionText = optionText;</span></code>
<code><span style="font-size: 10pt">            OptionCommand = <span style="color: blue">new</span> <span style="color: #2b91af">DelegateCommand</span>(OptionSelected);</span></code>
<code><span style="font-size: 10pt">        }</span></code>
<code><span style="font-size: 10pt">        <span style="color: blue">public</span> <span style="color: blue">void</span> OptionSelected()</span></code>
<code><span style="font-size: 10pt">        {</span></code>
<code><span style="font-size: 10pt">            <span style="color: #2b91af">MessageBox</span>.Show(<span style="color: #a31515">&quot;You selected:&quot;</span> + OptionText);</span></code>
<code><span style="font-size: 10pt">        }
</span></code><code><span style="font-size: 10pt">    }</span></code></pre>
<p>The sample project also shows how you can dynamically create context menus based on the state of the item.</p>
<h2>Sortable/Checkable ListView</h2>
<div style="margin: 0in 0in 10pt">There are two things that I think would be common requirements for a ListView. One is to be able to sort the items based on one or more columns. And the other is to be able to &lsquo;check&rsquo; an item like the CkeckedListbox. Neither of these are provided in the WPF ListView control. Adding a checkbox was pretty simple, sorting was a different story.</div>
<div style="margin: 0in 0in 10pt">&nbsp;Joel&nbsp;Rumerman wrote a nice article <a href="http://blogs.interknowlogy.com/joelrumerman/archive/2007/04/03/12497.aspx"><font color="#800080">here</font></a>&nbsp;and I found an implementation which fit nicely in the <a href="http://www.codeplex.com/AvalonControlsLib">AvalonControlsLibrary</a> in CodePlex. You can find supporting information there.</div>
<p style="text-align: center"><img alt="" height="207" src="http://chkpointedev.com/wp-content/uploads/ListView.PNG" width="370" /></p>
<pre> <code><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">UserControl</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Class</span><span style="color: blue; font-size: 10pt">=&quot;ListViewTestApp.Views.MainWindowView&quot;</span></code>
<code><span style="font-size: 10pt">   <span style="color: red"> xmlns</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span></code>
<code><span style="font-size: 10pt">   <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">c</span><span style="color: blue">=&quot;clr-namespace:ListViewTestApp.Common&quot;</span></span></code>
<code><span style="font-size: 10pt">   <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span></code>
<code><span style="font-size: 10pt">   <span style="color: red"> Height</span><span style="color: blue">=&quot;200&quot;</span><span style="color: red"> Width</span><span style="color: blue">=&quot;350&quot;&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Control.Resources</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Key</span><span style="color: blue; font-size: 10pt">=&quot;HeaderTemplateArrowUp&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">DockPanel</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: red; font-size: 10pt"> HorizontalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> Text</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: blue; font-size: 10pt">}&quot;/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">               </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Path</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Name</span><span style="color: blue; font-size: 10pt">=&quot;arrow&quot;</span><span style="color: red; font-size: 10pt"> StrokeThickness</span><span style="color: blue; font-size: 10pt"> = &quot;1&quot;</span><span style="color: red; font-size: 10pt"> Fill</span><span style="color: blue; font-size: 10pt"> = &quot;Gray&quot;</span><span style="color: red; font-size: 10pt"> Data</span><span style="color: blue; font-size: 10pt"> = &quot;M 5,10 L 15,10 L 10,5 L 5,10&quot;/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">DockPanel</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Key</span><span style="color: blue; font-size: 10pt">=&quot;HeaderTemplateArrowDown&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">DockPanel</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: red; font-size: 10pt"> HorizontalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> Text</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: blue; font-size: 10pt">}&quot;/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Path</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Name</span><span style="color: blue; font-size: 10pt">=&quot;arrow&quot;</span><span style="color: red; font-size: 10pt"> StrokeThickness</span><span style="color: blue; font-size: 10pt"> = &quot;1&quot;</span><span style="color: red; font-size: 10pt"> Fill</span><span style="color: blue; font-size: 10pt"> = &quot;Gray&quot;</span><span style="color: red; font-size: 10pt"> Data</span><span style="color: blue; font-size: 10pt">=&quot;M 5,5 L 10,10 L 15,5 L 5,5&quot;/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">DockPanel</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Key</span><span style="color: blue; font-size: 10pt">=&quot;HeaderTemplateTransparent&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">DockPanel</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">TextBlock</span><span style="color: red; font-size: 10pt"> HorizontalAlignment</span><span style="color: blue; font-size: 10pt">=&quot;Center&quot;</span><span style="color: red; font-size: 10pt"> Text</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: blue; font-size: 10pt">}&quot;/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Path</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Name</span><span style="color: blue; font-size: 10pt">=&quot;arrow&quot;</span><span style="color: red; font-size: 10pt"> StrokeThickness</span><span style="color: blue; font-size: 10pt">=&quot;1&quot;</span><span style="color: red; font-size: 10pt"> Fill</span><span style="color: blue; font-size: 10pt">=&quot;Transparent&quot;</span><span style="color: red; font-size: 10pt"> Data</span><span style="color: blue; font-size: 10pt">=&quot;M 5,5 L 10,10 L 15,5 L 5,5&quot;/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">DockPanel</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code><code> </code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: green; font-size: 10pt">&lt;!--Sort handler that sorts the columns--&gt;
</span></code><code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">c</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">GridViewSortHandler</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Key</span><span style="color: blue; font-size: 10pt">=&quot;sortHandler&quot;</span></code>
<code><span style="font-size: 10pt">                                 <span style="color: red"> ColumnHeaderSortedAscendingTemplate</span><span style="color: blue">=&quot;HeaderTemplateArrowUp&quot;</span></span></code>
<code><span style="font-size: 10pt">                                 <span style="color: red"> ColumnHeaderSortedDescendingTemplate</span><span style="color: blue">=&quot;HeaderTemplateArrowDown&quot;</span></span></code>
<code><span style="font-size: 10pt">                                 <span style="color: red"> ColumnHeaderNotSortedTemplate</span><span style="color: blue">=&quot;HeaderTemplateTransparent&quot; /&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: red; font-size: 10pt"> x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">Key</span><span style="color: blue; font-size: 10pt">=&quot;OrderItemStyle&quot;</span><span style="color: red; font-size: 10pt"> TargetType</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">x</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">Type</span><span style="color: red; font-size: 10pt"> ListViewItem</span><span style="color: blue; font-size: 10pt">}&quot;&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;HorizontalContentAlignment&quot;</span><span style="color: red; font-size: 10pt"> Value</span><span style="color: blue; font-size: 10pt">=&quot;Stretch&quot; /&gt;</span></code><code><span style="color: #a31515; font-size: 10pt">
           </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Setter</span><span style="color: red; font-size: 10pt"> Property</span><span style="color: blue; font-size: 10pt">=&quot;IsSelected&quot;</span><span style="color: red; font-size: 10pt"> Value</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=IsSelected,</span><span style="color: red; font-size: 10pt"> Mode</span><span style="color: blue; font-size: 10pt">=TwoWay}&quot; /&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Style</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Control.Resources</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">Grid</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ListView</span><span style="color: red; font-size: 10pt"> c</span><span style="color: blue; font-size: 10pt">:</span><span style="color: red; font-size: 10pt">GridViewSortHandler.GridViewSortHandler</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">StaticResource</span><span style="color: red; font-size: 10pt"> sortHandler</span><span style="color: blue; font-size: 10pt">}&quot;</span><span style="color: red; font-size: 10pt"> Name</span><span style="color: blue; font-size: 10pt">=&quot;listOrders&quot;</span><span style="color: red; font-size: 10pt"> Width</span><span style="color: blue; font-size: 10pt">=&quot;Auto&quot;</span></code>
<code><span style="font-size: 10pt">                <span style="color: red"> ItemContainerStyle</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource</span><span style="color: red"> OrderItemStyle</span><span style="color: blue">}&quot;</span></span></code><code><span style="font-size: 10pt">
             <span style="color: red"> ItemsSource</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding</span><span style="color: red"> Path</span><span style="color: blue">=OrderItems}&quot;&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">ListView.View</span><span style="color: blue; font-size: 10pt">&gt;</span></code><code><span style="color: #a31515; font-size: 10pt">
               </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">GridView</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                    </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">GridViewColumn</span><span style="color: red; font-size: 10pt"> Width</span><span style="color: blue; font-size: 10pt">=&quot;30&quot;&gt;</span></code><code><span style="color: #a31515; font-size: 10pt">
                      </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">GridViewColumn.CellTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                            </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: blue; font-size: 10pt">&gt;
</span></code><code><span style="color: #a31515; font-size: 10pt">                                </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">CheckBox</span><span style="color: red; font-size: 10pt"> IsEnabled</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=CheckEnabled}&quot;</span><span style="color: red; font-size: 10pt"> IsChecked</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=ItemChecked}&quot;&gt;&lt;/</span><span style="color: #a31515; font-size: 10pt">CheckBox</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">DataTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code><code><span style="color: #a31515; font-size: 10pt">
                       </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">GridViewColumn.CellTemplate</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">GridViewColumn</span><span style="color: blue; font-size: 10pt">&gt;</span></code><code><span style="color: #a31515; font-size: 10pt">
                   </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">c</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">SortableGridViewColumn</span><span style="font-size: 10pt"> <span style="color: red"> Width</span><span style="color: blue">=&quot;100&quot;</span> <span style="color: red">&nbsp;Header</span><span style="color: blue">=&quot;Date&quot;</span><span style="color: red"> SortPropertyName</span><span style="color: blue">=&quot;OrderDate&quot;</span> <span style="color: red">&nbsp;DisplayMemberBinding</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding</span><span style="color: red"> Path</span><span style="color: blue">=OrderDate}&quot; /&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">                   </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">c</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">SortableGridViewColumn</span><span style="color: red; font-size: 10pt"> Width</span><span style="color: blue; font-size: 10pt">=&quot;50&quot;</span><span style="font-size: 10pt"> <span style="color: red">&nbsp;Header</span><span style="color: blue">=&quot;Order#&quot;</span><span style="color: red"> SortPropertyName</span><span style="color: blue">=&quot;OrderNumber&quot;</span><span style="color: red"> DisplayMemberBinding</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding</span><span style="color: red"> Path</span><span style="color: blue">=OrderNumber}&quot; /&gt;</span></span></code>
<code><span style="color: #a31515; font-size: 10pt">                   </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">c</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">SortableGridViewColumn</span><span style="color: red; font-size: 10pt"> Width</span><span style="color: blue; font-size: 10pt">=&quot;50&quot;</span><span style="color: red; font-size: 10pt"> Header</span><span style="color: blue; font-size: 10pt">=&quot;Item&quot;</span><span style="color: red; font-size: 10pt"> SortPropertyName</span><span style="color: blue; font-size: 10pt">=&quot;ItemSKU&quot;</span><span style="color: red; font-size: 10pt"> DisplayMemberBinding</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=ItemSKU}&quot; /&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                   </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">c</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">SortableGridViewColumn</span><span style="color: red; font-size: 10pt"> Width</span><span style="color: blue; font-size: 10pt">=&quot;25&quot;</span><span style="color: red; font-size: 10pt"> Header</span><span style="color: blue; font-size: 10pt">=&quot;Qty&quot;</span><span style="color: red; font-size: 10pt"> SortPropertyName</span><span style="color: blue; font-size: 10pt">=&quot;ItemQty&quot;</span><span style="color: red; font-size: 10pt"> DisplayMemberBinding</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=ItemQty}&quot; /&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                   </span><span style="color: blue; font-size: 10pt">&lt;</span><span style="color: #a31515; font-size: 10pt">c</span><span style="color: blue; font-size: 10pt">:</span><span style="color: #a31515; font-size: 10pt">SortableGridViewColumn</span><span style="color: red; font-size: 10pt"> Header</span><span style="color: blue; font-size: 10pt">=&quot;Description&quot;</span><span style="color: red; font-size: 10pt"> SortPropertyName</span><span style="color: blue; font-size: 10pt">=&quot;&quot;</span><span style="color: red; font-size: 10pt"> DisplayMemberBinding</span><span style="color: blue; font-size: 10pt">=&quot;{</span><span style="color: #a31515; font-size: 10pt">Binding</span><span style="color: red; font-size: 10pt"> Path</span><span style="color: blue; font-size: 10pt">=Description}&quot;/&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">                </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">GridView</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">            </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">ListView.View</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">        </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">ListView</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="color: #a31515; font-size: 10pt">    </span><span style="color: blue; font-size: 10pt">&lt;/</span><span style="color: #a31515; font-size: 10pt">Grid</span><span style="color: blue; font-size: 10pt">&gt;</span></code>
<code><span style="line-height: 115%; color: blue; font-size: 10pt">&lt;/</span><span style="line-height: 115%; color: #a31515; font-size: 10pt">UserControl</span><span style="line-height: 115%; color: blue; font-size: 10pt">&gt;</span></code></pre>
<p>The sample project provides all the implementation details. Each column is also decorated with a &#39;sort direction&#39; arrow indicating ascending/descending sort order. You can extend the code to provide multi-column sort if required as well as custom sort algorithm. You&#39;ll find more information with the AvalonControlsLibrary which by the way includes a number of other useful controls.</p>
<p>One last note on the CheckBox, it&#39;s&nbsp;enabled from code. The reason is that sometimes you want to prevent the user from making the selection twice; maybe the order has already been shipped.</p>
<div style="margin: 0in 0in 10pt">Have fun.</div>
]]></content:encoded>
			<wfw:commentRss>http://chkpointedev.com/2009/10/wpf-tidbits/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

