<?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>Mindscape Blog &#187; WPF Elements</title>
	<atom:link href="http://www.mindscapehq.com/blog/index.php/category/wpf-elements/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mindscapehq.com/blog</link>
	<description>The official blog of Mindscape</description>
	<lastBuildDate>Fri, 03 Feb 2012 01:48:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Awesome DataGrid Productivity Features &#8211; DataTemplate Reuse With PropertyEditors</title>
		<link>http://www.mindscapehq.com/blog/index.php/2012/02/02/awesome-datagrid-productivity-features-datatemplate-reuse-with-propertyeditors/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2012/02/02/awesome-datagrid-productivity-features-datatemplate-reuse-with-propertyeditors/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 01:48:44 +0000</pubDate>
		<dc:creator>CallumG</dc:creator>
				<category><![CDATA[WPF Elements]]></category>
		<category><![CDATA[Data Grid]]></category>
		<category><![CDATA[GridView]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4466</guid>
		<description><![CDATA[An interesting case came up in the forums this week regarding the use of ComboBoxes as editors inside DataGrid cells, and whether they can be used to select a particular object by ID in the background while displaying a corresponding Description property on the object instead of the ID. This could of course be implemented [...]]]></description>
			<content:encoded><![CDATA[<p>An interesting case came up in the forums this week regarding the use of ComboBoxes as editors inside <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">DataGrid</a> cells, and whether they can be used to select a particular object by ID in the background while displaying a corresponding Description property on the object instead of the ID. This could of course be implemented with a DataTemplate containing a ComboBox with converters to display the appropriate description, but this approach would get messy as you&#8217;d have to add a unique template and converters for each column which needed a ComboBox. Wouldn&#8217;t it be much more elegant if you could create just one template but parameterise it so you could pass in different options for each column that used it?</p>
<p>Well, you can!  The PropertyEditor class supports an EditContext property which you can set up on a per-property basis, and the editor DataTemplate can bind to this EditContext and customize the template based on its state. I&#8217;ll go into detail on the above case in the second part of this post, but first off let&#8217;s look at a simpler use case where the EditContext can be used to clean up your XAML, but which is a bit easier for demo purposes!</p>
<p>Imagine a case where we have a model with multiple integer properties representing specifications of some object, for instance personal computers. We&#8217;d like to display these in a DataGrid, and it&#8217;d be great if the user could change the value in a cell with a Slider (or UpDown control, etc). As the various properties have differing sensible ranges they would normally need their own template containing a unique Slider with its Minimum/Maximum/SmallChange set appropriately.</p>
<p><a href="http://www.mindscapehq.com/blog/index.php/2012/02/02/awesome-datagrid-productivity-features-datatemplate-reuse-with-propertyeditors/post6-3/" rel="attachment wp-att-4476"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/post6-3.png" alt="" title="post6-3" width="544" height="240" align="center" class="aligncenter size-full wp-image-4476" /></a></p>
<p>Instead of creating three separate templates we can set the EditContext of a PropertyEditor, and then bind to this from the template. Firstly, we&#8217;ll need a class to hold the values we need to vary between instances of the template. For our numeric editing example this is very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ComputerEditInfo
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Maximum <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Minimum <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> SmallChange <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Then back in the XAML inside the DataGrid declaration, open a PropertyEditor tag and set its EditContext to be an instance of the above class. Here&#8217;s two out of three required:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:DataGrid.Editors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:PropertyEditor</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;Ram&quot;</span></span>
<span style="color: #009900;">                     <span style="color: #000066;">EditorTemplate</span>=<span style="color: #ff0000;">&quot;{StaticResource NumericSliderCellTemplate}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:PropertyEditor.EditContext<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:ComputerEditInfo</span> <span style="color: #000066;">Minimum</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Maximum</span>=<span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #000066;">SmallChange</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:PropertyEditor.EditContext<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:PropertyEditor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:PropertyEditor</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;HardDrive&quot;</span></span>
<span style="color: #009900;">                     <span style="color: #000066;">EditorTemplate</span>=<span style="color: #ff0000;">&quot;{StaticResource NumericSliderCellTemplate}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:PropertyEditor.EditContext<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:ComputerEditInfo</span> <span style="color: #000066;">Minimum</span>=<span style="color: #ff0000;">&quot;120&quot;</span> <span style="color: #000066;">Maximum</span>=<span style="color: #ff0000;">&quot;1024&quot;</span> <span style="color: #000066;">SmallChange</span>=<span style="color: #ff0000;">&quot;120&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:PropertyEditor.EditContext<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>                    
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:PropertyEditor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:DataGrid.Editors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Notice that we have to use the Editors collection instead of the Columns collection.</p>
<p>Now we can create our reusable DataTemplate. There are a couple of important things to be aware of when creating a reusable DataTemplate for use with a PropertyEditor.</p>
<p>First, because the template is going to be used for multiple properties, you can&#8217;t bind to the property by the actual property name on the originating object.  Instead, the PropertyEditor plumbing presents the value being edited as Value, and that&#8217;s what you have to bind to in the editing control(s).</p>
<p>Second, the PropertyEditor plumbing also supplies an EditContext property that you can bind to.  For any given instance of the editor template, this will contain the value of the EditContext in the PropertyEditor declaration that applies to the current instance.</p>
<p>Here&#8217;s the editor template for the numeric properties of the computer object:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;NumericSliderCellTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding EditContext.Minimum}&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;2,0,0,0&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">Foreground</span>=<span style="color: #ff0000;">&quot;#3D3D3D&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Slider</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;{Binding Value, Mode=TwoWay}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Minimum</span>=<span style="color: #ff0000;">&quot;{Binding EditContext.Minimum}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Maximum</span>=<span style="color: #ff0000;">&quot;{Binding EditContext.Maximum}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">SmallChange</span>=<span style="color: #ff0000;">&quot;{Binding EditContext.SmallChange}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;2,0,2,0&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding EditContext.Maximum}&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;2&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;0,0,4,0&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">Foreground</span>=<span style="color: #ff0000;">&quot;#3D3D3D&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Notice how the Slider and the TextBlocks bind to the EditContext to implement and display the correct per-property settings for minimum and maximum values and change size.  One template for multiple columns, each with their values correctly set &#8211; that&#8217;s pretty clean! And here&#8217;s the output, where after the cell is double-clicked into edit mode the Slider appears set with the minimum and maximum.</p>
<p><a href="http://www.mindscapehq.com/blog/index.php/2012/02/02/awesome-datagrid-productivity-features-datatemplate-reuse-with-propertyeditors/post6-4/" rel="attachment wp-att-4482"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/post6-4.png" alt="" title="post6-4" width="551" height="261" class="aligncenter size-full wp-image-4482" /></a></p>
<p>This of course can be extended for passing in any sort of data that can be reused with adjustments across columns, and next time we&#8217;ll look at a detailed implementation of the ComboBox case, where its DisplayMemberPath and SelectedValuePath will update based on the various PropertyEditors set for the columns. <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">Check out our site for more information on the DataGrid</a> and the 50+ other controls included in WPF Elements 5. Until then!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2012/02/02/awesome-datagrid-productivity-features-datatemplate-reuse-with-propertyeditors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nightly news, 3 February 2012</title>
		<link>http://www.mindscapehq.com/blog/index.php/2012/02/02/nightly-news-3-february-2012/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2012/02/02/nightly-news-3-february-2012/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 20:21:54 +0000</pubDate>
		<dc:creator>Ivan Towlson</dc:creator>
				<category><![CDATA[LightSpeed]]></category>
		<category><![CDATA[Web Workbench]]></category>
		<category><![CDATA[WPF Diagrams]]></category>
		<category><![CDATA[WPF Elements]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4518</guid>
		<description><![CDATA[It&#8217;s the end of another week here at Mindscape HQ and time as usual to check in on what we&#8217;ve shipped in the last seven days. Here&#8217;s what&#8217;s new in the latest nightly builds. WPF Elements Added handling for race conditions in DataGrid.BringCellIntoView and DataGrid.GetCell Fixed a bug in DataGrid.RemoveInputBinding Added DataGridColumn.AllowGrouping property, which allows [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s the end of another week here at Mindscape HQ and time as usual to check in on what we&#8217;ve shipped in the last seven days.  Here&#8217;s what&#8217;s new in the latest nightly builds.</p>
<p><a href="http://www.thepoke.co.uk/2011/11/29/23-legendary-album-covers-in-lego/?pid=6382"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/02/DeveloperNotes21.png" alt="" title="Well, Debbie Harry has certainly gone to seed.  And turned bright yellow" width="344" height="64" class="alignleft size-full wp-image-4519" /></a></p>
<p><strong>WPF Elements</strong></p>
<ul>
<li>Added handling for race conditions in DataGrid.BringCellIntoView and DataGrid.GetCell</li>
<li>Fixed a bug in DataGrid.RemoveInputBinding</li>
<li>Added DataGridColumn.AllowGrouping property, which allows you to specify that the user cannot group on that column</li>
<li>You can now template DataGrid group row headers</li>
</ul>
<p><strong>Web Workbench</strong></p>
<ul>
<li>Highlighting for Less pattern matching and guards</li>
<li>Fix for file generation error when using checkout-based source control system</li>
<li>Updated Less compiler to 1.2.1</li>
<li>Improved positioning of opening braces during Format Document</li>
<li>Fix for error with unbounded node (e.g. unclosed quote) in CoffeeScript</li>
</ul>
<p><strong>LightSpeed</strong></p>
<ul>
<li>Apply COLLATE NOCASE when creating SQLite GUID primary keys</li>
<li>Fixes relating to one-way associations when the originating side is a concrete table inheritance base class</li>
<li>Fixed migrations error with abstract classes</li>
</ul>
<p><strong>WPF Diagrams</strong></p>
<ul>
<li>Tweak to the ElbowPathfinder</li>
</ul>
<p>As always the free editions are available on the <a href="http://www.mindscapehq.com/downloads/">downloads page</a> and you can get the full editions from the <a href="http://www.mindscapehq.com/store/myaccount">store</a>.  Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2012/02/02/nightly-news-3-february-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nightly news, 27 January 2012</title>
		<link>http://www.mindscapehq.com/blog/index.php/2012/01/26/nightly-news-27-january-2012/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2012/01/26/nightly-news-27-january-2012/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 20:11:59 +0000</pubDate>
		<dc:creator>Ivan Towlson</dc:creator>
				<category><![CDATA[LightSpeed]]></category>
		<category><![CDATA[WPF Diagrams]]></category>
		<category><![CDATA[WPF Elements]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4431</guid>
		<description><![CDATA[The big news in this week&#8217;s nightly builds is the new hotness in the WPF Elements DataGrid. Grouping, exporting, new APIs and, well, grouping again because it&#8217;s so neat &#8212; check it out! Of course, we&#8217;ve got a bunch of other updates for you as well. Here&#8217;s what&#8217;s new this week. LightSpeed Exclude null associations [...]]]></description>
			<content:encoded><![CDATA[<p>The big news in this week&#8217;s nightly builds is the new hotness in the WPF Elements DataGrid.  Grouping, exporting, new APIs and, well, grouping again because it&#8217;s so neat &#8212; <a href="http://www.mindscapehq.com/blog/index.php/2012/01/25/fresh-wpf-elements-5-features-datagrid-grouping-and-exporting/">check it out</a>!  Of course, we&#8217;ve got a bunch of other updates for you as well.  Here&#8217;s what&#8217;s new this week.</p>
<p><a href="http://www.buzzfeed.com/daves4/12-extremely-disappointing-facts-about-popular-mus"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/DeveloperNotes21.png" alt="" title="How about this one?  Have I used this one?" width="344" height="64" class="alignleft size-full wp-image-4432" /></a></p>
<p><strong>LightSpeed</strong></p>
<ul>
<li>Exclude null associations from polymorphic association validation
</li>
<li>Fix for not being able to return array values from ICompiledParameterValues to populate an IN clause
</li>
<li>Fix for LINQ projection that included the result of a Count on a join-into result when there was no Where clause
</li>
<li>When updating a SQLite database with a GUID field, set COLLATE NOCASE on the column (because it is mapped as a string rather than a native GUID type)
</li>
<li>Added support for per-table identity block size (for when new tables use KeyTable but the database also contains legacy tables which are also updated by other apps using increment-by-1 sequences)
</li>
</ul>
<p><strong>WPF Diagrams</strong></p>
<ul>
<li>DiagramConnectionPointBase.OnPositionChanged is now exposed to user derived classes
</li>
<li>Fixed a bug in the ConnectionPointRelocation sample
</li>
</ul>
<p><strong>WPF Elements</strong></p>
<ul>
<li>DataGrid hotness!
</li>
<li>Fixed a bug in TimeExplorer
</li>
</ul>
<p>As usual, you can get the updated builds of free versions from the <a href="http://www.mindscapehq.com/downloads/">downloads page</a>, and of full versions from the <a href="http://www.mindscapehq.com/store/myaccount">store</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2012/01/26/nightly-news-27-january-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fresh WPF Elements 5 Features &#8211; DataGrid Grouping and Exporting!</title>
		<link>http://www.mindscapehq.com/blog/index.php/2012/01/25/fresh-wpf-elements-5-features-datagrid-grouping-and-exporting/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2012/01/25/fresh-wpf-elements-5-features-datagrid-grouping-and-exporting/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 03:56:34 +0000</pubDate>
		<dc:creator>CallumG</dc:creator>
				<category><![CDATA[WPF Elements]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4397</guid>
		<description><![CDATA[One of the great things about having a fast release cycle is being able to deliver cool new functionality as soon as it&#8217;s ready &#8211; no waiting for the next quarterly release for a crucial feature that could be released today. In the buildup to WPF Elements 5.1 we&#8217;ve been developing some great additions to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great things about having a fast release cycle is being able to deliver cool new functionality as soon as it&#8217;s ready &#8211; no waiting for the next quarterly release for a crucial feature that could be released today. In the buildup to WPF Elements 5.1 we&#8217;ve been developing some great additions to the existing controls in the suite, as well as going through the codebase with a fine-toothed comb to ensure it remains highly stable and bug-free. We&#8217;re not cruel enough to make you wait for these improvements, so you can grab them from the <a href="http://www.mindscapehq.com/products/wpfelements/nightly-builds">nightly builds</a> right now &#8211; both feature additions and bugfixes!</p>
<p>There are many small improvements to the API, such as being able to scroll a particular <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">DataGrid</a> cell into view, as well as two significant additions to the DataGrid we&#8217;re sure you&#8217;ll find very handy &#8211; Grouping and Exporting support. For the rest of the post I&#8217;ll be discussing how you can use these two features. First up &#8211; grouping!</p>
<h2>Grouping</h2>
<p>Users can now group data by any number of columns through an intuitive drag-and-drop interface &#8211; just drag a column header onto the grouping panel above the grid. Groups can be expanded and collapsed as expected, and the column grouping can be be removed by clicking on a button that appears on mouseover. Any number of columns can be added to the panel and the DataGrid will group the data in a nested fashion. Check out the demo below:</p>
<p><a href="http://www.mindscapehq.com/blog/index.php/2012/01/25/fresh-wpf-elements-5-features-datagrid-grouping-and-exporting/grouping3/" rel="attachment wp-att-4399"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/grouping3.gif" alt="DataGrid animated grouping demo" title="grouping3" width="723" height="334" class="aligncenter size-full wp-image-4399" /></a></p>
<p>Just set the IsGroupingPanelVisible property to True to enable the grouping UI. Alternatively, if you want to provide your own UI for grouping &#8212; or no UI at all, for example if you have an application where the data should always appear grouped &#8212; you can group on columns programatically by adding them to the GroupedColumns collection:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">MyDataGrid<span style="color: #008000;">.</span><span style="color: #0000FF;">GroupedColumns</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>MyDataGrid<span style="color: #008000;">.</span><span style="color: #0000FF;">EffectiveColumns</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Easy as that. Our DataGrid performance is speedy even with millions of rows, and it stays that way even if the DataGrid has a complex nesting hierarchy.</p>
<h2>Exporting</h2>
<p>Another handy new feature is the ability to export the data in a <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">DataGrid</a> into an appropriate file format. At the moment we support the near-universal CSV format with more to come, and you can export to file, string or TextWriter. Again, it&#8217;s dead easy to use.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">DataGridExporter<span style="color: #008000;">.</span><span style="color: #0000FF;">Csv</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WriteFile</span><span style="color: #008000;">&#40;</span>MyDataGrid, file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>In combination with a SaveFileDialog, you can export your DataGrid:</p>
<p><a href="http://www.mindscapehq.com/blog/index.php/2012/01/25/fresh-wpf-elements-5-features-datagrid-grouping-and-exporting/export1/" rel="attachment wp-att-4402"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/export1.png" alt="DataGrid exporting" title="export1" width="703" height="612" class="aligncenter size-full wp-image-4402" /></a></p>
<p>and have the resulting file be opened by Excel, complete with columns automatically generated by the DataGrid from your collections.</p>
<p><a href="http://www.mindscapehq.com/blog/index.php/2012/01/25/fresh-wpf-elements-5-features-datagrid-grouping-and-exporting/excel1-2/" rel="attachment wp-att-4412"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/excel11.png" alt="" title="excel1" width="443" height="388" class="aligncenter size-full wp-image-4412" /></a></p>
<p>That saves time! These two features along with bugfixes are available in the nightly builds right now, but they&#8217;ll officially be available in the WPF Elements 5.1 soon. You can <a href="http://www.mindscapehq.com/products/wpfelements/download">check out the 60 day trial of WPF Elements 5 here</a> featuring the <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">DataGrid</a> control plus more than 50 others.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2012/01/25/fresh-wpf-elements-5-features-datagrid-grouping-and-exporting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DataGrid customization with Elements 5: Sparklines, template selectors and more</title>
		<link>http://www.mindscapehq.com/blog/index.php/2012/01/23/datagrid-customization-with-elements-5-sparklines-template-selectors-and-more/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2012/01/23/datagrid-customization-with-elements-5-sparklines-template-selectors-and-more/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 02:59:24 +0000</pubDate>
		<dc:creator>CallumG</dc:creator>
				<category><![CDATA[WPF Elements]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4304</guid>
		<description><![CDATA[Following on from earlier posts about our new DataGrid control in WPF Elements 5, today I&#8217;ll be demonstrating some deeper customization options by creating a financial data display demo. By making a Chart control with an embedded LineSeries and setting a couple of properties we can create a great looking Sparkline graph, which can then [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from earlier posts about our new <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">DataGrid</a> control in WPF Elements 5, today I&#8217;ll be demonstrating some deeper customization options by creating a financial data display demo. By making a Chart control with an embedded LineSeries and setting a couple of properties we can create a great looking Sparkline graph, which can then be used as a template for a DataGrid column consisting of those graphs. All of this is included in WPF Elements 5, and you can <a href="http://www.mindscapehq.com/products/wpfelements/download">grab the 60 day fully featured trial here</a> to get started. I&#8217;ll then look at creating a template selector to apply templates to cells depending on their data, and the demo will also use a bit of custom logic to highlight the largest and smallest values in the collections. The final result will end up like this:</p>
<p><a href="http://www.mindscapehq.com/blog/index.php/2012/01/23/datagrid-customization-with-elements-5-sparklines-template-selectors-and-more/post4-datagrid/" rel="attachment wp-att-4305"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/post4-datagrid.png" alt="" title="post4-datagrid" width="724" height="314" class="aligncenter size-full wp-image-4305" /></a></p>
<p>To begin, declare a new DataGrid control in a XAML page and bind its ItemsSource property to a collection in a similar manner to <a href="http://www.mindscapehq.com/blog/index.php/2011/12/12/working-with-the-data-grid-day-1/">Working with the Data Grid &#8211; Day 1</a>. If we are to add charts to this DataGrid its model will need a property of a type that contains an ObservableCollection of DateTimeDouble objects, which the LineGraph will use to draw itself. Here&#8217;s an archive with example data structures illustrating the required behavior (which generate random points suitable for the purposes of this demo): <a href='http://www.mindscapehq.com/blog/index.php/2012/01/23/datagrid-customization-with-elements-5-sparklines-template-selectors-and-more/datamodel/' rel='attachment wp-att-4320'>DataModel</a>.</p>
<p><strong>Setting up the sparkline charts</strong></p>
<p>Next, in the ResourceDictionary add the following DataTemplates containing the formatted charts. The Chart control in WPF Elements 5 has heaps of customization options, and with a few simple tweaks the LineSeries can display a great looking Sparkline chart. Here&#8217;s one possible look for a Sparkline template:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;BidChartCell&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:Chart</span> <span style="color: #000066;">LegendPosition</span>=<span style="color: #ff0000;">&quot;None&quot;</span> <span style="color: #000066;">TitleTemplate</span>=<span style="color: #ff0000;">&quot;{x:Null}&quot;</span> <span style="color: #000066;">Padding</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:LineSeries</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding BidTrend.Data1}&quot;</span> <span style="color: #000066;">AlwaysShowYAxisZero</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000066;">YAxisDataBuffer</span>=<span style="color: #ff0000;">&quot;1000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:Chart.XAxis</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:ChartAxis</span> <span style="color: #000066;">Visibility</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:Chart.XAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:Chart.YAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:ChartAxis</span> <span style="color: #000066;">Visibility</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:Chart.YAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The chart declared in that DataTemplate is going to look rather unnatural in any place larger than a <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">DataGrid</a> cell, so let&#8217;s apply it to a column in our DataGrid by setting its DisplayTemplate property:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:DataGrid</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding Data}&quot;</span> <span style="color: #000066;">AllowEditing</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:DataGrid.Columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:DataGridColumn</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;BidTrend&quot;</span></span>
<span style="color: #009900;">                       <span style="color: #000066;">DisplayTemplate</span>=<span style="color: #ff0000;">&quot;{StaticResource BidChartCell}&quot;</span></span>
<span style="color: #009900;">                       <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Bid Trend&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:DataGrid.Columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ms:DataGrid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Pretty easy! If you were to increase the rows in the model you&#8217;d notice the performance is speedy even with dozens of charts on screen, and stays that way during resizing, dynamic data updating and similar tasks.</p>
<p><strong>Showing additional data with template selectors</strong></p>
<p>Now how about formatting the Change columns to show an image based on the data in each cell? One solution would be to create a custom class that derives from DataTemplateSelector and overrides SelectTemplate(). Here&#8217;s a snippet of the implementation with logic that returns a template based on whether the cell&#8217;s Double is positive or negative:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ChangeDataTemplateSelector <span style="color: #008000;">:</span> DataTemplateSelector
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> DataTemplate SelectTemplate<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> item, DependencyObject container<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    FrameworkElement element <span style="color: #008000;">=</span> container <span style="color: #0600FF; font-weight: bold;">as</span> FrameworkElement<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>element <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> item <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      Entry entryItem <span style="color: #008000;">=</span> item <span style="color: #0600FF; font-weight: bold;">as</span> Entry<span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>ChangeType <span style="color: #008000;">==</span> CellChangeType<span style="color: #008000;">.</span><span style="color: #0000FF;">Bid</span><span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>entryItem<span style="color: #008000;">.</span><span style="color: #0000FF;">BidChange</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          <span style="color: #0600FF; font-weight: bold;">return</span> NegativeChangeTemplate<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>entryItem<span style="color: #008000;">.</span><span style="color: #0000FF;">BidChange</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          <span style="color: #0600FF; font-weight: bold;">return</span> PositiveChangeTemplate<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
      <span style="color: #008000;">&#125;</span>
      <span style="color: #0600FF; font-weight: bold;">else</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>entryItem<span style="color: #008000;">.</span><span style="color: #0000FF;">AskChange</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          <span style="color: #0600FF; font-weight: bold;">return</span> NegativeChangeTemplate<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>entryItem<span style="color: #008000;">.</span><span style="color: #0000FF;">AskChange</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          <span style="color: #0600FF; font-weight: bold;">return</span> PositiveChangeTemplate<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> NoChangeTemplate<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> DataTemplate PositiveChangeTemplate <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The full code with the other two properties and the enum is contained in the archive at the bottom of this post. Back in the XAML, add the DataTemplates that are to be applied to the cell to the ResourceDictionary (here&#8217;s one of four required):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;PositiveBidChangeTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PositiveBidCell&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;35&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding BidChange}&quot;</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Right&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;0,0,6,0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">Source</span>=<span style="color: #ff0000;">&quot;../Images/up.png&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>We can now declare an instance of our DataTemplateSelector and set its properties to our DataTemplates. The Bid selector will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:ChangeDataTemplateSelector</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;BidChangeSelector&quot;</span></span>
<span style="color: #009900;">                                  <span style="color: #000066;">PositiveChangeTemplate</span>=<span style="color: #ff0000;">&quot;{StaticResource PositiveBidChangeTemplate}&quot;</span></span>
<span style="color: #009900;">                                  <span style="color: #000066;">NegativeChangeTemplate</span>=<span style="color: #ff0000;">&quot;{StaticResource NegativeBidChangeTemplate}&quot;</span></span>
<span style="color: #009900;">                                  <span style="color: #000066;">ChangeType</span>=<span style="color: #ff0000;">&quot;Bid&quot;</span></span>
<span style="color: #009900;">                                  <span style="color: #000066;">NoChangeTemplate</span>=<span style="color: #ff0000;">&quot;{StaticResource NoChangeBidTemplate}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Now that has been set up, it&#8217;s a simple matter of setting the DisplayTemplateSelector property on the appropriate DataGridColumn that you wish to apply the templates to. We may as well make the column&#8217;s title look a bit nicer at the same time.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:DataGridColumn</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;BidChange&quot;</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Bid Change&quot;</span></span>
<span style="color: #009900;">                   <span style="color: #000066;">DisplayTemplateSelector</span>=<span style="color: #ff0000;">&quot;{StaticResource BidChangeSelector}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>That will get the Change and Trend columns looking like the screenshot at the top of this post. In a future post I&#8217;ll show how to extend the model to record the highest and lowest data, and use XAML triggers to format cells based upon that information. In the meantime, check out the archive below for the full code from this post.</p>
<p><a href='http://www.mindscapehq.com/blog/index.php/2012/01/23/datagrid-customization-with-elements-5-sparklines-template-selectors-and-more/datagrid-post-4/' rel='attachment wp-att-4338'>DataGrid with sparklines and template selectors</a></p>
<p>And don&#8217;t forget to <a href="http://www.mindscapehq.com/products/wpfelements/download">download the 60-day trial of WPF Elements</a> and try out your own designs!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2012/01/23/datagrid-customization-with-elements-5-sparklines-template-selectors-and-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nightly news, 20 January 2012</title>
		<link>http://www.mindscapehq.com/blog/index.php/2012/01/19/nightly-news-20-january-2012/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2012/01/19/nightly-news-20-january-2012/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 20:41:11 +0000</pubDate>
		<dc:creator>Ivan Towlson</dc:creator>
				<category><![CDATA[LightSpeed]]></category>
		<category><![CDATA[NHibernate Designer]]></category>
		<category><![CDATA[SimpleDB Management Tools]]></category>
		<category><![CDATA[Web Workbench]]></category>
		<category><![CDATA[WPF Diagrams]]></category>
		<category><![CDATA[WPF Elements]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4345</guid>
		<description><![CDATA[Cripes! Weeks and weeks of updates to catch up on! Here&#8217;s what&#8217;s new in the nightly builds since the last update. LightSpeed Fix for one-to-one association join chain in LINQ Where clauses Added support for negated boolean expressions in LINQ Any and All Fixed a memory leak with compiled FindById queries Validation errors now provide [...]]]></description>
			<content:encoded><![CDATA[<p>Cripes!  Weeks and weeks of updates to catch up on!  Here&#8217;s what&#8217;s new in the nightly builds since the last update.</p>
<p><a href="http://www.headinjurytheater.com/article73.htm"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/DeveloperNotes2.png" alt="" title="And I can no longer remember which easter eggs I&#039;ve already used" width="344" height="64" class="alignleft size-full wp-image-4346" /></a></p>
<p><strong>LightSpeed</strong></p>
<ul>
<li>Fix for one-to-one association join chain in LINQ Where clauses
</li>
<li>Added support for negated boolean expressions in LINQ Any and All
</li>
<li>Fixed a memory leak with compiled FindById queries
</li>
<li>Validation errors now provide access to the validation rule instance
</li>
<li>Include schema in auto-joined tables being joined by an identifier expression
</li>
<li>Fixed automatic date-time range validation for Oracle
</li>
<li>Improved support for SQL Server 2008 TIME data type
</li>
<li>Fixed an issue where a query with criteria on the left and a logical combination on the right could be processed incorrectly
</li>
<li>Fix for DeletedOn column being incorrectly aliased in update/delete queries
</li>
<li>Added support for deleting by LINQ query
</li>
<li>Added Procedure and Scale options to ProcedureParameter class
</li>
<li>Fix for procedure parameters of user-defined types in designer being generated into wrapper function signatures as object instead of strongly typed
</li>
<li>Fix for value objects not being handled correctly in batch updates
</li>
<li>Fixed exception if you put DiscriminatorAttribute on a root entity class
</li>
<li>We now raise an exception if a SQL Server stored procedure calls RAISERROR (sic: what is this, guys, Fortran?) <em>after</em> performing a successful SELECT (previously only errors raised before the SELECT would cause exceptions)
</li>
<li>Added a property for migration code to access the connection string of the database being migrated
</li>
<li>When a stored procedure sets an out parameter to SQL NULL, we now translate this to CLR null instead of leaving it as DBNull.Value (this fixes casting errors in strong-typed wrapper methods)
</li>
<li>Fix for virtual (non-mapped) discriminators not being populated on insert
</li>
<li>Entity- and interface-level query filtering (in progress and subject to change)
</li>
</ul>
<p><strong>Web Workbench</strong></p>
<ul>
<li>Collapsing support for non-top-level regions
</li>
<li>Sass and Less Format Document command
</li>
<li>Fixed issue in Sass compilation if install path included non-ANSI characters
</li>
<li>Fixed JavaScript minifier mangling non-ANSI characters
</li>
<li>Upgraded CoffeeScript compiler to 1.2.0
</li>
<li>CoffeeScript comment highlighting fixes
</li>
<li>Comment/uncomment block support
</li>
<li>Performance improvements when making many deletes from a document
</li>
<li>Error checking and signature help for Sass and Less built-in functions
</li>
</ul>
<p><strong>WPF Elements<br />
</strong></p>
<ul>
<li>Continuing improvements to control themes
</li>
<li>Fixes for potential issues in TimeExplorer, Chart, ChartAxis and PieSeries
</li>
<li>Added option for rounding on lost focus in NumericTextBox
</li>
<li>Added ResetZoom command for charts
</li>
<li>MajorTickSpacing now keeps consistent tick density as user zooms
</li>
<li>Added PieSeries.SelectedDataPointChanged event
</li>
<li>Improvements to automatic bar chart width calculation
</li>
<li>Fixed error when changing chart highlight mode
</li>
<li>Fixed an issue with horizontal bar charts using categories along the Y axis
</li>
<li>Resolved a DataGrid issue
</li>
<li>Fixed foreground colours not being respected in CurrencyTextBox
</li>
<li>Fixed potential null reference error when changing DataGrid.ItemsSource
</li>
<li>Fixed some issues with chart default axes
</li>
</ul>
<p><strong>WPF Diagrams</strong></p>
<ul>
<li>Added TreeLayoutAlgorithm
</li>
<li>Fixed null reference error in ConnectionPointThumb
</li>
<li>Fixed a diagram binding issue
</li>
<li>Fix for a bug that was stealing mouse wheel and scroll events
</li>
<li>Added an option to turn off infinite scrolling
</li>
</ul>
<p><strong>NHibernate Designer</strong></p>
<ul>
<li>Added support for NHibernate sql-insert, sql-update and sql-delete overrides
</li>
<li>Added support for stored procedures and named SQL queries
</li>
</ul>
<p><strong>SimpleDB Management Tools</strong></p>
<ul>
<li>No longer need to click away from a row to ensure it is saved</li>
</ul>
<p>As usual you can get the latest nightly builds from the <a href="http://www.mindscapehq.com/downloads/">Downloads page</a> (free editions) or the <a href="http://www.mindscapehq.com/store/myaccount">store</a> (full editions).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2012/01/19/nightly-news-20-january-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kick start 2012 with this special offer!</title>
		<link>http://www.mindscapehq.com/blog/index.php/2012/01/12/kick-start-2012-with-this-special-offer/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2012/01/12/kick-start-2012-with-this-special-offer/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 08:36:04 +0000</pubDate>
		<dc:creator>John-Daniel Trask</dc:creator>
				<category><![CDATA[LightSpeed]]></category>
		<category><![CDATA[MegaPack]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[NHibernate Designer]]></category>
		<category><![CDATA[Phone Elements]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[Silverlight Elements]]></category>
		<category><![CDATA[SimpleDB Management Tools]]></category>
		<category><![CDATA[Web Workbench]]></category>
		<category><![CDATA[WPF Diagrams]]></category>
		<category><![CDATA[WPF Elements]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4262</guid>
		<description><![CDATA[Make building better software your New Year&#8217;s resolution by taking advantage of our 30% sale on the Mega Pack. For a limited time, pay only $699 and you&#8217;ll receive: LightSpeed O/R Mapper (normally $349) WPF Elements (normally $699) WPF Diagrams (normally $699) Silverlight Elements (normally $699) Phone Elements for WP7 (normally $299) NHibernate Designer (normally [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mindscapehq.com/productive-2012"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/JanuarySaleBlogImage.jpg" alt="Get 9 products for an amazing price" title="Get 9 products for an amazing price" width="718" height="450" class="alignnone size-full wp-image-4263" /></a></p>
<p>Make building better software your New Year&#8217;s resolution by <a href="http://www.mindscapehq.com/productive-2012">taking advantage of our 30% sale on the Mega Pack</a>.</p>
<p>For a limited time, pay only $699 and you&#8217;ll receive:</p>
<ul>
<li><a href="http://www.mindscapehq.com/products/lightspeed">LightSpeed O/R Mapper</a> <span style="color: rgb(192, 192, 192); ">(normally $349)</span></li>
<li><a href="http://www.mindscapehq.com/products/wpfelements">WPF Elements</a> <span style="color: rgb(192, 192, 192); ">(normally $699)</span></li>
<li><a href="http://www.mindscapehq.com/products/wpfdiagrams">WPF Diagrams</a> <span style="color: rgb(192, 192, 192); ">(normally $699)</span></li>
<li><a href="http://www.mindscapehq.com/products/silverlightelements">Silverlight Elements</a> <span style="color: rgb(192, 192, 192); ">(normally $699)</span></li>
<li><a href="http://www.mindscapehq.com/products/phone-elements">Phone Elements for WP7</a> <span style="color: rgb(192, 192, 192); ">(normally $299)</span></li>
<li><a href="http://www.mindscapehq.com/products/nhdesigner">NHibernate Designer</a> <span style="color: rgb(192, 192, 192); ">(normally $99)</span></li>
<li><a href="http://www.mindscapehq.com/products/simpledbtools">SimpleDB Management Tools</a> <span style="color: rgb(192, 192, 192); ">(normally $29)</span></span></li>
<li><a href="http://www.mindscapehq.com/products/web-workbench">Web Workbench</a> <span style="color: rgb(192, 192, 192); ">(normally $29)</span></li>
<li><a href="http://www.mindscapehq.com/products/sharepointtools">Visual Tools for SharePoint</a> <span style="color: rgb(192, 192, 192); ">(normally $349)</span></li>
</ul>
<p>Plus, you also get:</p>
<ul>
<li>12 months of new releases, nightly builds and new products!</li>
<li>The best support in the business!</li>
</ul>
<p>Imagine that &#8211; a full range of developer tools across WPF, Silverlight, Windows Phone, Data Access, Web Development and Domain Modeling for just $699!</p>
<p>So, save thousands of dollars by getting all your tools at once with our 30% off Mega Pack Special now.</p>
<p>Hurry, promotion ends 1 Feb 2012!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2012/01/12/kick-start-2012-with-this-special-offer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF Elements 5 Dashboard Sample</title>
		<link>http://www.mindscapehq.com/blog/index.php/2012/01/09/wpf-elements-5-dashboard-sample/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2012/01/09/wpf-elements-5-dashboard-sample/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 00:13:14 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[MegaPack]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF Elements]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4243</guid>
		<description><![CDATA[Not long ago we released version 5 of WPF Elements, a suite of fantastic WPF controls (if I do say so myself, as the lead developer&#8230;). This version includes a high performance data grid control, a time explorer for selecting time ranges in a convenient manner and hundreds of enhancements across the board. In the [...]]]></description>
			<content:encoded><![CDATA[<p>Not long ago we released version 5 of <a href="https://www.mindscapehq.com/products/wpfelements">WPF Elements</a>, a suite of fantastic WPF controls (if I do say so myself, as the lead developer&#8230;). This version includes a <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">high performance data grid control</a>, a <a href="http://www.mindscapehq.com/products/wpfelements/controls/time-explorer">time explorer</a> for selecting time ranges in a convenient manner and hundreds of enhancements across the board. In the latest <a href="http://www.mindscapehq.com/products/wpfelements/nightly-builds">nightly build</a> you will find a new sample app that demonstrates how to use various controls from WPF elements to build a sales dashboard. This app is built using the <a href="http://caliburnmicro.codeplex.com/">Caliburn Micro framework</a> and is implemented using the popular MVVM design pattern.</p>
<p><a href="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/Pipper-Catering-Dashboard.gif"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/Pipper-Catering.gif" alt="Pipper Catering Dashboard" title="Pipper Catering Dashboard" width="718" height="440" class="alignnone size-full wp-image-4252" /></a></p>
<p><strong>User interaction</strong></p>
<p>First lets have a look at what this dashboard provides in the user interface. Along the top of the dashboard is the <a href="https://www.mindscapehq.com/products/wpfelements/controls/time-explorer">time explorer</a> control. This allows the user to select a time range by dragging or clicking the mouse. By zooming in with the mouse wheel, the time explorer will display shorter time intervals such as weeks and days. Within the time explorer is a line chart displaying some summary data for the overall dashboard. This makes it easy for the user to select a time range around any interesting points in the data. Every time the user selects a new time range, the data displayed in the charts, gauges and data grid are updated to only include the data in the selected time range.</p>
<p><a href="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/UserInteraction.png"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/UserInteraction.png" alt="Time explorer interaction" title="Time explorer interaction" width="718" height="458" class="alignnone size-full wp-image-4248" /></a></p>
<p><strong>Data drill down</strong></p>
<p>The <a href="https://www.mindscapehq.com/products/wpfelements/controls/wpf-stacked-bar-chart">stacked bar chart</a> below the time explorer is plotting a category breakdown of the data for each point displayed on the X axis. An individual bar shows the data for either a month, day, or 2 hour time slot based on the magnitude of the selected time range. Clicking on one of the bars will drill down to the next time interval.</p>
<p><a href="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/DataDrillDown.png"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/DataDrillDown.png" alt="Data drill down" title="Data drill down" width="718" height="284" class="alignnone size-full wp-image-4249" /></a></p>
<p><strong>Category filtering</strong></p>
<p>Selecting one of the segments in the doughnut chart will filter the data grid by the selected category, and emphasise the appropriate points in the stacked bar chart and the equivalent gauge.</p>
<p><a href="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/CategoryFiltering1.png"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2012/01/CategoryFiltering1.png" alt="Category filtering" title="Category filtering" width="718" height="628" class="alignnone size-full wp-image-4250" /></a></p>
<p>Along the bottom of the dashboard is a text block displaying the total sales value, animated linear gauges, and our <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">WPF data grid</a>. Users can reorder, resize and sort the columns in the data grid to display the current data however they would prefer.</p>
<p><strong>MVVM architecture</strong></p>
<p>The MVVM design pattern is commonly used to create robust WPF applications that are easy to maintain. The main idea behind this pattern is to cleanly separate the data model from the user interface. The only things linking these two parts together should be bindings, commands and event handlers. The data model of the dashboard application listens to changes made to the various controls based on the user interaction. These changes are analysed and the displayed data held within the model is updated to reflect the selected time ranges or filters. The controls within the user interface listen to the changes made to the data model and then updates the visuals for the user to see.</p>
<p>You can <a href="http://assets.mindscape.co.nz/Trial/Nightlies/20120109/WpfElements5Trial-20120109.msi">download the trial version of the latest nightly build from here</a>, or go to your <a href="http://www.mindscapehq.com/store/myaccount">account page</a> if you are already a customer. The smaller data model classes can be found in the Model folder. The main data model class is called DashboardViewModel, and the UI is built up in the DashboardView.xaml file. The SimpleLinearGauge extends our AnimatedValueDisplay, and the remaining class files are for hooking into the Caliburn Micro framework.</p>
<p>Have any questions about WPF Elements? <a href="http://www.mindscapehq.com/forums/forum/15">We&#8217;d love to hear from you in the forum!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2012/01/09/wpf-elements-5-dashboard-sample/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Working with the Data Grid &#8211; Day 3</title>
		<link>http://www.mindscapehq.com/blog/index.php/2011/12/18/working-with-the-data-grid-day-3/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2011/12/18/working-with-the-data-grid-day-3/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 02:22:10 +0000</pubDate>
		<dc:creator>CallumG</dc:creator>
				<category><![CDATA[WPF Elements]]></category>
		<category><![CDATA[Custom Editors]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[WPF Data Grid]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4207</guid>
		<description><![CDATA[The Data Grid control in WPF Elements 5 has many powerful features for applying cell templates, custom editors and data validation, and they&#8217;re all really easy to use. In minutes you can have a data grid up and running that will present information to the user in a specified style, provide hints in edit mode [...]]]></description>
			<content:encoded><![CDATA[<p>The Data Grid control in <a href="http://www.mindscapehq.com/products/wpfelements">WPF Elements 5</a> has many powerful features for applying cell templates, custom editors and data validation, and they&#8217;re all really easy to use. In minutes you can have a data grid up and running that will present information to the user in a specified style, provide hints in edit mode then check that the data is correct using any validation code you desire.</p>
<p>Building on the example we&#8217;re created in the first two posts (<a href="http://www.mindscapehq.com/blog/index.php/2011/12/12/working-with-the-data-grid-day-1/">part 1</a>, <a href="http://www.mindscapehq.com/blog/index.php/2011/12/14/working-with-the-data-grid-day-2/">part 2</a>), let&#8217;s next add a custom cell template to display the numeric data in the Balance column in a currency format. This can be accomplished by setting the DisplayTemplate property of the appropriate DataGridColumn. WPF Elements 5 includes many useful controls for data display and editing, and the CurrencyTextBox is perfect for our purposes. It will format the value with currency information appropriate to the current culture automatically, as well as taking care of the decimal point and cents entered (if any). The CurrencyTextBox control Add this as a Resource:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- style information to make it look how we want --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;NegativeBalanceStyle&quot;</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;TextBox&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Transparent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Foreground&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;DarkRed&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;BorderThickness&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- add the currency text box to our data template --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;BalanceCellTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:CurrencyTextBox</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;{Binding Balance}&quot;</span> <span style="color: #000066;">NegativeStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource NegativeBalanceStyle}&quot;</span></span>
<span style="color: #009900;">                      <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;Transparent&quot;</span> <span style="color: #000066;">Foreground</span>=<span style="color: #ff0000;">&quot;White&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>and assigning it to the property:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:DataGridColumn</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;Balance&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;140&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">DisplayTemplate</span>=<span style="color: #ff0000;">&quot;{StaticResource BalanceCellTemplate}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>will format the Balance column nicely.</p>
<p><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2011/12/datagrid3-1.png" alt="WPF Data Grid with custom editors" title="WPF Data Grid with custom editors" width="600" height="450" class="alignnone size-full wp-image-4208" /></p>
<p>Next up is custom cell editors. You can be as creative as you like here &#8211; if you have a particular type of data that would be especially intuitive to select in a visual manner, or if a custom converter would assist your users, the WPF Data Grid will support it. There are some great examples in the Sample Explorer demos, such as a metric to imperial (feet + inches) converter, and of course the built-in color pickers. You could even allow users to select a timezone graphically like in the DropDownEditBox demo, right in the middle of a Data Grid cell. All these demos are available in the <a href="http://www.mindscapehq.com/products/wpfelements/download">60 day trial of WPF Elements 5 which you can grab here</a>.</p>
<p>For the phone number column it would be nice to provide the user with a masked textbox to help them enter the required digits. Again WPF Elements 5 comes with a control with this functionality built-in &#8211; the Masked Textbox. To apply this control to our Phone column create these resource:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;PhoneEditor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:MaskedTextBox</span> <span style="color: #000066;">Mask</span>=<span style="color: #ff0000;">&quot;00-000-0000&quot;</span> <span style="color: #000066;">AutoSkipLiterals</span>=<span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Phone}&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">LiteralStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource Literal}&quot;</span> <span style="color: #000066;">PromptStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource Prompt}&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;Transparent&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">PromptCharDisplaySelector</span>=<span style="color: #ff0000;">&quot;{StaticResource PromptCharDisplaySelector}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;Literal&quot;</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;Inline&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;FontWeight&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Bold&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Foreground&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;DarkGoldenrod&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;Prompt&quot;</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;Run&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Foreground&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;LightGray&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;FontFamily&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Wingdings&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>      
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:FancyPromptCharDisplaySelector</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;PromptCharDisplaySelector&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>and then set the property:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:DataGridColumn</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;Phone&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;120&quot;</span> <span style="color: #000066;">EditorTemplate</span>=<span style="color: #ff0000;">&quot;{StaticResource PhoneEditor}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>This highlights the rather ugly case where the user only partially completes the phone number field, or deletes it altogether. The obvious next step is validation! Fortunately this is also easy to apply to the Data Grid. It provides an event, ValidateCell, which will be raised upon data being altered. Generate the method and inside it place something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">object</span> value <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">Cell</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">Cell</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Column</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyName</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;Phone&quot;</span><span style="color: #008000;">:</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> number <span style="color: #008000;">=</span> value <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>number<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">11</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      e<span style="color: #008000;">.</span><span style="color: #0000FF;">IsValid</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
      e<span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationMessage</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Number must contain 9 numerals&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;Address&quot;</span><span style="color: #008000;">:</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> address <span style="color: #008000;">=</span> value <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>address<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      e<span style="color: #008000;">.</span><span style="color: #0000FF;">IsValid</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
      e<span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationMessage</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Address cannot be null&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This will produce the behavior illustrated in the screenshot below. The user is prompted for the expected input when editing a cell in the Phone column, and if any invalid input is received the cell will be highlighted with a red border. Much better!</p>
<p><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2011/12/datagrid3-2.png" alt="WPF Data Grid with validation showing" title="WPF Data Grid with validation showing" width="600" height="450" class="alignnone size-full wp-image-4218" /></p>
<p>If you haven&#8217;t already, <a href="http://www.mindscapehq.com/products/wpfelements/download">download the 60 day trial of WPF Elements 5</a> to check out the Data Grid and more than 50 other controls.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2011/12/18/working-with-the-data-grid-day-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working with the Data Grid &#8211; Day 2</title>
		<link>http://www.mindscapehq.com/blog/index.php/2011/12/14/working-with-the-data-grid-day-2/</link>
		<comments>http://www.mindscapehq.com/blog/index.php/2011/12/14/working-with-the-data-grid-day-2/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 00:11:54 +0000</pubDate>
		<dc:creator>CallumG</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF Elements]]></category>

		<guid isPermaLink="false">http://www.mindscapehq.com/blog/?p=4149</guid>
		<description><![CDATA[Following on from the first post about the new WPF Data Grid control in WPF Elements 5, today I&#8217;ll be writing about some of the options for customizing it. If you haven&#8217;t already checked out the new version with it and over 50 other controls head over and grab the 60 day trial here. Getting [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from the first post about the new <a href="http://www.mindscapehq.com/products/wpfelements/controls/data-grid">WPF Data Grid</a> control in <a href="http://www.mindscapehq.com/products/wpfelements">WPF Elements 5</a>, today I&#8217;ll be writing about some of the options for customizing it. If you haven&#8217;t already checked out the new version with it and over 50 other controls head over and <a href="http://www.mindscapehq.com/products/wpfelements/download">grab the 60 day trial here</a>. Getting the control up and running was pretty easy, and setting the behavior to your specifications is just as simple. So what properties can we set? The follow is a list of some of the important ones, many more tweaks can be made through the API. Adjust the following to taste:</p>
<h3>Rows &#038; Columns</h3>
<ul>
<li>ShowColumnHeaders- will hide the row of column labels if False. Defaults to True</li>
<li>ShowRowHeaders- as above</li>
<li>AllowColumnReorder &#8211; allows the user to change the order of columns by dragging and dropping</li>
<li>RowHeaderWidth &#8211; sets the width of the row header block</li>
<li>AutoGenerateColumns &#8211; will create the columns based on the properties in the bound collection</li>
</ul>
<h3>Frozen Columns</h3>
<ul>
<li>FrozenColumnCount &#8211; the specified number of columns will remain stationary when the Data Grid is scrolled horizontally</li>
<li>ShowFirstFrozenLine &#8211; if True if frozen column shadow line will be displayed on the left when FrozenColumnCount is set to 0</li>
</ul>
<h3>Selection &#038; Editing</h3>
<ul>
<li>HighlightedCell &#8211; gets or sets the cell that has focus (black border)</li>
<li>SelectedCell &#038; SelectedCells &#8211; gets or sets the cell, or collection of cells that have been selected (yellow highlight). Both highlighted and selected cells can be set programmatically</li>
<li>SelectionType &#8211; sets a user&#8217;s click to highlight either a Row or Cell</li>
<li>SelectionMode &#8211; Single allows one cell/row to be selected at a time; Multiple adds a single cell/row to the current selection with a click; Extended allows a block of cells/rows to be highlighted through click and drag functionality</li>
<li>AllowEditing &#8211; if set to True the user will be able to double-click a cell to edit its contents (if False the Data Grid is read-only). Once in editing mode the user can tab across the row</li>
<li>SetAllowEditing() &#8211; when called on a DataGrid, can set either a cell or a row to be read-only. Can be passed a row or a DataGridCell</li>
</ul>
<h3>Paging</h3>
<ul>
<li>IsPagerVisible &#8211; shows the pager control if is True (defaults to False)</li>
<li>PageSize &#8211; sets number of items on a page. Default is 0 (all items on one page)</li>
<li>PageIndex &#8211; sets the current page to be displayed</li>
<li>PagerStyle &#8211; allows you to set a custom style for the pager control</li>
<li>MaxPagerButtonCount &#8211; sets the maximum amount of page buttons to display (including the ellipsis)</li>
<li>EllipsisMode &#8211; place an ellipsis button (indicating further pages) at positions After, Before, None or Both</li>
</ul>
<p>For example the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ms:DataGrid</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;DataGrid&quot;</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding Data}&quot;</span> <span style="color: #000066;">RowHeaderWidth</span>=<span style="color: #ff0000;">&quot;15&quot;</span> <span style="color: #000066;">SelectionMode</span>=<span style="color: #ff0000;">&quot;Extended&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">SelectionType</span>=<span style="color: #ff0000;">&quot;Cell&quot;</span> <span style="color: #000066;">IsPagerVisible</span>=<span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #000066;">PageSize</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">EllipsisMode</span>=<span style="color: #ff0000;">&quot;Both&quot;</span> <span style="color: #000066;">MaxPagerButtonCount</span>=<span style="color: #ff0000;">&quot;5&quot;</span> </span>
<span style="color: #009900;">                 <span style="color: #000066;">AllowColumnReorder</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000066;">FrozenColumnCount</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>produces this result:</p>
<p><a href="http://www.mindscapehq.com/blog/index.php/2011/12/14/working-with-the-data-grid-day-2/datagrid/" rel="attachment wp-att-4163"><img src="http://cdn.mindscapehq.com/blog/wp-content/uploads/2011/12/DataGrid.gif" alt="" title="DataGrid" width="601" height="452" class="alignnone size-full wp-image-4163" /></a></p>
<p>There is also a whole set of properties for the columns themselves. Naturally you can set Widths &#038; MinWidths, alongside setting the Header (which can be any object, just like a cell). Other properties include AllowSort, AllowResize, AllowEditing, SortDirection and most importantly the DisplayTemplate and EditorTemplate properties, for completely customizing the look and feel of a particular column.</p>
<p>Next time we&#8217;ll look at styling the DataGrid, then adding in a custom editor. <a href="http://www.mindscapehq.com/products/wpfelements/download">Download the 60 day trial of WPF Elements now to explore this control plus dozens more</a>. Until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindscapehq.com/blog/index.php/2011/12/14/working-with-the-data-grid-day-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: basic (Requested URI is rejected)
Database Caching 4/22 queries in 0.015 seconds using disk: basic
Content Delivery Network via cdn.mindscapehq.com

Served from: www.mindscapehq.com @ 2012-02-03 22:21:00 -->
