<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Scott Morrison : Silverlight</title><link>http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx</link><description>Tags: Silverlight</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Tech Ed 2009 Demo Files</title><link>http://blogs.msdn.com/scmorris/archive/2009/05/17/tech-ed-2009-demo-files.aspx</link><pubDate>Mon, 18 May 2009 09:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9624847</guid><dc:creator>scmorris</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/9624847.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=9624847</wfw:commentRss><description>&lt;P&gt;It is always a blast to talk at Tech Ed and this year was no different.&amp;nbsp; It was great to get to meet many of you and hear how you are using DataGrid, DataForm, Validation, and RIA Services in your projects today.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;As promised, here are the files for the demos that I showed in my presentations.&lt;/P&gt;
&lt;P&gt;All demos were done on the MIX’09 Silverlight Beta bits and accompanying tools:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;VS 2008 SP1 &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.microsoft.com/express/sql/download/" mce_href="http://www.microsoft.com/express/sql/download/"&gt;Sql Express 2008&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://code.msdn.microsoft.com/RiaServices" mce_href="http://code.msdn.microsoft.com/RiaServices"&gt;.NET RIA Services March '09 Preview&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://silverlight.net/getstarted/silverlight3/default.aspx" mce_href="http://silverlight.net/getstarted/silverlight3/default.aspx"&gt;Silverlight 3 Beta&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;WUX 303: Building Data-Driven RIAs with Microsoft ASP.NET and Microsoft Silverlight&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;What we covered:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Navigation, browser integration, permalinks &lt;/LI&gt;
&lt;LI&gt;Domain methods, filtering, paging, grouping, sorting &lt;/LI&gt;
&lt;LI&gt;Adding validation metadata &lt;/LI&gt;
&lt;LI&gt;Windows Authentication &lt;/LI&gt;
&lt;LI&gt;Writing a different view in ASP.Net and SEO &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Watch It: (&lt;EM&gt;Right now it is restricted to Tech Ed attendees&lt;/EM&gt;)&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.msteched.com/online/view.aspx?tid=ff4f56fc-ff74-4a68-90a8-33c69b0acecc"&gt;http://www.msteched.com/online/view.aspx?tid=ff4f56fc-ff74-4a68-90a8-33c69b0acecc&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Files:&lt;/P&gt;
&lt;P&gt;&lt;IFRAME style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 94px; PADDING-RIGHT: 0px; HEIGHT: 94px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginHeight=0 src="http://cid-e7a27f7920b66c3f.skydrive.live.com/embedgrid.aspx/Downloads/WUX303.zip" frameBorder=0 marginWidth=0 scrolling=no mce_src="http://cid-e7a27f7920b66c3f.skydrive.live.com/embedgrid.aspx/Downloads/WUX303.zip"&gt;&lt;/IFRAME&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;WUX 308: Delivering Rich User Experiences for Business Applications with Microsoft Silverlight 3&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;What we covered:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Customizing the DataGrid: TemplateColumns, Row Details, events in template columns &lt;/LI&gt;
&lt;LI&gt;Charts &lt;/LI&gt;
&lt;LI&gt;Custimizing the DataForm: Using the Display attribute, the Display / Edit templates &lt;/LI&gt;
&lt;LI&gt;Writing a custom cross-field validation method&lt;/LI&gt;
&lt;LI&gt;Export to Excel &lt;/LI&gt;
&lt;LI&gt;DataGrid Copy / Paste with Excel &lt;/LI&gt;
&lt;LI&gt;Going out of browser &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Watch It: (&lt;EM&gt;Right now it is restricted to Tech Ed attendees&lt;/EM&gt;)&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.msteched.com/online/view.aspx?tid=b35f4684-54b2-4da5-9a70-663f79dd9ab7"&gt;http://www.msteched.com/online/view.aspx?tid=b35f4684-54b2-4da5-9a70-663f79dd9ab7&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Files:&lt;/P&gt;
&lt;P&gt;&lt;IFRAME style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 94px; PADDING-RIGHT: 0px; HEIGHT: 94px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginHeight=0 src="http://cid-e7a27f7920b66c3f.skydrive.live.com/embedgrid.aspx/Downloads/WUX308.zip" frameBorder=0 marginWidth=0 scrolling=no mce_src="http://cid-e7a27f7920b66c3f.skydrive.live.com/embedgrid.aspx/Downloads/WUX308.zip"&gt;&lt;/IFRAME&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; If you get a reference error for the Activity control, re-add the dll that is included in the zip.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9624847" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Template+Columns/default.aspx">Template Columns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataForm/default.aspx">DataForm</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/RIA+Services/default.aspx">RIA Services</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+3/default.aspx">Silverlight 3</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Validation/default.aspx">Validation</category></item><item><title>Silverlight 2 DataGrid December 2008 Release</title><link>http://blogs.msdn.com/scmorris/archive/2008/12/19/silverlight-2-datagrid-december-2008-release.aspx</link><pubDate>Fri, 19 Dec 2008 23:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9242893</guid><dc:creator>scmorris</dc:creator><slash:comments>18</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/9242893.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=9242893</wfw:commentRss><description>&lt;P&gt;Since we released the first version of the DataGrid in October we have been listening to your feedback and have an early holiday gift to give.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Today we are releasing an updated DataGrid that contains almost 30 fixes to the top issues that we heard, including:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Rows containing focus no longer disappear when the ItemsSource changes &lt;/LI&gt;
&lt;LI&gt;ComboBox and other controls opening a popup now work as expected when set as cell content&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;DataGrid Selection is preserved when sorting &lt;/LI&gt;
&lt;LI&gt;Buttons outside the DataGrid work as expected when they are clicked while the DataGrid is in editing mode &lt;/LI&gt;
&lt;LI&gt;Improved FrozenColumn behavior&lt;/LI&gt;
&lt;LI&gt;Improved cell currency&lt;/LI&gt;
&lt;LI&gt;SelectedItem is updated before the CurrentCellChanged event is raised&lt;/LI&gt;
&lt;LI&gt;Many more... &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;For the full list of fixes check out this &lt;A target=_blank href="http://silverlight.net/forums/t/59990.aspx" mce_href="http://silverlight.net/forums/t/59990.aspx"&gt;post by Brian Braeckel&lt;/A&gt; one of our DataGrid developers.&lt;/P&gt;
&lt;H4&gt;Breaking Changes&lt;/H4&gt;
&lt;P&gt;As a result of these fixes there are several behavioral breaking changes that you should consider before upgrading:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;FrozenColumnCount now takes hidden columns into account.&amp;nbsp; Previously, only the first columns with Visibility set to Visible were included in the range of frozen columns.&amp;nbsp; A column with Visibility set to Collapsed can now be considered frozen even though it isn’t visible.&amp;nbsp; This is to ensure that a column’s DisplayIndex corresponds with the DataGrid’s FrozenColumnCount (i.e. if FrozenColumnCount == 3, columns with DisplayIndex &amp;lt; 3 are considered frozen).&lt;/LI&gt;
&lt;LI&gt;The DataGrid’s current cell is now kept in sync with an ICollectionView’s notion of currency.&amp;nbsp; Moving the current position or changing the current item of an ICollectionView will now move the current cell and selected item of a DataGrid, and vice versa.&amp;nbsp; For this to work, the DataGrid’s ItemsSource must be set to a collection that fully implements ICollectionView.&lt;/LI&gt;
&lt;LI&gt;A developer can now programmatically reorder a non-frozen column to the frozen column range (and vice versa) by changing a column’s DisplayIndex.&amp;nbsp; The DataGrid used to throw an exception in these cases.&amp;nbsp; An end-user, however, is still unable to do this through the UI by dragging column headers.&lt;/LI&gt;&lt;/OL&gt;
&lt;H4&gt;Installation Instructions&lt;/H4&gt;
&lt;P&gt;Visit the &lt;A target=_blank href="http://www.microsoft.com/downloads/details.aspx?FamilyID=084a1bb2-0078-4009-94ee-e659c6409db0" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=084a1bb2-0078-4009-94ee-e659c6409db0"&gt;Silverlight 2 DataGrid December 2008 Release&lt;/A&gt; download page and follow the installation instructions carefully.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;In order to use the new DataGrid you need to do all of the following:&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Close all instances of Microsoft Visual Studio. &lt;/LI&gt;
&lt;LI&gt;Delete all cached toolbox items by removing all files beginning with "toolbox" from %LocalAppData%\Microsoft\VisualStudio\9.0. 
&lt;UL&gt;
&lt;LI&gt;On Microsoft Windows XP, %LocalAppData% is Documents and Settings\&lt;I&gt;UserName&lt;/I&gt;\Local Settings\Application Data. &lt;/LI&gt;
&lt;LI&gt;On Microsoft Windows Vista, %LocalAppData% is Users\&lt;I&gt;UserName&lt;/I&gt;\AppData\Local. &lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;Replace the following assemblies with the ones contained in the package in the link above: 
&lt;UL&gt;
&lt;LI&gt;%ProgramFiles%\Microsoft SDKs\Silverlight\v2.0\Libraries\Client\System.Windows.Controls.Data.dll &lt;/LI&gt;
&lt;LI&gt;%ProgramFiles%\Microsoft SDKs\Silverlight\v2.0\Libraries\Client\System.Windows.Controls.Data.Design.dll &lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;For any existing projects, delete the reference to System.Windows.Controls.Data.dll and then re-add the reference.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;We hope you enjoy the update and we look forward to bringing great new things to future versions of the DataGrid.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9242893" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Breaking+Changes/default.aspx">Breaking Changes</category></item><item><title>Freezing Columns in the Silverlight DataGrid</title><link>http://blogs.msdn.com/scmorris/archive/2008/10/15/freezing-columns-in-the-silverlight-datagrid.aspx</link><pubDate>Wed, 15 Oct 2008 11:47:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9000471</guid><dc:creator>scmorris</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/9000471.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=9000471</wfw:commentRss><description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;Freezing columns is just one of the many things you can do with the Silverlight DataGrid. &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx" target="_blank"&gt;Read more about the features that the Silverlight 2 DataGrid has to offer...&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Freezing Columns&lt;/h3&gt;  &lt;p&gt;Have you ever been working with a large enough number of columns that you get horizontal scrolling, but you want some of the columns to not scroll?&amp;#160; Think of a column such as Employee Name that you want to remain visible while you scroll through ten weeks of sales data.&amp;#160; You might want to see which employee had the best sales for week 4.&amp;#160; Since the Employee column is on the far left, any amount of scrolling causes it to scroll out of view, that is unless you freeze it.&amp;#160; This causes it to not scroll and always be visible putting your other data in context.&lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="286" alt="FrozenColumns" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/FreezingColumnsintheSilverlightDataGrid_1476/FrozenColumns_74cfdd55-a1fa-4b2e-a60d-66c6efd58332.png" width="504" border="0" /&gt; &lt;/p&gt;  &lt;p&gt;To freeze columns, you simply set the &lt;strong&gt;FrozenColumnCount&lt;/strong&gt; property on the DataGrid to the number of columns you want to freeze.&amp;#160; For instance, to freeze the Employee column pictured above, you would write:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="code"&gt;employeeSalesGrid.FrozenColumnCount = 1;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;EmployeeSalesGrid.FrozenColumnCount = 1&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;IsFrozen&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are programmatically working with a column and want to know if it is frozen or not, you can check the IsFrozen property on the Column.&amp;#160; This is a readonly property that will let you know if the column you are working with is frozen.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9000471" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Frozen+Columns/default.aspx">Frozen Columns</category></item><item><title>Post Beta 2 Breaking Changes</title><link>http://blogs.msdn.com/scmorris/archive/2008/10/15/post-beta-2-breaking-changes.aspx</link><pubDate>Wed, 15 Oct 2008 10:23:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9000420</guid><dc:creator>scmorris</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/9000420.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=9000420</wfw:commentRss><description>&lt;p&gt;As mentioned we made some changes, hopefully for the better, to the DataGrid API since Beta 2.&amp;#160; Special thanks to our developer Yifung Lin for compiling this list:&lt;/p&gt;  &lt;h3&gt;DataGrid breaking changes&lt;/h3&gt;  &lt;h4&gt;&lt;b&gt;DisplayMemberBinding renamed to Binding&lt;/b&gt;&lt;/h4&gt;  &lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;  &lt;h5&gt;Summary&lt;/h5&gt;  &lt;p&gt;DisplayMemberBinding wasn&amp;#8217;t an ideal name, but we used it because WPF has some precedence with it.&amp;#160; This breaks down in scenarios where there is a separate Binding for display like in ComboBox scenarios since our Binding is actually the property field binding as opposed to the display binding.&lt;/p&gt;  &lt;h5&gt;Fix Required&lt;/h5&gt;  &lt;p&gt;Users using DataGridBoundColumn will need to change DisplayMemberBinding to Binding.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;[Xaml]&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberBinding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;FirstName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[Xaml]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;FirstName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;DataGrid has VSM support&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;The DataGrid now supports the Visual State Manager.&lt;/p&gt;

&lt;h5&gt;&lt;strong&gt;Fix Required&lt;/strong&gt;&lt;/h5&gt;

&lt;p&gt;Custom DataGrid templates need to be updated.&amp;#160; The new templates can be found at: &lt;a href="http://msdn.microsoft.com/library/cc278066(vs.95).aspx"&gt;http://msdn.microsoft.com/library/cc278066(vs.95).aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;IEditableObject moved to System.ComponentModel namespace&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;In the full framework IEditableObject is part of the System.ComponentModel namespace and it is located in System.dll&amp;#160; For Silverlight, it was temporarily in the System.Windows.Controls.Data.dll under the System.Windows.Controls namespace.&amp;#160; It now&amp;#160; matches the full framework.&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;Users using IEditableObject need to update the namespace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Controls;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ComponentModel;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;SelectionChanged event changed from EventHandler to SelectionChangedEventHandler&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;Using SelectionChangedEventHandler allows the user to access OldItems and NewItems.&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;The signature for the SelectionChanged event handler needs to be updated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;SelectionChanged(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
{

}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;SelectionChanged(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;SelectionChangedEventArgs &lt;/span&gt;e)
{

}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h4&gt;
  &lt;p&gt;&lt;/p&gt;

  &lt;h4&gt;&amp;#160;&lt;/h4&gt;

  &lt;p&gt;&lt;/p&gt;
&lt;/h4&gt;

&lt;h4&gt;DataGridHeaders enum renamed to DataGridHeadersVisibility&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;DataGridHeadersVisibility is a better indication of what the enum is.&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;DataGridHeaders -&amp;gt; DataGridHeadersVisibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;dataGrid.HeadersVisibility = &lt;span style="color: #2b91af"&gt;DataGridHeaders&lt;/span&gt;.Column;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;dataGrid.HeadersVisibility = &lt;span style="color: #2b91af"&gt;DataGridHeadersVisibility&lt;/span&gt;.Column;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;DataGridAutoGeneratingColumnEventArgs change&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;The PropertyInfo of DataGridAutoGeneratingColumnEventArgs was changed to PropertyName and PropertyType.&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;Update to use PropertyName and PropertyType.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;name = e.Property.Name;
&lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;type = e.Property.Type;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;name = e.PropertyName;
&lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;type = e.PropertyType;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;DataGridColumn GenerateElement and GenerateEditingElement now take in the cell&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;GenerateElement and GenerateEditingElement now provide the containing cell&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;Update signature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;protected override &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;GenerateEditingElement(&lt;span style="color: blue"&gt;object &lt;/span&gt;dataItem)
{

}

&lt;span style="color: blue"&gt;protected override &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;GenerateElement(&lt;span style="color: blue"&gt;object &lt;/span&gt;dataItem)
{ 

}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;protected override &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;GenerateEditingElement(&lt;span style="color: #2b91af"&gt;DataGridCell &lt;/span&gt;cell, &lt;span style="color: blue"&gt;object &lt;/span&gt;dataItem)
{

}

&lt;span style="color: blue"&gt;protected override &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;GenerateElement(&lt;span style="color: #2b91af"&gt;DataGridCell &lt;/span&gt;cell, &lt;span style="color: blue"&gt;object &lt;/span&gt;dataItem)
{ 

}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;DataGridColumnReorderingEventArgs changed&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected:&lt;/strong&gt; Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;The following modifications were made to the DataGridColumnReorderingEventArgs:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Old&lt;/b&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public object &lt;/span&gt;DragIndicatorContent { &lt;span style="color: blue"&gt;get&lt;/span&gt;; set}
&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;DropLocationIndicator { &lt;span style="color: blue"&gt;get&lt;/span&gt;; set}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;b&gt;New&lt;/b&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Control &lt;/span&gt;DragIndicator { &lt;span style="color: blue"&gt;get&lt;/span&gt;; set}
&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Control &lt;/span&gt;DropLocationIndicator { &lt;span style="color: blue"&gt;get&lt;/span&gt;; set}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;Update to use DragIndicator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;dragIndicator = e.DragIndicatorContent;
&lt;span style="color: #2b91af"&gt;FrameworkElement &lt;/span&gt;dropIndicator = e.DropLocationIndicator;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;Control &lt;/span&gt;dragIndicator = e.DragIndicator;
&lt;span style="color: #2b91af"&gt;Control &lt;/span&gt;type = e.DropLocationIndicator;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;DataGrid.CancelingEdit and DataGrid.CommittingEdit events removed&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;Explicit Binding is required to implement these 2 events correctly.&amp;#160; Since the Silverlight Binding does not support explicit Bindings, these events were removed.&amp;#160; They will be resurrected when explicit Binding is supported.&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;The DataGrid.CancelingEdit and the DataGrid.CommittingEdit events can no longer be used.&amp;#160; It is recommended that you use IEditableObject to track when a commit has occurred.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;DataGrid.DataError event removed&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;The concept of a DataError event was taken from Winforms.&amp;#160; This does not fit well into the WPF model so the event was removed.&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;The DataGrid.DataError event can no longer be used.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;DataGridColumn.Header no longer supports visuals&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;Visuals cannot be duplicated so they cannot be used for the Header property due to column reordering.&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;To put visuals in column headers, users will need to use the header's ContentTemplate to include the visual instead of setting it as the Header.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[Xaml]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberBinding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;FirstName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn.Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;hello&amp;quot; /&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn.Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[Xaml]&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;LastName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;hello&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn.HeaderStyle&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dataprimitives:DataGridColumnHeader&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ContentTemplate&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn.HeaderStyle&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;Root element of DataGridRow changed from Grid to DataGridFrozenGrid&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected:&lt;/strong&gt; Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;DataGridFrozenGrid derives from Grid and it contains an IsFrozen attached property.&amp;#160; Users can use IsFrozen to specify parts of the Row that are frozen&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;Custom DataGridRow templates need to use DataGridFrozenGrid as the root element instead of Grid.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;Gridline renamed to GridLine&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected:&lt;/strong&gt; Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;Gridline would be appropriate if it was a word.&amp;#160; MS Word says it is, but the dictionary says it&amp;#8217;s not.&amp;#160; WPF has precedence with GridLine so we went with that.&lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;All instances of Gridline need to be renamed to GridLine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;dataGrid.GridlinesVisibility = &lt;span style="color: #2b91af"&gt;DataGridGridlinesVisibility&lt;/span&gt;.All;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;RTM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[c#]&lt;/p&gt;

&lt;pre class="code"&gt;dataGrid.GridLinesVisibility = &lt;span style="color: #2b91af"&gt;DataGridGridLinesVisibility&lt;/span&gt;.All;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;Template only controls moved to primitives namespace&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;These types moved from the System.Windows.Controls namespace to the System.Windows.Controls.Primitives namespace:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;DataGridCellsPresenter &lt;/li&gt;

  &lt;li&gt;DataGridColumnHeadersPresenter &lt;/li&gt;

  &lt;li&gt;DataGridDetailsPresenter &lt;/li&gt;

  &lt;li&gt;DataGridRowsPresenter &lt;/li&gt;

  &lt;li&gt;DataGridColumnHeader &lt;/li&gt;

  &lt;li&gt;DataGridRowHeader &lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;The types above need to be referenced using the System.Windows.Controls.Primitives namespace.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;b&gt;DataGridCheckBoxColumn.Content was removed&lt;/b&gt;&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Who Is Affected: &lt;/strong&gt;Silverlight 2 Beta 2 managed applications that use the DataGrid.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;The Content property was not useful for mainline scenarios so it was removed. &lt;/p&gt;

&lt;h5&gt;Fix Required&lt;/h5&gt;

&lt;p&gt;The DataGridCheckBoxColumn.Content property can no longer be used.&amp;#160; In rare scenarios where it is needed, users can template the CheckBox through ElementStyle and EditingElementStyle&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9000420" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Breaking+Changes/default.aspx">Breaking Changes</category></item><item><title>Silverlight 2 DataGrid is Released</title><link>http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx</link><pubDate>Wed, 15 Oct 2008 09:43:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9000390</guid><dc:creator>scmorris</dc:creator><slash:comments>21</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/9000390.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=9000390</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2008/10/14/silverlight-2-released.aspx" target="_blank"&gt;As you might have heard&lt;/a&gt;, we just released &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;Silverlight 2&lt;/a&gt;, and with it the first version of the Silverlight DataGrid!&amp;#160; We have been building this for a while, giving the first glimpse of it last March in Silverlight 2 Beta 1, and tweaking it ever since based on your feedback.&amp;#160; We were able to pack a lot of great features into it, and I look forward to hearing from you what features you want next!&amp;#160; &lt;/p&gt;  &lt;p&gt;In celebration of its release, all of the &lt;a href="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx" target="_blank"&gt;previous walkthroughs&lt;/a&gt; have been updated to work with the RTW bits, and new walkthroughs are on their way.&amp;#160; &lt;/p&gt;  &lt;p&gt;Also, if you have never used the Silverlight DataGrid before, &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx" target="_blank"&gt;here is a good place to start&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;What's New?&lt;/h3&gt;  &lt;p&gt;You might be wondering what has changed since Beta 2:&lt;/p&gt;  &lt;table width="100%"&gt;&lt;tbody&gt;     &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="172" alt="Automation" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Automation_6e110932-8a7c-49c1-937d-19738ae80695.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Accessibility: &lt;/h4&gt;          &lt;p&gt;One of the biggest features that we have added since Beta 2 is the addition of an automation peer framework which allows the DataGrid to work well with screen readers.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="VSM" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/VSM_0b87db00-ad2f-4a15-816c-31009eab0d9a.png" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Support for the VSM: &lt;/h4&gt;          &lt;p&gt;The Visual State Manager (VSM) is a tool that allows designers to customize how a control looks in various states, and the animations used to switch between these states.&lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/expression/archive/2008/07/11/more-articles-on-visual-state-manager.aspx" target="_blank"&gt;Read more about the Visual State Manager...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Performance" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Performance_9c404d48-3526-468a-a786-78787e8426b2.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Performance, Performance, Performance:&lt;/h4&gt;          &lt;p&gt;We have done a lot in this area to try to get the DataGrid running as fast as possible. If the last time you used it was in Beta 1 or even Beta 2, you should definitely take another look. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 5px 10px 10px 0px; border-right-width: 0px" height="179" alt="API" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/API_823651ff-5015-4b74-81d8-acb4af779c64.png" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;API Improvements: &lt;/h4&gt;          &lt;p&gt;Based on your feedback, we took another pass through the API in an effort to simplify it more and give you more control over the DataGrid.&lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/15/post-beta-2-breaking-changes.aspx"&gt;Read about the Breaking Changes since Beta 2...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="NewLook" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/NewLook_7a03c298-9617-4f06-a031-deb31c6ae7a2.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Great New Look: &lt;/h4&gt;          &lt;p&gt;The entire framework got a visual upgrade since Beta 2, and the DataGrid is no exception.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h3&gt;What's Else Can It Do?&lt;/h3&gt;  &lt;p&gt;For those of you new to the Silverlight DataGrid, here is a quick rundown of what it could already do:&lt;/p&gt;  &lt;table&gt;&lt;tbody&gt;     &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="AutoSized" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/AutoSized_e44a613e-8c5e-4f25-b20e-795402123c8c.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Auto-sizing: &lt;/h4&gt;          &lt;p&gt;Everything in the DataGrid can be auto-sized.&amp;#160; That includes the DataGrid itself, Columns, Rows, Headers, and Row Details meaning that you do not have to worry about the size of what you are putting into the DataGrid, it will grow to accommodate it. &lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/06/10/auto-sizing-the-silverlight-datagrid.aspx" target="_blank"&gt;Read more about Auto-sizing...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="NewLook" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/NewLook_7a03c298-9617-4f06-a031-deb31c6ae7a2.jpg" width="129" border="0" /&gt;&lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Sorting:&lt;/h4&gt;          &lt;p&gt;Any time you bind the DataGrid to a collection that implements IList such as a List&amp;lt;T&amp;gt; you now get sorting for free.&amp;#160; Even better, sorting isn't limited to a single column, but end users can sort by multiple columns by holding Shift and clicking on additional column headers. As an RTM improvement, you can also choose which columns you want to support sorting. &lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/06/10/sorting-data-in-the-silverlight-datagrid.aspx" target="_blank"&gt;Read more about Sorting...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Reorder" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Reorder_6f7d9d77-5d26-42ff-b902-db9b42c4545c.jpg" width="129" border="0" /&gt;&amp;#160;&lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;&lt;strong&gt;Column Reordering:&lt;/strong&gt; &lt;/h4&gt;          &lt;p&gt;End users can reorder columns at runtime just by dragging a column's header, and developers can control not only the order, but the appearance of the reordering UI as well as the behavior. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Resize" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Resize_47ad8959-cc35-4692-ba31-1e6071c20500.jpg" width="129" border="0" /&gt;&lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Column Resizing:&lt;/h4&gt;          &lt;p&gt;Just like reordering, and sorting, end users can control the size of columns at runtime. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="FrozenColumns" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/FrozenColumns_88b4d009-55d1-4d33-bb3f-6ac4d82c9a34.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Frozen Columns: &lt;/h4&gt;          &lt;p&gt;This is a semi-advanced feature, but once you know about it you'll be surprised at how useful it can be.&amp;#160; A frozen column does not scroll horizontally but rather is &amp;quot;frozen&amp;quot; in place.&amp;#160; This is the same as the Freeze Column feature in Excel. &lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/15/freezing-columns-in-the-silverlight-datagrid.aspx" target="_blank"&gt;Read more about Freezing Columns...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="RowDetails" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/RowDetails_4756094e-f1fb-47c8-9b28-d2ffd9d5568b.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Row Details:&lt;/h4&gt;          &lt;p&gt;This feature is one that we are very excited about.&amp;#160; In short, it is an area in each row that allows you to put any UI you want that spans all columns.&amp;#160; This could be anything from form-based entry to the contents of a column that would do better if given more space. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="AutoGeneration" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/AutoGeneration_f9a4fdae-ca3b-4a43-a0e6-f4f2e5095f00.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Auto-Generation of Columns: &lt;/h4&gt;          &lt;p&gt;A great feature to help get an application up and running quickly, auto-generation of columns creates a column for every property on the item that it is bound to. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Skinnable" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Skinnable_7ef3c20c-c8d0-4e06-8011-c91ea20312f1.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Highly Customizable Visuals: &lt;/h4&gt;          &lt;p&gt;The look of the Silverlight 2 DataGrid has been improved, but it doesn't mean that you can't change it.&amp;#160; Every aspect of the DataGrid's appearance can be retemplated to create a drastically different looking DataGrid that maintains all of the great features listed here. &lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/corrinab/archive/tags/Control+Skins/default.aspx" target="_blank"&gt;Read more about Customizing Control Visuals...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Edit" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Edit_bda5e11f-8a67-4069-924f-8622238b3265.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Editable: &lt;/h4&gt;          &lt;p&gt;The DataGrid control allows your users to edit the data that it is bound to.&amp;#160; One benefit of the Silverlight DataGrid is that it gives you control over what control is used to display the data for each cell, and what control is used to edit the data for each cell even if they are different.&amp;#160; The customization is easy, and it handles switching between the two when the user wants to go into edit mode. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Scrollable" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Scrollable_84ca9a5d-bc1a-4a2d-b661-86228676f592.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Scrollable: &lt;/h4&gt;          &lt;p&gt;Another benefit that the DataGrid provides is the ability to scroll through long lists of data.&amp;#160; The DataGrid does a lot behind the scenes to make this experience as smooth as possible for your users even when you have a large number of rows.&amp;#160; You can also scroll columns and items into view to make sure that an item you want to highlight to your user is visible on screen. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="MultiSelect" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/MultiSelect_a1331575-053a-42c2-92e9-ba14cf240c67.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Multi-Selection:&lt;/h4&gt;          &lt;p&gt;The DataGrid provides both single as well as extended selection modes, allowing you to choose if you want users to be able to select more than one row at a time &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="ColumnTypes" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/ColumnTypes_b1abe567-c622-478b-9f89-1078b06cb815.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Built-in Column Types: &lt;/h4&gt;          &lt;p&gt;Out of the box you can use both Text columns as well as CheckBox columns, and creating your own column types is easy.&lt;/p&gt;          &lt;p&gt;Read more about using the Built-in Column Types:&lt;/p&gt;          &lt;ul&gt;           &lt;li&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx" target="_blank"&gt;In XAML&lt;/a&gt; &lt;/li&gt;            &lt;li&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx" target="_blank"&gt;In Code Behind at Runtime&lt;/a&gt; &lt;/li&gt;         &lt;/ul&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 0px 0px; border-right-width: 0px" height="179" alt="TemplateColumn" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/TemplateColumn_99a53b6c-8bc3-46e3-a02a-c517f8d70884.jpg" width="129" border="0" /&gt;&lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Template Column:&lt;/h4&gt;          &lt;p&gt;In addition to the built-in column types, the template column gives you complete control of what to show during display and edit modes.&lt;/p&gt;          &lt;p&gt;Read more about using the Template Column:&lt;/p&gt;          &lt;ul&gt;           &lt;li&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx#template" target="_blank"&gt;In XAML&lt;/a&gt; &lt;/li&gt;            &lt;li&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx#template" target="_blank"&gt;In Code Behind at Runtime&lt;/a&gt; &lt;/li&gt;         &lt;/ul&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9000390" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Template+Columns/default.aspx">Template Columns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/AutoGenerateColumns/default.aspx">AutoGenerateColumns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Links/default.aspx">Links</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Sorting/default.aspx">Sorting</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Auto-sizing/default.aspx">Auto-sizing</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Row+Details/default.aspx">Row Details</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Frozen+Columns/default.aspx">Frozen Columns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Column+Resizing/default.aspx">Column Resizing</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/VSM/default.aspx">VSM</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Column+Reordering/default.aspx">Column Reordering</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Breaking+Changes/default.aspx">Breaking Changes</category></item><item><title>Sorting Data in the Silverlight DataGrid</title><link>http://blogs.msdn.com/scmorris/archive/2008/06/10/sorting-data-in-the-silverlight-datagrid.aspx</link><pubDate>Tue, 10 Jun 2008 11:11:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8589313</guid><dc:creator>scmorris</dc:creator><slash:comments>23</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/8589313.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=8589313</wfw:commentRss><description>&lt;table cellspacing="0" cellpadding="5" width="100%" bgcolor="#fff8c9" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;This post has been updated to work with the &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;RTW version of the Silverlight 2 DataGrid&lt;/a&gt;.&amp;#160; The code examples are not guaranteed to work with previous Beta versions of the DataGrid. &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx" target="_blank"&gt;Read more about the features that the Silverlight 2 DataGrid has to offer...&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h4&gt;Multi-column Sorting&lt;/h4&gt;  &lt;p&gt;One of the most requested features in Beta 1 was a way to sort the data contained in the DataGrid.&amp;#160; In fact it was so desired that clever developers such as &lt;a href="http://mattberseth.com/" target="_blank"&gt;Matt Berseth&lt;/a&gt; simply &lt;a href="http://mattberseth.com/blog/2008/03/sorting_with_silverlight_2s_da.html" target="_blank"&gt;created their own implementation&lt;/a&gt;.&amp;#160; Fortunately, you no longer have to put much work into getting this functionality out of the box.&amp;#160; &lt;/p&gt;  &lt;p&gt;To get sorting functionality in your DataGrid you will need to perform the following steps:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Make sure that the collection that you use as the DataGrid's ItemsSource implements IList.&amp;#160; Common implementations are List&amp;lt;T&amp;gt; and ObservableCollection&amp;lt;T&amp;gt;.&amp;#160; &lt;/li&gt;    &lt;li&gt;That's it, you don't need to do anything else &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Why this odd requirement?&amp;#160; Under the covers, when a DataGrid is data bound to a collection that implements IList, it creates an internal ListCollectionView to provide the sorting functionality.&amp;#160; Since CollectionViews can handle multiple levels of sorting, the DataGrid also possesses this functionality and exposes it by allowing your users to click on multiple headers while holding the Shift key. &lt;/p&gt;  &lt;p&gt;Here is the DataGrid showing off multi-column sorting:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="284" alt="MultiColumnSort" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/SortingDataintheSilverlightDataGrid_C2F5/MultiColumnSort_f6a82498-f6c9-4f56-b306-a3c8d83b60f9.png" width="484" border="0" /&gt; &lt;/p&gt;  &lt;h4&gt;Customizing Sorting&lt;/h4&gt;  &lt;p&gt;Alternatively if you want more control over how the sorting algorithm is performed, you can implement the ICollectionView interface currently found in System.Windows.Controls.Data.&amp;#160; The DataGrid knows that when it is bound to an implementation of ICollectionView that it should delegate all sorting to it, listening to its SortDescriptions collection and visually displaying the sorting status of the CollectionView.&amp;#160; Additionally by using an external CollectionView, you can have multiple controls share the same sort order.&lt;/p&gt;  &lt;h5&gt;Turning Off Sorting&lt;/h5&gt;  &lt;p&gt;It is easy to get sorting out of the box, but you might not want to allow your DataGrid or a particular column to be sorted by your user.&amp;#160; To turn this off, use DataGrid's CanUserSortColumns property to turn on or off all sorting at the DataGrid level, or use DataGridColumn's CanUserSort to turn on or off sorting for a particular column.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="code"&gt;dataGrid1.CanUserSortColumns = &lt;span style="color: blue"&gt;false&lt;/span&gt;;&lt;/pre&gt;

&lt;pre class="code"&gt;unsortableColumn.CanUserSort = &lt;span style="color: blue"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;DataGrid1.CanUserSortColumns = &lt;span style="color: blue"&gt;False&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;UnsortableColumn.CanUserSort = &lt;span style="color: blue"&gt;False&lt;/span&gt;&lt;/pre&gt;

&lt;h5&gt;Choosing Which Property to Sort By&lt;/h5&gt;

&lt;p&gt;Sometimes the property that your column is bound to is not always the one that you want it to sort by.&amp;#160; Normally a column sorts by the property that it is bound to through the Binding property.&amp;#160; However, if you look at the Template Column there is no Binding property, meaning that the DataGrid has no idea of how to sort the data if you were to click on that column's header.&amp;#160; To give the DataGrid that information, you can use a property found on all column types called SortMemberPath.&amp;#160; This property allows you to specify a path to the property on the data item that you want that particular column to sort by.&amp;#160; Now if you create a template column that uses a DatePicker to allow your user to select a date instead of the standard TextBox, you can still provide sorting for that column by setting the SortMemberPath.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;datePickerColumn.SortMemberPath = &lt;span style="color: #a31515"&gt;&amp;quot;Birthday&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;DatePickerColumn.SortMemberPath = &lt;span style="color: #a31515"&gt;&amp;quot;Birthday&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Notice that since SortMemberPath is on DataGridColumn, you can use this beyond just template columns and can actually have a column bound to one property, but sort based on another property.&amp;#160; This is a much less common scenario, but becomes useful when working with types that normally don't support sorting such as Colors or Images.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sorting UI Cues&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the picture above you can see that each sorted column has an arrow in its header indicating if it is sorted ascending or descending.&amp;#160; It also has a subtle animation when switching between the two.&amp;#160; If you want to customize how this looks or behaves, the easiest way to do this is to use the Visual State Manager in Blend.&amp;#160; Otherwise, you can manually override the &lt;a href="http://msdn.microsoft.com/library/cc278066(vs.95).aspx" target="_blank"&gt;default DataGridColumnHeader template&lt;/a&gt; using the DataGrid.ColumnHeaderStyle property.&amp;#160; The template contains two storyboards, one named &amp;quot;SortAscending&amp;quot; and the other named &amp;quot;SortDescending&amp;quot;.&amp;#160; These two storyboards are ran by the DataGrid when a column is sorted ascending or descending.&amp;#160; Finally there is a third storyboard called &amp;quot;Unsorted&amp;quot; that is ran when the data is no longer being sorted by that column and can be used to clean up any UI that you used to display sort status.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8589313" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Sorting/default.aspx">Sorting</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category></item><item><title>Auto-sizing the Silverlight DataGrid</title><link>http://blogs.msdn.com/scmorris/archive/2008/06/10/auto-sizing-the-silverlight-datagrid.aspx</link><pubDate>Tue, 10 Jun 2008 11:09:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8589307</guid><dc:creator>scmorris</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/8589307.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=8589307</wfw:commentRss><description>&lt;table cellspacing="0" cellpadding="5" width="100%" bgcolor="#fff8c9" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;This post has been updated to work with the &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;RTW version of the Silverlight 2 DataGrid&lt;/a&gt;.&amp;#160; The code examples are not guaranteed to work with previous Beta versions of the DataGrid. &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx" target="_blank"&gt;Read more about the features that the Silverlight 2 DataGrid has to offer...&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h4&gt;Auto-sizing the DataGrid&lt;/h4&gt;  &lt;p&gt;The Silverlight 2 DataGrid is auto-sized by default.&amp;#160; This means that if you put it in a Canvas or a StackPanel and don't specify a Height or Width, or a MaxHeight or MaxWidth, you will get a DataGrid that is sized to its contents.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;Warning:&lt;/em&gt; &lt;/strong&gt;This can be dangerous however if you are working with a large (1000+ item) collection as the ItemsSource.&amp;#160; Since the DataGrid will grow to the size of its contents, and will create objects for each cell that it can show based on its height, it will literally create thousands of objects to display all of the data.&amp;#160; As you can guess this has app performance implications so you should avoid the combination of an auto-sized DataGrid and a large amount of data to display.&amp;#160; This isn't an issue of course if you specify a Height or MaxHeight for the DataGrid, or put it in a container such as a Grid that provides it with a size.&lt;/p&gt;  &lt;p&gt;Since the default size for the DataGrid is auto you won't have write any code to get auto-sizing behavior, but if you do give the DataGrid a height or width, and then want to switch it back to auto-size at runtime, simply set that value to double.NaN which is WPF and Silverlight's way of having a FrameworkElement auto-size itself.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="code"&gt;dataGrid1.Height = &lt;span style="color: blue"&gt;double&lt;/span&gt;.NaN;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;DataGrid1.Height = &lt;span style="color: blue"&gt;Double&lt;/span&gt;.NaN&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h4&gt;Auto-sizing Columns and Rows&lt;/h4&gt;

&lt;p&gt;In addition to the DataGrid auto-sizing itself, Columns and Rows are also auto-sized by default.&amp;#160; Like the DataGrid, rows are auto-sized in the same manner by setting the value to double.NaN while columns on the other hand are done slightly differetly.&amp;#160; If you have ever worked with the Grid control, you might have noticed that the Width property of its ColumnDefinitions is not of type double, but rather a struct called GridLength.&amp;#160; The reason for this is that unlike a FrameworkElement's Width or Height properties which only have the possible values of Auto or a numeric value, a ColumnDefinition's Width can be set to a numeric value, Auto, or Star.&amp;#160; DataGridColumn.Width follows a similar pattern where instead of being of type double, it is of type DataGridLength.&lt;/p&gt;

&lt;p&gt;The possible values for DataGridLenth are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Auto: &lt;/strong&gt;This auto-sizes the column or row to grow to the size of the largest header &lt;em&gt;or &lt;/em&gt;cell.&amp;#160; It is effectively a combination of the other two auto-size modes.&amp;#160; You might notice as you scroll when a new larger cell is encountered that this value increases.&amp;#160; It will however not decrease once that item is scrolled out of view. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;SizeToHeader: &lt;/strong&gt;This auto-sizes the column or row the grow to the size of the header.&amp;#160; This will ignore the contents of the cells when determining its size and will not change unless the size of the header changes. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;SizeToCells: &lt;/strong&gt;This auto-sizes the column or row to grow to the size of the largest visible cell.&amp;#160; It will ignore the header cell in this calculation.&amp;#160; You might notice as you scroll when a new larger cell is encountered that this value increases.&amp;#160; It will however not decrease once that item is scrolled out of view. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Numeric: &lt;/strong&gt;Unlike the others this is not an enum value, but rather simply a numeric value such as 100.&amp;#160; This mode will behave the same way that Beta 1 did, however setting it in code behind is slightly different. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Setting these in XAML is straight forward other than that unfortunately just like GridLength, there is no Intellisense for the enum values since a number is a valid entry as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;XAML&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dataGrid1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
            &lt;/span&gt;&lt;span style="color: red"&gt;&lt;strong&gt;Width&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;=&amp;quot;Auto&amp;quot;&lt;/strong&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Auto&amp;quot;/&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
            &lt;/span&gt;&lt;span style="color: red"&gt;&lt;strong&gt;Width&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;=&amp;quot;SizeToHeader&amp;quot;&lt;/strong&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Size to Header&amp;quot;/&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
            &lt;/span&gt;&lt;span style="color: red"&gt;&lt;strong&gt;Width&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;=&amp;quot;SizeToCells&amp;quot;&lt;/strong&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Size to Cells&amp;quot;/&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
           &lt;strong&gt; &lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&lt;strong&gt;Width&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;=&amp;quot;50&amp;quot;&lt;/strong&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Numeric&amp;quot;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you were to run the code above and give it a data source it would look something like this:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="269" alt="AutoSizedColumns" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/AutosizingtheSilverlightDataGrid_C008/AutoSizedColumns_08c61a74-eede-45e3-9947-28fda55f5223.png" width="384" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;As you can see, once you know the possible enum values, setting it in XAML is fairly simple, and the Beta 1 code of Width=&amp;quot;100&amp;quot; just works.&amp;#160; When you are working in code behind however things get slightly more tricky. &lt;/p&gt;

&lt;p&gt;If you wanted to write code to do the same as above:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;DataGrid &lt;/span&gt;dataGrid1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGrid&lt;/span&gt;();
dataGrid1.AutoGenerateColumns = &lt;span style="color: blue"&gt;false&lt;/span&gt;;

&lt;span style="color: #2b91af"&gt;DataGridTextColumn &lt;/span&gt;col1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridTextColumn&lt;/span&gt;();
col1.Binding = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binding&lt;/span&gt;();
&lt;strong&gt;col1.Width = &lt;span style="color: #2b91af"&gt;DataGridLength&lt;/span&gt;.Auto;
&lt;/strong&gt;col1.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Auto&amp;quot;&lt;/span&gt;;
dataGrid1.Columns.Add(col1);
&lt;span style="color: #2b91af"&gt;DataGridTextColumn &lt;/span&gt;col2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridTextColumn&lt;/span&gt;();
col2.Binding = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binding&lt;/span&gt;();
&lt;strong&gt;col2.Width = &lt;span style="color: #2b91af"&gt;DataGridLength&lt;/span&gt;.SizeToHeader;
&lt;/strong&gt;col2.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Size to Header&amp;quot;&lt;/span&gt;;
dataGrid1.Columns.Add(col2);
&lt;span style="color: #2b91af"&gt;DataGridTextColumn &lt;/span&gt;col3 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridTextColumn&lt;/span&gt;();
col3.Binding = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binding&lt;/span&gt;();
&lt;strong&gt;col3.Width = &lt;span style="color: #2b91af"&gt;DataGridLength&lt;/span&gt;.SizeToCells;&lt;/strong&gt;
col3.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Size to Cells&amp;quot;&lt;/span&gt;;
dataGrid1.Columns.Add(col3);
&lt;span style="color: #2b91af"&gt;DataGridTextColumn &lt;/span&gt;col4 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridTextColumn&lt;/span&gt;();
col4.Binding = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binding&lt;/span&gt;();
&lt;strong&gt;col4.Width = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridLength&lt;/span&gt;(50);
&lt;/strong&gt;col4.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Numeric&amp;quot;&lt;/span&gt;;
dataGrid1.Columns.Add(col4);

dataGrid1.ItemsSource = &lt;span style="color: #a31515"&gt;&amp;quot;a b c d e f g h i j&amp;quot;&lt;/span&gt;.Split();
LayoutRoot.Children.Add(dataGrid1);&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;dataGrid1 &lt;span style="color: blue"&gt;As New &lt;/span&gt;DataGrid
dataGrid1.AutoGenerateColumns = &lt;span style="color: blue"&gt;False

Dim &lt;/span&gt;col1 &lt;span style="color: blue"&gt;As New &lt;/span&gt;DataGridTextColumn
col1.Binding = &lt;span style="color: blue"&gt;New &lt;/span&gt;Binding
&lt;strong&gt;col1.Width = DataGridLength.Auto&lt;/strong&gt;
col1.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Auto&amp;quot;
&lt;/span&gt;dataGrid1.Columns.Add(col1)
&lt;span style="color: blue"&gt;Dim &lt;/span&gt;col2 &lt;span style="color: blue"&gt;As New &lt;/span&gt;DataGridTextColumn
col2.Binding = &lt;span style="color: blue"&gt;New &lt;/span&gt;Binding
&lt;strong&gt;col2.Width = DataGridLength.SizeToHeader
&lt;/strong&gt;col2.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Size to Header&amp;quot;
&lt;/span&gt;dataGrid1.Columns.Add(col2)
&lt;span style="color: blue"&gt;Dim &lt;/span&gt;col3 = &lt;span style="color: blue"&gt;New &lt;/span&gt;DataGridTextColumn
col3.Binding = &lt;span style="color: blue"&gt;New &lt;/span&gt;Binding
col3.Width = DataGridLength.SizeToCells
col3.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Size to Cells&amp;quot;
&lt;/span&gt;dataGrid1.Columns.Add(col3)
&lt;span style="color: blue"&gt;Dim &lt;/span&gt;col4 = &lt;span style="color: blue"&gt;New &lt;/span&gt;DataGridTextColumn
col4.Binding = &lt;span style="color: blue"&gt;New &lt;/span&gt;Binding
&lt;strong&gt;col4.Width = &lt;span style="color: blue"&gt;New &lt;/span&gt;DataGridLength(50)
&lt;/strong&gt;col4.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Numeric&amp;quot;
&lt;/span&gt;dataGrid1.Columns.Add(col4)

dataGrid1.ItemsSource = &lt;span style="color: #a31515"&gt;&amp;quot;a b c d e f g h i j&amp;quot;&lt;/span&gt;.Split()
LayoutRoot.Children.Add(dataGrid1)&lt;/pre&gt;

&lt;p&gt;The interesting line above is where the Numeric column's width is set to 50.&amp;#160; There are two ways to do this.&amp;#160; If you are working with doubles, you can create a new GridLength that takes a double in its constructor.&amp;#160; This is the most common and the easiest way to do it.&amp;#160; If however you are working with strings such as a value in a TextBox, you can use the ConvertFrom method on DataGridLengthConverter which takes an object and returns a GridLength.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8589307" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Auto-sizing/default.aspx">Auto-sizing</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category></item><item><title>What's New in the Silverlight DataGrid in Beta 2</title><link>http://blogs.msdn.com/scmorris/archive/2008/06/10/what-s-new-in-the-silverlight-datagrid-in-beta-2.aspx</link><pubDate>Tue, 10 Jun 2008 11:07:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8589303</guid><dc:creator>scmorris</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/8589303.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=8589303</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;Silverlight 2 Beta 2&lt;/a&gt; was released this weekend, see what ScottGu has to say about it &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/06/06/silverlight-2-beta2-released.aspx" target="_blank"&gt;here&lt;/a&gt;.&amp;#160; We've all been pretty busy since releasing Beta 1 at MIX, and there are a lot of great new features across the product as a result.&amp;#160; The question that you might be asking is what has changed in the DataGrid?&amp;#160; Check out this list of new features and their associated posts to find out.&lt;/p&gt;  &lt;h4&gt;New Features Overview&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/06/10/auto-sizing-the-silverlight-datagrid.aspx" target="_blank"&gt;Auto-sizing:&lt;/a&gt;&lt;/strong&gt; Unlike Beta 1 when you had to specify widths and heights yourself, everything in the DataGrid now can be auto-sized.&amp;#160; That includes the DataGrid itself, Columns, Rows, Headers, and Row Details. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/06/10/sorting-data-in-the-silverlight-datagrid.aspx" target="_blank"&gt;Sorting:&lt;/a&gt;&lt;/strong&gt; Now any time you bind the DataGrid to a collection that implements IList such as a List&amp;lt;T&amp;gt; you now get sorting for free.&amp;#160; Even better sorting isn't limited to a single column, but end users can sort by multiple columns by holding Ctrl and clicking on additional column headers. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Column Reordering:&lt;/strong&gt; In Beta 1 the order of columns could be set programmatically, but now in Beta 2 we have extended this capability to the end user, where column reordering can be performed at runtime just by dragging a column's header. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Frozen Columns: &lt;/strong&gt;This is a semi-advanced feature, but once you know about it you'll be surprised at how useful it can be.&amp;#160; A frozen column does not scroll horizontally but rather is &amp;quot;frozen&amp;quot; in place.&amp;#160; This is the same as the Freeze Column feature in Excel. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Programmatic Scrolling: &lt;/strong&gt;Now you can scroll columns and items into view to make sure that an item you want to highlight to your user is visible on screen. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Performance Enhancements:&lt;/strong&gt; One of the big points of feedback we got in Beta 1 was vertical scrolling speed needed to be faster.&amp;#160; We've made some improvements in this space to speed things up. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;API Improvements:&lt;/strong&gt; These are changes that we made to existing API's to try to make using the DataGrid easier.&amp;#160; Hopefully they are all for the better, and we would love to hear your feedback if you think that something could be easier. &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8589303" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Links/default.aspx">Links</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Sorting/default.aspx">Sorting</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Beta+2/default.aspx">Beta 2</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Auto-sizing/default.aspx">Auto-sizing</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category></item><item><title>Defining Silverlight DataGrid Columns at Runtime</title><link>http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx</link><pubDate>Tue, 15 Apr 2008 01:25:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8395118</guid><dc:creator>scmorris</dc:creator><slash:comments>34</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/8395118.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=8395118</wfw:commentRss><description>&lt;table cellspacing="0" cellpadding="5" width="100%" bgcolor="#fff8c9" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;This post has been updated to work with the &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;RTW version of the Silverlight 2 DataGrid&lt;/a&gt;.&amp;#160; The code examples are not guaranteed to work with previous Beta versions of the DataGrid. &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx" target="_blank"&gt;Read more about the features that the Silverlight 2 DataGrid has to offer...&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Now that you know the &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx" target="_blank"&gt;basics of the Silverlight DataGrid&lt;/a&gt; and how to &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx" target="_blank"&gt;specify the Columns in XAML&lt;/a&gt;, you might want to customize your DataGrid's columns at runtime.&lt;/p&gt;  &lt;p&gt;This process is pretty straight forward, so instead of doing the usual end-to-end walk through, I'm going to provide you with a Rosetta Stone between the static XAML form and the dynamic C#/VB form for &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx" target="_blank"&gt;the scenario in the last post&lt;/a&gt;.&lt;/p&gt;  &lt;h4&gt;Defining a DataGrid&lt;/h4&gt;  &lt;p&gt;For any of these columns to be useful you are going to first need a DataGrid to add them to.&amp;#160; The following creates a DataGrid, adds it as a child of the root layout Grid, and sets its ItemsSource to a collection called &amp;quot;source&amp;quot;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;DataGrid &lt;/span&gt;targetDataGrid = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGrid&lt;/span&gt;();
targetDataGrid.ItemsSource = source;
targetDataGrid.AutoGenerateColumns = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
LayoutRoot.Children.Add(targetDataGrid);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;TargetDataGrid &lt;span style="color: blue"&gt;As New &lt;/span&gt;DataGrid
TargetDataGrid.ItemsSource = Source
TargetDataGrid.AutoGenerateColumns = &lt;span style="color: blue"&gt;False&lt;/span&gt;
LayoutRoot.Children.Add(TargetDataGrid)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h4&gt;&amp;#160;&lt;/h4&gt;

&lt;h4&gt;Defining a DataGrid Text Column&lt;/h4&gt;

&lt;p&gt;The following creates a DataGridTextColumn bound to the FirstName property with a header of &amp;quot;First Name&amp;quot;, and adds it to the columns collection of the DataGrid named &amp;quot;targetDataGrid&amp;quot;.&lt;/p&gt;

&lt;h5&gt;Static&lt;/h5&gt;

&lt;pre class="code"&gt; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;targetDataGrid&amp;quot;&amp;gt;
     &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
         &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First Name&amp;quot; 
             &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;FirstName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
     &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h5&gt;Dynamic&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Data;&lt;/pre&gt;

&lt;pre class="code"&gt;...&lt;span style="color: #2b91af"&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;DataGridTextColumn &lt;/span&gt;textColumn = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridTextColumn&lt;/span&gt;();
textColumn.Header = &lt;span style="color: #a31515"&gt;&amp;quot;First Name&amp;quot;&lt;/span&gt;;
textColumn.Binding = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binding&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;);
targetDataGrid.Columns.Add(textColumn);&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Data&lt;/pre&gt;

&lt;pre class="code"&gt;...&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;TextColumn &lt;span style="color: blue"&gt;As New &lt;/span&gt;DataGridTextColumn
TextColumn.Header = &lt;span style="color: #a31515"&gt;&amp;quot;First Name&amp;quot;
&lt;/span&gt;TextColumn.Binding = &lt;span style="color: blue"&gt;New &lt;/span&gt;Binding(&lt;span style="color: #a31515"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;)
TargetDataGrid.Columns.Add(TextColumn)&lt;/pre&gt;

&lt;h4&gt;&amp;#160;&lt;/h4&gt;

&lt;h4&gt;Defining a DataGrid CheckBox Column&lt;/h4&gt;

&lt;p&gt;The following creates a DataGridCheckColumn bound to the Available property with a header of &amp;quot;Available&amp;quot;, and adds it to the columns collection of the DataGrid named &amp;quot;targetDataGrid&amp;quot;.&lt;/p&gt;

&lt;h5&gt;Static&lt;/h5&gt;

&lt;pre class="code"&gt; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;targetDataGrid&amp;quot;&amp;gt;
     &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
         &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridCheckBoxColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Available &amp;quot; 
             &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Available&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
     &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h5&gt;Dynamic&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Data;&lt;/pre&gt;

&lt;pre class="code"&gt;...&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;DataGridCheckBoxColumn &lt;/span&gt;checkBoxColumn = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridCheckBoxColumn&lt;/span&gt;();
checkBoxColumn.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Available&amp;quot;&lt;/span&gt;;
checkBoxColumn.Binding = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Binding&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Available&amp;quot;&lt;/span&gt;);
targetDataGrid.Columns.Add(checkBoxColumn);&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Data&lt;/pre&gt;

&lt;pre class="code"&gt;...&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;CheckBoxColumn &lt;span style="color: blue"&gt;As New &lt;/span&gt;DataGridCheckBoxColumn
CheckBoxColumn.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Available&amp;quot;
&lt;/span&gt;CheckBoxColumn.Binding = &lt;span style="color: blue"&gt;New &lt;/span&gt;Binding(&lt;span style="color: #a31515"&gt;&amp;quot;Available&amp;quot;&lt;/span&gt;)
TargetDataGrid.Columns.Add(CheckBoxColumn)&lt;/pre&gt;

&lt;h4&gt;&amp;#160;&lt;/h4&gt;
&lt;a name="template"&gt;
  &lt;h4&gt;Defining a DataGrid Template Column&lt;/h4&gt;
&lt;/a&gt;

&lt;p&gt;The following creates a DataGridTemplateColumn bound to the Birthday property with a header of &amp;quot;Birthday&amp;quot;, and adds it to the columns collection of the DataGrid named &amp;quot;targetDataGrid&amp;quot;.&lt;/p&gt;

&lt;h5&gt;Static&lt;/h5&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;local&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DateTimeConverter &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;DateConverter&amp;quot; /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;...&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;targetDataGrid&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot; &amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Birthday&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn.CellTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock 
                        &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Birthday&lt;/span&gt;&lt;span style="color: blue"&gt;, 
                        &lt;/span&gt;&lt;span style="color: red"&gt;Converter&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;DateConverter&lt;/span&gt;&lt;span style="color: blue"&gt;}}&amp;quot; 
&lt;/span&gt;&lt;span style="color: blue"&gt;                        &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;4&amp;quot;/&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn.CellTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn.CellEditingTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;basics&lt;span style="color: blue"&gt;:&lt;/span&gt;DatePicker 
                        &lt;/span&gt;&lt;span style="color: red"&gt;SelectedDate&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Birthday&lt;/span&gt;&lt;span style="color: blue"&gt;, &lt;/span&gt;&lt;span style="color: red"&gt;Mode&lt;/span&gt;&lt;span style="color: blue"&gt;=TwoWay}&amp;quot; /&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn.CellEditingTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h5&gt;Dynamic&lt;/h5&gt;

&lt;p&gt;There are two ways to dynamically create a template column for a DataGrid.&amp;#160; One is to load in the CellTemplate and CellEditingTemplates as DataTemplates from resources, and the other is to construct the DataTemplates on the fly using XamlReader.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Resources Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This method creates the CellTemplate DataTemplate and the CellEditingTemplate DataTemplate in XAML and stores them as named resources.&amp;#160; Then when the column is created the DataTemplates are used.&lt;/p&gt;

&lt;p&gt;Use the below XAML to create the DataTemplates as resources to support the code for this method.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;local&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DateTimeConverter &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;DateConverter&amp;quot; /&amp;gt;

    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;myCellTemplate&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock 
            &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Birthday&lt;/span&gt;&lt;span style="color: blue"&gt;, 
            &lt;/span&gt;&lt;span style="color: red"&gt;Converter&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;DateConverter&lt;/span&gt;&lt;span style="color: blue"&gt;}}&amp;quot; 
&lt;/span&gt;&lt;span style="color: blue"&gt;            &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;4&amp;quot;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;myCellEditingTemplate&amp;quot;&amp;gt;
        &amp;lt;&lt;span style="color: #a31515"&gt;basics&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DatePicker 
            &lt;/span&gt;&lt;span style="color: red"&gt;SelectedDate&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Birthday&lt;/span&gt;&lt;span style="color: blue"&gt;, &lt;/span&gt;&lt;span style="color: red"&gt;Mode&lt;/span&gt;&lt;span style="color: blue"&gt;=TwoWay}&amp;quot; /&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Data;&lt;/pre&gt;

&lt;pre class="code"&gt;...&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;DataGridTemplateColumn &lt;/span&gt;templateColumn = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridTemplateColumn&lt;/span&gt;();
templateColumn.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Birthday&amp;quot;&lt;/span&gt;;
templateColumn.CellTemplate = (&lt;span style="color: #2b91af"&gt;DataTemplate&lt;/span&gt;)Resources[&lt;span style="color: #a31515"&gt;&amp;quot;myCellTemplate&amp;quot;&lt;/span&gt;];
templateColumn.CellEditingTemplate = 
                       (&lt;span style="color: #2b91af"&gt;DataTemplate&lt;/span&gt;)Resources[&lt;span style="color: #a31515"&gt;&amp;quot;myCellEditingTemplate&amp;quot;&lt;/span&gt;];
targetDataGrid.Columns.Add(templateColumn);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Data&lt;/pre&gt;

&lt;pre class="code"&gt;...&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;TemplateColumn &lt;span style="color: blue"&gt;As New &lt;/span&gt;DataGridTemplateColumn
TemplateColumn.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Birthday&amp;quot;
&lt;/span&gt;TemplateColumn.CellTemplate = Resources(&lt;span style="color: #a31515"&gt;&amp;quot;myCellTemplate&amp;quot;&lt;/span&gt;)
TemplateColumn.CellEditingTemplate = Resources(&lt;span style="color: #a31515"&gt;&amp;quot;myCellEditingTemplate&amp;quot;&lt;/span&gt;)
TargetDataGrid.Columns.Add(TemplateColumn)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;2. XamlReader Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This method creates the DataTemplate inline using the XamlReader class.&amp;#160; This class takes a string and parses it to try to build a visual tree.&amp;#160; In this case we are creating DataTemplates.&amp;#160; This method is especially useful if the DataTemplate itself has to be dynamic.&amp;#160; One example being if you wanted to modify what the element in the template was bound to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Warning:&lt;/em&gt; &lt;/strong&gt;This method is considerably more difficult than the resources method.&amp;#160; I recommend only using this if you need to dynamically create the DataTemplate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some things to watch out for:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;You will need to declare any XAML namespace that is used in the data template &lt;/li&gt;

  &lt;li&gt;Any custom XAML namespace needs to specify both the clr-namespace and the assembly &lt;/li&gt;

  &lt;li&gt;You cannot have white space between the xmlns: and the name of your namespace &lt;/li&gt;

  &lt;li&gt;External resources cannot be referenced, they need to be declared inline &lt;/li&gt;

  &lt;li&gt;The entire template is a single line, so if you get a XAML Parse exception, it will always say line 1, however the character is fairly accurate if you were to concatenate all of your lines. &lt;/li&gt;

  &lt;li&gt;When using the StringBuilder approach shown below, make sure that you have the correct white space at the end of a line so that it is correctly separated when concatenated with the next line. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that the warnings are out of the way, here is how you do the equivalent of the code above:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Data;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Markup;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Text;&lt;/pre&gt;

&lt;pre class="code"&gt;...&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;DataGridTemplateColumn &lt;/span&gt;templateColumn = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataGridTemplateColumn&lt;/span&gt;();
templateColumn.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Birthday&amp;quot;&lt;/span&gt;;

&lt;span style="color: #2b91af"&gt;StringBuilder &lt;/span&gt;CellTemp = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringBuilder&lt;/span&gt;();
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;DataTemplate &amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns='http://schemas.microsoft.com/winfx/&amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;2006/xaml/presentation' &amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' &amp;quot;&lt;/span&gt;);

&lt;span style="color: green"&gt;//Be sure to replace &amp;quot;YourNamespace&amp;quot; and &amp;quot;YourAssembly&amp;quot; with your app's 
//actual namespace and assembly here
&lt;/span&gt;CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:local = 'clr-namespace:YourNamespace&amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;;assembly=YourAssembly'&amp;gt;&amp;quot;&lt;/span&gt;);

CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;Grid&amp;gt;&amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;Grid.Resources&amp;gt;&amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;local:DateTimeConverter x:Key='DateConverter' /&amp;gt;&amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;/Grid.Resources&amp;gt;&amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;TextBlock &amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;Text = '{Binding Birthday, &amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;Converter={StaticResource DateConverter}}' &amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;Margin='4'/&amp;gt;&amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;/Grid&amp;gt;&amp;quot;&lt;/span&gt;);
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;/DataTemplate&amp;gt;&amp;quot;&lt;/span&gt;);

&lt;span style="color: #2b91af"&gt;StringBuilder &lt;/span&gt;CellETemp = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringBuilder&lt;/span&gt;();
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;DataTemplate &amp;quot;&lt;/span&gt;);
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns='http://schemas.microsoft.com/winfx/&amp;quot;&lt;/span&gt;);
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;2006/xaml/presentation' &amp;quot;&lt;/span&gt;);
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' &amp;quot;&lt;/span&gt;);
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:basics='clr-namespace:System.Windows.Controls;&amp;quot;&lt;/span&gt;);
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;assembly=System.Windows.Controls' &amp;gt;&amp;quot;&lt;/span&gt;);
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;basics:DatePicker &amp;quot;&lt;/span&gt;);
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;SelectedDate='{Binding Birthday, Mode=TwoWay}' /&amp;gt;&amp;quot;&lt;/span&gt;);
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;/DataTemplate&amp;gt;&amp;quot;&lt;/span&gt;);

templateColumn.CellTemplate =
    (&lt;span style="color: #2b91af"&gt;DataTemplate&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;XamlReader&lt;/span&gt;.Load(CellTemp.ToString());
templateColumn.CellEditingTemplate =
    (&lt;span style="color: #2b91af"&gt;DataTemplate&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;XamlReader&lt;/span&gt;.Load(CellETemp.ToString());
targetDataGrid.Columns.Add(templateColumn);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Data
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Text
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Markup&lt;/pre&gt;

&lt;pre class="code"&gt;...&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;TemplateColumn &lt;span style="color: blue"&gt;As New &lt;/span&gt;DataGridTemplateColumn
TemplateColumn.Header = &lt;span style="color: #a31515"&gt;&amp;quot;Birthday&amp;quot;

&lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;CellTemp &lt;span style="color: blue"&gt;As New &lt;/span&gt;StringBuilder
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;DataTemplate &amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns='http://schemas.microsoft.com/winfx/&amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;2006/xaml/presentation' &amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' &amp;quot;&lt;/span&gt;)

&lt;span style="color: green"&gt;'Be sure to replace &amp;quot;YourNamespace&amp;quot; and &amp;quot;YourAssembly&amp;quot; with your app's 
'actual namespace and assembly here
&lt;/span&gt;CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:local = 'clr-namespace:YourNamespace&amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;;assembly=YourAssembly'&amp;gt;&amp;quot;&lt;/span&gt;)

CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;Grid&amp;gt;&amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;Grid.Resources&amp;gt;&amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;local:DateTimeConverter x:Key='DateConverter' /&amp;gt;&amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;/Grid.Resources&amp;gt;&amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;TextBlock &amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;Text = '{Binding Birthday, &amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;Converter={StaticResource DateConverter}}' &amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;Margin='4'/&amp;gt;&amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;/Grid&amp;gt;&amp;quot;&lt;/span&gt;)
CellTemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;/DataTemplate&amp;gt;&amp;quot;&lt;/span&gt;)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;CellETemp &lt;span style="color: blue"&gt;As New &lt;/span&gt;StringBuilder
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;DataTemplate &amp;quot;&lt;/span&gt;)
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns='http://schemas.microsoft.com/winfx/&amp;quot;&lt;/span&gt;)
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;2006/xaml/presentation' &amp;quot;&lt;/span&gt;)
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' &amp;quot;&lt;/span&gt;)
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;xmlns:basics='clr-namespace:System.Windows.Controls;&amp;quot;&lt;/span&gt;)
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;assembly=System.Windows.Controls' &amp;gt;&amp;quot;&lt;/span&gt;)
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;basics:DatePicker &amp;quot;&lt;/span&gt;)
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;SelectedDate='{Binding Birthday, Mode=TwoWay}' /&amp;gt;&amp;quot;&lt;/span&gt;)
CellETemp.Append(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;/DataTemplate&amp;gt;&amp;quot;&lt;/span&gt;)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;TemplateColumn.CellTemplate = XamlReader.Load(CellTemp.ToString())
TemplateColumn.CellEditingTemplate = XamlReader.Load(CellETemp.ToString())
targetDataGrid.Columns.Add(TemplateColumn)&lt;/pre&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8395118" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Value+Converters/default.aspx">Value Converters</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Template+Columns/default.aspx">Template Columns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category></item><item><title>Defining Columns for a Silverlight DataGrid</title><link>http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx</link><pubDate>Fri, 28 Mar 2008 04:28:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8340724</guid><dc:creator>scmorris</dc:creator><slash:comments>43</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/8340724.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=8340724</wfw:commentRss><description>&lt;table cellspacing="0" cellpadding="5" width="100%" bgcolor="#fff8c9" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;This post has been updated to work with the &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;RTW version of the Silverlight 2 DataGrid&lt;/a&gt;.&amp;#160; The code examples are not guaranteed to work with previous Beta versions of the DataGrid. &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx" target="_blank"&gt;Read more about the features that the Silverlight 2 DataGrid has to offer...&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;If you read my &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx" target="_blank"&gt;last post&lt;/a&gt;, you might have noticed how easy it is to get a Silverlight DataGrid up and running with the AutoGenerateColumns feature.&amp;#160; Something else you might have noticed is that if you don't like the default column choices it is sort of hard to change them.&amp;#160; Not to fear however since there are two ways to get more control.&amp;#160; One way is to use the AutoGeneratingColumn event (we'll talk about this in a different post) but the easiest way, and the topic of our discussion today, is by using the Columns collection.&lt;/p&gt;  &lt;h4&gt;The Columns Collection and You&lt;/h4&gt;  &lt;p&gt;The Columns Collection is your ticket to controlling the DataGrid's column order, appearance, and even what controls they use to represent data in their cells.&amp;#160; It enables you to have a concrete instance for each column that you define unlike auto generation that simply fills the column collection for you.&lt;/p&gt;  &lt;p&gt;Before we dive into using the Columns collection though, it is useful to know what you can put in it.&lt;/p&gt;  &lt;h5&gt;DataGrid Column Types&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;DataGridTextColumn&lt;/strong&gt; - When you think of a standard column in a DataGrid, you probably picture something that looks a lot like a DataGridTextColumn.&amp;#160; This column is the default and uses a TextBlock to display its data, and a TextBox to allow editing of its data.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DataGridCheckBoxColumn &lt;/strong&gt;- The DataGridCheckBoxColumn is the first out of box custom column type.&amp;#160; It provides a read-only CheckBox for displaying a boolean or nullable boolean value, and a normal CheckBox to allow editing of that value.&amp;#160; This column derives from DataGridBoundColumn and serves as a sample for building your own column types.&amp;#160; We'll walk through the process of building your own column types in a future post.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DataGridTemplateColumn &lt;/strong&gt;- If the DataGrid was a movie, the DataGridTemplateColumn would be the star.&amp;#160; It is the most versatile column but, like most prima donnas, takes the most work to get up and going.&amp;#160; Once it is going though there is pretty much no limit to what it can do. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;Using the Columns Collection&lt;/h5&gt;  &lt;p&gt;First we need to get our project back to where we ended last time.&amp;#160; Go ahead and follow the steps 1 and 2 &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you followed steps 1 &amp;amp; 2 from the previous post, your DataGrid should look something like this: &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dg&amp;quot;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;(If yours looks different because you did step 3, don't worry since it won't affect this walk through. The one exception is that you need to change IsReadOnly back to False.)&lt;/p&gt;

&lt;p&gt;Also, in the code behind file for Page.xaml you should be setting the source to a List&amp;lt;Data&amp;gt; where Data is the custom business object you created.&lt;/p&gt;

&lt;p&gt;Now that we are all on the same page lets start playing with the Column collection.&lt;/p&gt;

&lt;p&gt;Since auto generation is no longer needed, go ahead and set AutoGenerateColumns to False.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dg&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now add the Columns collection, and add a Text column in it bound to the &amp;quot;FirstName&amp;quot; property.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dg&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First Name&amp;quot; 
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;FirstName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The code above is doing a few things:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;It creates the &lt;strong&gt;Columns&lt;/strong&gt; collection using the &amp;lt;data:DataGrid.Columns&amp;gt; tag. &lt;/li&gt;

  &lt;li&gt;Inside that collection it creates a new &lt;strong&gt;DataGridTextColumn&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;The content that you see in the column header is set to &amp;quot;First Name&amp;quot; using the &lt;strong&gt;Header &lt;/strong&gt;property &lt;/li&gt;

  &lt;li&gt;The column is data bound to the FirstName property using the &lt;strong&gt;Binding &lt;/strong&gt;property.&amp;#160; Notice that since the DataContext of the DataGrid is its ItemsSource collection a Source does not need to be specified.&amp;#160; &lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Side Note:&lt;/em&gt; Some of you might be wondering why we use &lt;strong&gt;Binding&lt;/strong&gt; here instead of a string like DisplayMember&lt;strong&gt;Path&lt;/strong&gt;.&amp;#160; The thinking behind this decision was that a binding gives you a lot more control of what ends up being shown.&amp;#160; It allows the use of converters, and leaves the door open for the addition of validation, and formatters.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you run this you should see something like this:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="FirstColumn" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/SpecifyingColumnsforaSilverlightDataGrid_80AC/FirstColumn_e2d39670-f708-4954-9c6a-bdb09e737111.png" width="404" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;In addition to the &lt;strong&gt;Header &lt;/strong&gt;and &lt;strong&gt;Binding &lt;/strong&gt;properties, you can also customize the column through properties such as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Column Properties:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;CanUserResize &lt;/strong&gt;- Determines if this column can be resized.&amp;#160; In regards to its relationship with the DataGrid property CanUserResizeColumns, false always wins. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;CanUserReorder &lt;/strong&gt;- Determines if this column can be reordered with other columns.&amp;#160; In regards to its relationship with the DataGrid property CanUserReorderColumns, false always wins. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;CanUserSort &lt;/strong&gt;- Determines if this column can be sorted.&amp;#160; In regards to its relationship with the DataGrid property CanUserSortColumns, false always wins. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;IsReadOnly &lt;/strong&gt;- Determines if this column can be edited.&amp;#160; In regards to its relationship with the DataGrid property IsReadOnly, true always wins. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Width &lt;/strong&gt;- Sets the width of the column.&amp;#160; Setting this value overrides the DataGrid ColumnWidth property. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;MinWidth &lt;/strong&gt;- Sets the minimum width for this column. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Visibility &lt;/strong&gt;- Hides or shows this column &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;ElementStyle &lt;/strong&gt;- The property used to style the display element for a column.&amp;#160; (In the case of the TextBox Column the display element is the TextBlock) &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;EditingElementStyle &lt;/strong&gt;- The property used to style the editing element for a column.&amp;#160; (In the case of the TextBox Column the display element is the TextBox) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;TextBox Column Specific Properties:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;FontFamily&lt;/strong&gt; - Sets the &lt;a href="http://msdn2.microsoft.com/library/system.windows.controls.control.fontfamily.aspx" target="_blank"&gt;FontFamily&lt;/a&gt; property on both the TextBlock and TextBox. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;FontSize&lt;/strong&gt; - Sets the &lt;a href="http://msdn2.microsoft.com/library/system.windows.controls.control.fontsize.aspx" target="_blank"&gt;FontSize&lt;/a&gt; property on both the TextBlock and TextBox. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;FontStyle &lt;/strong&gt;- Sets the &lt;a href="http://msdn2.microsoft.com/library/system.windows.controls.control.fontstyle.aspx" target="_blank"&gt;FontStyle&lt;/a&gt; property on both the TextBlock and TextBox. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;FontWeight &lt;/strong&gt;- Sets the &lt;a href="http://msdn2.microsoft.com/library/system.windows.controls.control.fontweight.aspx" target="_blank"&gt;FontWeight&lt;/a&gt; property on both the TextBlock and TextBox. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Foreground&lt;/strong&gt; - Sets the &lt;a href="http://msdn2.microsoft.com/library/system.windows.controls.control.foreground.aspx" target="_blank"&gt;Foreground&lt;/a&gt; property on both the TextBlock and TextBox. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;CheckBox Column Specific Properties:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;IsThreeState&lt;/strong&gt; - Sets the &lt;a href="http://msdn2.microsoft.com/library/system.windows.controls.primitives.togglebutton.isthreestate.aspx" target="_blank"&gt;IsThreeState&lt;/a&gt; property on the CheckBoxes &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lets now finish off the columns that we used to have by adding two more DataGridTextBoxColumns and a DataGridCheckBoxColumn bound to &amp;quot;LastName&amp;quot;, &amp;quot;Age&amp;quot;, and &amp;quot;Available&amp;quot;.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dg&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot; &amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First Name&amp;quot;
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;FirstName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Last Name&amp;quot; 
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;LastName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Age&amp;quot; &lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;50&amp;quot; &lt;/span&gt;
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Age&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridCheckBoxColumn&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Available&amp;quot; 
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Available&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now when you run the application you have the same output as the auto generation, except now you control the order, what the header says, and you can set properties.&amp;#160; For instance in the code above the width of the Age column is set to 50 instead of the usual Auto.&lt;/p&gt;

&lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="AllColumns" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/SpecifyingColumnsforaSilverlightDataGrid_80AC/AllColumns_f8727851-cea9-429b-b2a3-bd975c10c776.png" width="404" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;
&lt;a name="template"&gt;
  &lt;h4&gt;Unleashing the Template Column&lt;/h4&gt;
&lt;/a&gt;

&lt;p&gt;Now that we have recreated the auto generated DataGrid from before let's add some new functionality, specifically a column that can be bound to a DateTime.&amp;#160; To do this we can either create a new column type, or just use a template column.&amp;#160; Since we only plan on using this column once, let's use a template column.&lt;/p&gt;

&lt;p&gt;First let's add something for this column to bind to.&amp;#160; Going back to your &lt;strong&gt;Data&lt;/strong&gt; class, add the following property:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DateTime &lt;/span&gt;Birthday{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private &lt;/span&gt;_birthday &lt;span style="color: blue"&gt;As &lt;/span&gt;DateTime

&lt;span style="color: blue"&gt;Property &lt;/span&gt;Birthday() &lt;span style="color: blue"&gt;As &lt;/span&gt;DateTime
    &lt;span style="color: blue"&gt;Get
        Return &lt;/span&gt;_birthday
    &lt;span style="color: blue"&gt;End Get
    Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As &lt;/span&gt;DateTime)
        _birthday = value
    &lt;span style="color: blue"&gt;End Set
End Property&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Also we need to update the Page.xaml code behind to initialize the new property:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;Page()
{
    InitializeComponent();

    &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Data&lt;/span&gt;&amp;gt; source = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Data&lt;/span&gt;&amp;gt;();
    &lt;span style="color: blue"&gt;int &lt;/span&gt;itemsCount = 100;

    &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;i = 0; i &amp;lt; itemsCount; i++)
    {
        source.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Data&lt;/span&gt;()
        {
            FirstName = &lt;span style="color: #a31515"&gt;&amp;quot;First&amp;quot;&lt;/span&gt;,
            LastName = &lt;span style="color: #a31515"&gt;&amp;quot;Last&amp;quot;&lt;/span&gt;,
            Age = i,
            Available = i % 2 == 0&lt;strong&gt;,&lt;/strong&gt;
            &lt;strong&gt;Birthday = &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt;.Today.AddYears(-i)&lt;/strong&gt;
        });
    }

    dg.ItemsSource = source;                
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Public Sub New&lt;/span&gt;()
    InitializeComponent()

    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;Source &lt;span style="color: blue"&gt;As &lt;/span&gt;List(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Data) = &lt;span style="color: blue"&gt;New &lt;/span&gt;List(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Data)
    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;ItemsCount &lt;span style="color: blue"&gt;As Integer &lt;/span&gt;= 100

    &lt;span style="color: blue"&gt;For &lt;/span&gt;index &lt;span style="color: blue"&gt;As Integer &lt;/span&gt;= 1 &lt;span style="color: blue"&gt;To &lt;/span&gt;ItemsCount
        Source.Add(&lt;span style="color: blue"&gt;New &lt;/span&gt;Data() &lt;span style="color: blue"&gt;With &lt;/span&gt;_
        { _
            .FirstName = &lt;span style="color: #a31515"&gt;&amp;quot;First&amp;quot;&lt;/span&gt;, _
            .LastName = &lt;span style="color: #a31515"&gt;&amp;quot;Last&amp;quot;&lt;/span&gt;, _
            .Age = index, _
            .Available = (index &lt;span style="color: blue"&gt;Mod &lt;/span&gt;2 = 0)&lt;strong&gt;, _&lt;/strong&gt;
            &lt;strong&gt;.Birthday = DateTime.Today.AddYears(-index) _&lt;/strong&gt;
        })
    &lt;span style="color: blue"&gt;Next

    &lt;/span&gt;dg.ItemsSource = Source
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now that the data is there we can bind to it.&amp;#160; Going back to the Page.xaml file add a DataGridTemplateColumn to the Columns collection right after the &amp;quot;Available&amp;quot; column.&lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;basics&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:System.Windows.Controls;&lt;br /&gt;assembly=System.Windows.Controls&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dg&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot; &amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First Name&amp;quot;
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;FirstName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Last Name&amp;quot; 
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;LastName&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTextColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Age&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;50&amp;quot;
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Age&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridCheckBoxColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Available&amp;quot; 
                &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Available&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;

        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;&lt;strong&gt;DataGridTemplateColumn&lt;/strong&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Birthday&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn.CellTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Birthday&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;4&amp;quot;/&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn.CellTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn.CellEditingTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;span style="color: #a31515"&gt;basics&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DatePicker 
                        &lt;/span&gt;&lt;span style="color: red"&gt;SelectedDate&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Birthday&lt;/span&gt;&lt;span style="color: blue"&gt;, &lt;/span&gt;&lt;span style="color: red"&gt;Mode&lt;/span&gt;&lt;span style="color: blue"&gt;=TwoWay}&amp;quot; /&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGridTemplateColumn.CellEditingTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;&lt;strong&gt;DataGridTemplateColumn&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Warning:&lt;/em&gt;&lt;/strong&gt; Be sure to add the DatePicker from the ToolBox so the basics namespace and associated reference to System.Windows.Controls is added for you.&lt;/p&gt;

&lt;p&gt;What's going on in the code above:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A &lt;strong&gt;DataGridTemplateColumn&lt;/strong&gt; is being added to the Columns collection with its header being set to &amp;quot;Birthday&amp;quot;. &lt;/li&gt;

  &lt;li&gt;The &lt;strong&gt;CellTemplate &lt;/strong&gt;property, which takes a &lt;strong&gt;DataTemplate,&lt;/strong&gt; is being used to define the UI that cells in the column will use to display the data. &lt;/li&gt;

  &lt;li&gt;In this instance, the content of that DataTemplate is a TextBlock that has its Text property bound to the &amp;quot;Birthday&amp;quot; property on the Data Item.&amp;#160; Once again notice that no binding source is necessary since the default DataContext of a Template column's contents is the data item that it will be representing. &lt;/li&gt;

  &lt;li&gt;In addition to the CellTemplate the DataGridTemplateColumn's &lt;strong&gt;CellEditingTemplate &lt;/strong&gt;property is also being set.&amp;#160; This property is also a DataTemplate and defines the UI that cells in the column will display during edit mode. &lt;/li&gt;

  &lt;li&gt;In this instance, the content of the CellEditingTemplate's DataTemplate is a DatePicker control that has its SelectedDate property also bound to the &amp;quot;Birthday&amp;quot; property. &lt;/li&gt;

  &lt;li&gt;Notice that its binding has the &lt;strong&gt;Mode&lt;/strong&gt; property set to &lt;strong&gt;TwoWay&lt;/strong&gt;.&amp;#160; This is crucial to make sure that any changes made to this property at runtime will be pushed back into the data source. Note that you do not need to set the Mode when you are using the DisplayMemberBinding property in column types other than DataGridTemplateColumn because the columns themselves take care of this. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you run this you should see a new column in your DataGrid that uses a TextBlock to display a date, and then switches to a DatePicker during edit mode to provide a richer input experience.&lt;/p&gt;

&lt;p&gt;(If your DataGrid still has all of the properties set from Step 3 of the last post you need to set &lt;strong&gt;IsReadOnly&lt;/strong&gt; back to &lt;strong&gt;False&lt;/strong&gt; if you want to be able to see the DatePicker in edit mode)&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="320" alt="TemplateColumn" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/SpecifyingColumnsforaSilverlightDataGrid_80AC/TemplateColumn_348a43ea-c3b0-42c5-b064-f12e29a5bac9.png" width="431" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;Using Value Converters&lt;/h4&gt;

&lt;p&gt;This column is pretty much exactly what we want, but there is a finishing touch missing.&amp;#160; If you look at the text, it has an annoying 12:00:00 AM after each date.&amp;#160; Since we only care about the date itself and not the time, let's reformat this string to the short date format that matches what is shown in the DatePicker.&lt;/p&gt;

&lt;p&gt;Add a new class to your Silverlight project and name it &amp;quot;&lt;strong&gt;DateTimeConverter&lt;/strong&gt;&amp;quot;.&amp;#160; Then add:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Data;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Globalization;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DateTimeConverter&lt;/span&gt;: &lt;span style="color: #2b91af"&gt;IValueConverter
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;public object &lt;/span&gt;Convert(&lt;span style="color: blue"&gt;object &lt;/span&gt;value, 
                       &lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;targetType, 
                       &lt;span style="color: blue"&gt;object &lt;/span&gt;parameter, 
                       &lt;span style="color: #2b91af"&gt;CultureInfo &lt;/span&gt;culture)
    {
        &lt;span style="color: #2b91af"&gt;DateTime &lt;/span&gt;date = (&lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt;)value;
        &lt;span style="color: blue"&gt;return &lt;/span&gt;date.ToShortDateString();
    }

    &lt;span style="color: blue"&gt;public object &lt;/span&gt;ConvertBack(&lt;span style="color: blue"&gt;object &lt;/span&gt;value, 
                              &lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;targetType, 
                              &lt;span style="color: blue"&gt;object &lt;/span&gt;parameter, 
                              &lt;span style="color: #2b91af"&gt;CultureInfo &lt;/span&gt;culture)
    {
        &lt;span style="color: blue"&gt;string &lt;/span&gt;strValue = value.ToString();
        &lt;span style="color: #2b91af"&gt;DateTime &lt;/span&gt;resultDateTime;
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt;.TryParse(strValue, &lt;span style="color: blue"&gt;out &lt;/span&gt;resultDateTime))
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;resultDateTime;
        }
        &lt;span style="color: blue"&gt;return &lt;/span&gt;value;
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Data

&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;DateTimeConverter
    &lt;span style="color: blue"&gt;Implements &lt;/span&gt;IValueConverter

    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;Convert(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, _
                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;targetType &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Type, _
                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;parameter &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, _
                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;culture &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Globalization.CultureInfo) _
                &lt;span style="color: blue"&gt;As Object &lt;/span&gt;_
                &lt;span style="color: blue"&gt;Implements &lt;/span&gt;System.Windows.Data.IValueConverter.Convert

        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;DateValue &lt;span style="color: blue"&gt;As &lt;/span&gt;DateTime = value
        &lt;span style="color: blue"&gt;Return &lt;/span&gt;DateValue.ToShortDateString()

    &lt;span style="color: blue"&gt;End Function

    Public Function &lt;/span&gt;ConvertBack(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, _
                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;targetType &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Type, _
                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;parameter &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, _
                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;culture &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Globalization.CultureInfo) _
                &lt;span style="color: blue"&gt;As Object &lt;/span&gt;_
                &lt;span style="color: blue"&gt;Implements &lt;/span&gt;System.Windows.Data.IValueConverter.ConvertBack

        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;StrValue &lt;span style="color: blue"&gt;As String &lt;/span&gt;= value.ToString()
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;ResultDateTime &lt;span style="color: blue"&gt;As &lt;/span&gt;DateTime

        &lt;span style="color: blue"&gt;If &lt;/span&gt;DateTime.TryParse(StrValue, ResultDateTime) &lt;span style="color: blue"&gt;Then
            Return &lt;/span&gt;ResultDateTime
        &lt;span style="color: blue"&gt;End If

        Return &lt;/span&gt;value

    &lt;span style="color: blue"&gt;End Function
End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look at the code, a converter is a class that implements &lt;a href="http://msdn2.microsoft.com/library/system.windows.data.ivalueconverter.aspx" target="_blank"&gt;IValueConverter&lt;/a&gt; and as part of that provides two methods: Convert and ConvertBack.&amp;#160; These two methods are where you can perform your custom logic, in this case parsing a DateTime to and from a short date string format.&lt;/p&gt;

&lt;p&gt;Now that you have your reusable converter class you can use it in data binding.&lt;/p&gt;

&lt;p&gt;Back in your Page.xaml add a local xmlns.&amp;#160; To do this add the following in the UserControl tag next to the other xmlns declarations:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;local&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:_____________&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Where the _________ is the name of your Application.&amp;#160; IntelliSense should provide the correct syntax as an option in the dropdown.&amp;#160; Next add the converter to your UserControl as a static resource.&lt;/p&gt;
&lt;span style="color: blue"&gt;
  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;local&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DateTimeConverter &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;DateConverter&amp;quot; /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;

&lt;p&gt;Finally use the converter in the TextBox's binding in the DataGridTemplateColumn.&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock 
    &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Birthday&lt;/span&gt;&lt;span style="color: blue"&gt;, &lt;/span&gt;&lt;span style="color: red"&gt;Converter&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;DateConverter&lt;/span&gt;&lt;span style="color: blue"&gt;}}&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;
    &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;4&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now when you run the application, the text will be formatted in the manner that the converter specified.&lt;/p&gt;

&lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="TemplateColumnWithConverter" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/SpecifyingColumnsforaSilverlightDataGrid_80AC/TemplateColumnWithConverter_6442a25f-0bd7-445a-8e17-92360ab1d62a.png" width="404" border="0" /&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8340724" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Value+Converters/default.aspx">Value Converters</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Template+Columns/default.aspx">Template Columns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/AutoGenerateColumns/default.aspx">AutoGenerateColumns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category></item><item><title>Using The Silverlight DataGrid</title><link>http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx</link><pubDate>Fri, 21 Mar 2008 16:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8328575</guid><dc:creator>scmorris</dc:creator><slash:comments>79</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/8328575.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=8328575</wfw:commentRss><description>&lt;table cellspacing="0" cellpadding="5" width="100%" bgcolor="#fff8c9" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;This post has been updated to work with the &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;RTW version of the Silverlight 2 DataGrid&lt;/a&gt;.&amp;#160; The code examples are not guaranteed to work with previous Beta versions of the DataGrid.&amp;#160; &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx" target="_blank"&gt;Read more about the features that the Silverlight 2 DataGrid has to offer...&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;If you have ever worked on an application that displayed large amounts of data, one of the cornerstones of your application was probably a DataGrid control.&amp;#160; We have provided four .NET DataGrids over the years, two for ASP.NET and two for Windows Forms, but until now Silverlight and WPF were left out of the party.&amp;#160; &lt;/p&gt;  &lt;p&gt;At MIX 2008 we shipped the first preview of the Silverlight DataGrid and a preview of it in WPF was also shown.&amp;#160; Now that it is out there people want to know how to use it.&amp;#160; If you are one of those people, then you have come to the right place.&amp;#160; Here's a quick guide on how to get up and running with a Silverlight DataGrid.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;h4&gt;Step 0: Create A Silverlight Project&lt;/h4&gt;  &lt;p&gt;Start a new Silverlight Application as outlined in my &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/12/getting-started-with-silverlight.aspx" target="_blank" mce_href="http://blogs.msdn.com/scmorris/archive/2008/03/12/getting-started-with-silverlight.aspx"&gt;previous post&lt;/a&gt;.&amp;#160; When given the option, choose the default &amp;quot;Add a new ASP.NET Web project&amp;quot; option.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;h4&gt;Step 1: Add a DataGrid&lt;/h4&gt;  &lt;p&gt;If everything went smoothly in the previous step, your project should be loaded and opened to Page.xaml.&amp;#160; Now just find the DataGrid on the Toolbox and drag it into the root layout Grid named &amp;quot;LayoutRoot&amp;quot;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="239" alt="DataGridOnToolBox" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/YourFirstDataGridAtLeastInSilverlight_EB0D/DataGridOnToolBox_12.png" width="520" border="0" mce_src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/YourFirstDataGridAtLeastInSilverlight_EB0D/DataGridOnToolBox_12.png" /&gt; &lt;/p&gt;  &lt;p&gt;This does a few things behind the scenes:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;It adds a reference in your Silverlight project to System.Windows.Controls.Data &lt;/li&gt;    &lt;li&gt;It adds an xmlns called &amp;quot;data&amp;quot; to the root UserControl that specifies that the DataGrid is in the System.Windows.Controls namespace and located in the System.Windows.Controls.Data assembly      &lt;ul&gt;       &lt;div align="left"&gt;         &lt;pre class="code"&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:System.Windows.Controls;&lt;br /&gt; assembly=System.Windows.Controls.Data&amp;quot;&lt;/span&gt;&lt;/pre&gt;
      &lt;/div&gt;
      &lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;It adds an instance of the DataGrid as a child of &amp;quot;LayoutRoot&amp;quot; 
    &lt;ul&gt;
      &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
      &lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are the type of the person who likes to see things working after each step, feel free to F5 (choose the option to allow debugging in the popup) and take in the awesome sight that is an empty DataGrid.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="EmptyDataGrid" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/YourFirstDataGridAtLeastInSilverlight_EB0D/EmptyDataGrid_250a611c-9d84-40b9-8d46-a7756dcf9aae.png" width="404" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;Not much here, so lets fill it with something.&lt;/p&gt;

&lt;h4&gt;&amp;#160;&lt;strong&gt;Step 2: Set the ItemsSource and AutoGenerateColumns&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;The way to make a DataGrid interesting is by giving it some data.&amp;#160; This is done through the DataGrid's &lt;strong&gt;ItemsSource&lt;/strong&gt; property.&amp;#160; This is same property that other controls in WPF and Silverlight, such as ListBox, use to specify where they will get their data.&amp;#160; The one difference here is that you cannot place arbitrary content in it and have it create a collection for you. &lt;/p&gt;

&lt;p&gt;Instead you need to provide it a collection of anything that implements &lt;a href="http://msdn2.microsoft.com/library/9eekhta0.aspx" target="_blank" mce_href="http://msdn2.microsoft.com/library/9eekhta0.aspx"&gt;IEnumerable&lt;/a&gt; such as a &lt;a href="http://msdn2.microsoft.com/library/6sh2ey19.aspx" target="_blank" mce_href="http://msdn2.microsoft.com/library/6sh2ey19.aspx"&gt;List&lt;/a&gt; or &lt;a href="http://msdn2.microsoft.com/library/ms668604.aspx" target="_blank" mce_href="http://msdn2.microsoft.com/library/ms668604.aspx"&gt;ObservableCollection&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The ItemsSource can be specified inline in XAML such as:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dg&amp;quot;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &lt;/span&gt;&lt;span style="color: green"&gt;&amp;lt;!--Something that implements IEnumerable --&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid.ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;However, it is more commonly set in code behind, which is what we will do in this example.&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2 A: Name the DataGrid and build&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we go to the code behind you will want to be sure to give the DataGrid a name such as &amp;quot;dg&amp;quot;.&amp;#160; Also be sure to build so that you can reference the DataGrid in code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;my&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dg&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;my&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step 2 B: Create and Set the Items Source&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that the DataGrid is ready to have its ItemsSource set, go to the Page's constructor located in the code behind file for Page.xaml (A handy shortcut to do this from within Page.xaml is F7) and add the following line below InitializeComponent:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;Page()
{
    InitializeComponent();
    dg.ItemsSource = &lt;span style="color: #a31515"&gt;&amp;quot;H e l l o W o r l d !&amp;quot;&lt;/span&gt;.Split();
}&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Public Sub New&lt;/span&gt;()
    InitializeComponent()
    dg.ItemsSource = &lt;span style="color: #a31515"&gt;&amp;quot;H e l l o W o r l d !&amp;quot;&lt;/span&gt;.Split()
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;(If you get the build error: &amp;quot;The name 'dg' does not exist in the current context&amp;quot; with the code above be sure to build a second time so that the name has a chance to propagate) &lt;/p&gt;

&lt;p&gt;One of the easiest ways to generate an IEnumerable collection is &lt;a href="http://msdn2.microsoft.com/library/system.string.split(VS.71).aspx" target="_blank" mce_href="http://msdn2.microsoft.com/library/system.string.split(VS.71).aspx"&gt;String.Split&lt;/a&gt;.&amp;#160; When the resulting array is set as the ItemsSource of the DataGrid a column will be automatically generated since AutoGenerateColumns is true.&amp;#160; When you run the application, it will look like this:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="StringSplitDataGrid" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/YourFirstDataGridAtLeastInSilverlight_EB0D/StringSplitDataGrid_0695d3ca-d884-4c84-a1b0-e005d5f32d2f.png" width="404" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;This is a little better, but so far this could be done with a ListBox.&amp;#160; Lets add some more complicated data so that we actually need to use a DataGrid.&lt;/p&gt;

&lt;p&gt;Add a new class to your Silverlight project (not the Web project) and name it &amp;quot;Data&amp;quot;.&lt;/p&gt;

&lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="341" alt="AddNewClass" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/YourFirstDataGridAtLeastInSilverlight_EB0D/AddNewClass_3.png" width="419" border="0" mce_src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/YourFirstDataGridAtLeastInSilverlight_EB0D/AddNewClass_3.png" /&gt; &lt;/p&gt;

&lt;p&gt;Then add a few properties to bind to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are using C#, you can use the great 3.0 &lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2007/03/03/c-3-0-automatic-properties-explained.aspx" target="_blank" mce_href="http://community.bartdesmet.net/blogs/bart/archive/2007/03/03/c-3-0-automatic-properties-explained.aspx"&gt;Automatic Properties&lt;/a&gt; feature.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Data
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;public string &lt;/span&gt;FirstName { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue"&gt;public string &lt;/span&gt;LastName { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue"&gt;public int &lt;/span&gt;Age { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue"&gt;public bool &lt;/span&gt;Available { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
}&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;Data
    &lt;span style="color: blue"&gt;Private &lt;/span&gt;_firstName &lt;span style="color: blue"&gt;As String
    Private &lt;/span&gt;_lastName &lt;span style="color: blue"&gt;As String
    Private &lt;/span&gt;_age &lt;span style="color: blue"&gt;As Integer
    Private &lt;/span&gt;_available &lt;span style="color: blue"&gt;As Boolean

    Property &lt;/span&gt;FirstName() &lt;span style="color: blue"&gt;As String
        Get
            Return &lt;/span&gt;_firstName
        &lt;span style="color: blue"&gt;End Get
        Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
            _firstName = value
        &lt;span style="color: blue"&gt;End Set
    End Property

    Property &lt;/span&gt;LastName() &lt;span style="color: blue"&gt;As String
        Get
            Return &lt;/span&gt;_lastName
        &lt;span style="color: blue"&gt;End Get
        Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
            _lastName = value
        &lt;span style="color: blue"&gt;End Set
    End Property

    Property &lt;/span&gt;Age() &lt;span style="color: blue"&gt;As Integer
        Get
            Return &lt;/span&gt;_age
        &lt;span style="color: blue"&gt;End Get
        Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Integer&lt;/span&gt;)
            _age = value
        &lt;span style="color: blue"&gt;End Set
    End Property

    Property &lt;/span&gt;Available() &lt;span style="color: blue"&gt;As Boolean
        Get
            Return &lt;/span&gt;_available
        &lt;span style="color: blue"&gt;End Get
        Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;)
            _available = value
        &lt;span style="color: blue"&gt;End Set
    End Property
End Class&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Once the Data class is defined, it can now be used to provide data for the DataGrid.&amp;#160; Go back to the code behind file for Page.xaml and replace the previous ItemsSource assignment with the following.&amp;#160; A useful trick here is to use the C# and VB 3.0 &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx" target="_blank" mce_href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx"&gt;Object Initializer&lt;/a&gt; feature to initialize the Data objects as we add them to the List.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;Page()
{
    InitializeComponent();
    &lt;span style="color: green"&gt;//dg.ItemsSource = &amp;quot;H e l l o W o r l d !&amp;quot;.Split();

    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Data&lt;/span&gt;&amp;gt; source = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Data&lt;/span&gt;&amp;gt;();
    &lt;span style="color: blue"&gt;int &lt;/span&gt;itemsCount = 100;

    &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;i = 0; i &amp;lt; itemsCount; i++)
    {
        source.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Data&lt;/span&gt;() 
        { 
            FirstName = &lt;span style="color: #a31515"&gt;&amp;quot;First&amp;quot;&lt;/span&gt;, 
            LastName = &lt;span style="color: #a31515"&gt;&amp;quot;Last&amp;quot;&lt;/span&gt;, 
            Age = i, 
            Available = (i % 2 == 0) 
        });
    }

    dg.ItemsSource = source;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Public Sub New&lt;/span&gt;()
    InitializeComponent()
    &lt;span style="color: green"&gt;'dg.ItemsSource = &amp;quot;H e l l o W o r l d !&amp;quot;.Split()

    &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;Source &lt;span style="color: blue"&gt;As &lt;/span&gt;List(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Data) = &lt;span style="color: blue"&gt;New &lt;/span&gt;List(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Data)
    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;ItemsCount &lt;span style="color: blue"&gt;As Integer &lt;/span&gt;= 100

    &lt;span style="color: blue"&gt;For &lt;/span&gt;index &lt;span style="color: blue"&gt;As Integer &lt;/span&gt;= 1 &lt;span style="color: blue"&gt;To &lt;/span&gt;ItemsCount
        Source.Add(&lt;span style="color: blue"&gt;New &lt;/span&gt;Data() &lt;span style="color: blue"&gt;With &lt;/span&gt;_
        { _
            .FirstName = &lt;span style="color: #a31515"&gt;&amp;quot;First&amp;quot;&lt;/span&gt;, _
            .LastName = &lt;span style="color: #a31515"&gt;&amp;quot;Last&amp;quot;&lt;/span&gt;, _
            .Age = index, _&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; .Available = (index &lt;span style="color: blue"&gt;Mod &lt;/span&gt;2 = 0) _
        })
    &lt;span style="color: blue"&gt;Next

    &lt;/span&gt;dg.ItemsSource = Source
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;When you run this you will notice that columns are created for you. This is because auto-generation takes over, using reflection to create a column for each property in Data, setting the column header to the name of the property, and choosing default column types based on the property type.&amp;#160; For instance the Available column is a DataGridCheckBoxColumn.&amp;#160; (If you did not want this behavior, but rather wanted to choose your own columns, you can do this by setting the DataGrid's AutoGenerateColumns property to false.&amp;#160; For information on choosing your own columns see my post on &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx" target="_blank"&gt;Defining Columns for a Silverlight DataGrid&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&amp;#160; &lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="DataListDataGrid" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/YourFirstDataGridAtLeastInSilverlight_EB0D/DataListDataGrid_45f8a7e8-c576-4771-8d77-be132ea74340.png" width="404" border="0" /&gt; &lt;/p&gt;

&lt;h4&gt;Step 3: Simple Customization of the DataGrid&lt;/h4&gt;

&lt;p&gt;The easiest way to customize the DataGrid is through a variety of properties.&amp;#160; The other two ways are through Styles and Templates which will be covered in future posts.&amp;#160; Some of the most useful properties for customization are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GridLinesVisibility &amp;amp; HeadersVisibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These properties are enumerations that control what gridlines and headers are displayed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RowBackground &amp;amp; AlternatingRowBackground&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These properties are shortcuts to setting the background color for both rows and alternating rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ColumnWidth &amp;amp; RowHeight&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These properties set the default column width and default row height.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IsReadOnly &amp;amp; CanUserResizeColumns&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These properties control if the end user can edit the data in the grid and if the columns can be resized.&lt;/p&gt;

&lt;p&gt;For instance if you set the following properties to the following values:&lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;dg&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot; 
    &lt;/span&gt;&lt;span style="color: red"&gt;GridlinesVisibility&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;None&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;HeadersVisibility&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;All&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;RowBackground&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Cornsilk&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;AlternatingRowBackground&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;LemonChiffon&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;ColumnWidth&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;85&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;RowHeight&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;30&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;IsReadOnly&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;CanUserResizeColumns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;
    &amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;data&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;You would get this:&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="CustomizedDataGrid" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/YourFirstDataGridAtLeastInSilverlight_EB0D/CustomizedDataGrid_7b1589d4-b70a-4e35-8e86-ac58ab0e45ef.png" width="404" border="0" /&gt; &lt;/p&gt;

&lt;h4&gt;Step 4: Enjoy&lt;/h4&gt;

&lt;p&gt;Now that you have the basics, enjoy using the DataGrid.&amp;#160; &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx"&gt;Next time&lt;/a&gt; I'll go into how to explicitly define and customize columns instead of using auto generation.&lt;/p&gt;

&lt;p&gt;Also, you can &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx"&gt;read more about the features that the Silverlight 2 DataGrid has to offer...&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8328575" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/AutoGenerateColumns/default.aspx">AutoGenerateColumns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category></item></channel></rss>