<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>vbnet &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/vbnet/</link>
	<description>Feed of posts on WordPress.com tagged "vbnet"</description>
	<pubDate>Tue, 01 Dec 2009 07:06:38 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[REPORTING WITH PRINTDOCUMENT IN .NET]]></title>
<link>http://gilbertadjin.wordpress.com/2009/11/28/reporting-with-printdocument-in-net/</link>
<pubDate>Sat, 28 Nov 2009 12:17:34 +0000</pubDate>
<dc:creator>Gilbert Adjin Frimpong</dc:creator>
<guid>http://gilbertadjin.wordpress.com/2009/11/28/reporting-with-printdocument-in-net/</guid>
<description><![CDATA[Due to flexibility in creating reports with some tools in the .NET framework , using PrintDocument()]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Due to flexibility in creating reports with some tools in the .NET framework , using PrintDocument() class in creating reports is fading out. But sometimes you don&#8217;t have a choice but to use it. For instance creating reports without any predefined data source or generating reports where needed columns are determined at runtime. </p>
</p>
<p>In this post we will go through creating a report using the PrintDocument. Our datasoure will also come from a listview which contains a list of file types and their sizes from an indexed drive. When using the report document everything is drawn to the report interface, thus you draw a string, an image,a line. the difficulty in here also is, you yourself determine at runtime where your text, lines and images should be positioned</p>
<p>To start with, first drag a PrintPreviewDialog control on your form. The control is named “PrintPreview1”.</p>
<p><a href="http://gilbertadjin.files.wordpress.com/2009/11/image3.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://gilbertadjin.files.wordpress.com/2009/11/image_thumb3.png?w=412&#038;h=170" width="412" height="170" /></a> </p>
<p>Then go to the code view and create&#160; your procedure below.</p>
<p>Private Sub detaildisksreport_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim linesPerPage As Single = 0    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim yPos As Single = 0    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Static count As Integer = 0    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim x, y, c, i As Integer    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim leftMargin As Single = e.MarginBounds.Left    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim topMargin As Single = e.MarginBounds.Top </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;declaring fonts to use in your reports   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim backFont As New Font(&#34;Arial&#34;, 10, FontStyle.Italic)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim HeaderFont As New Font(&#34;Arial&#34;, 20, FontStyle.Bold)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim normfont As New Font(&#34;Times New Roman&#34;, 18, FontStyle.Regular) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216; Calculate the number of lines per page.   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; linesPerPage = e.MarginBounds.Height / normfont.GetHeight(e.Graphics) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;x determines the horizontal positions whiles y determines the vertical position </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216; Drawing an image on top of the report   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim b As Rectangle    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim pic As New Rectangle(40, 5, pic1.Width + 40, pic1.Height + 40)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawImage(pic1.Image, pic) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;drawing a line around the image   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; b = New Rectangle(40, 5, pic1.Width + 40, pic1.Height + 40)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawRectangle(Pens.Black, b) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; linesPerPage = e.MarginBounds.Height / normfont.GetHeight(e.Graphics)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; linesPerPage = linesPerPage &#8211; 5 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216; Drawing our report titles   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; x = 190    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; y = pic1.Height + 70 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(&#34;DETAIL DRIVE REPORT&#34;, HeaderFont, Brushes.Black, x, y) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; y += 40   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; x = 25    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(&#34; FOLDERS ON DRIVE :&#160; &#34; &#38; Me.cmbCat.SelectedItem.ToString.ToUpper, HeaderFont, Brushes.Black, x, y)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; y += 40    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; x = 10    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(&#34;REPORT GENERATED ON &#34; &#38; Now.ToLongDateString.ToUpper, HeaderFont, Brushes.Black, x, y)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; y += 10    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; x = 5 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawLine(Pens.Black, 5, y + 30, 820, y + 30)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; x = 10    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; y += 60    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; c = y </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(&#34;FOLDER NAME&#34;, HeaderFont, Brushes.Blue, x, y)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; x += 260 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(&#34;NUMBER OF FILES&#34;, HeaderFont, Brushes.Blue, x, y)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; x += 330 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(&#34;FOLDER SIZE&#34;, HeaderFont, Brushes.Blue, x, y) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawLine(Pens.Black, 5, y + 30, 820, y + 30) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; x = 33   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; y = c + 40 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; i = 0   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;adding the content to the report    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; For i = count To Me.LsvCDs.Items.Count &#8211; 1 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim len As Integer   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; If LsvCDs.Items.Item(i).SubItems(0).Text.Length &#62; 25 Then    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; len = 25    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Else    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; len = LsvCDs.Items.Item(i).SubItems(0).Text.Length    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; End If </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawImage(Me.SmallImages.Images(0), 15, y + 2) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(Me.LsvCDs.Items.Item(i).SubItems(0).Text.Substring(0, len), normfont, Brushes.Blue, x, y)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; x += 400    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(Me.LsvCDs.Items.Item(i).SubItems(1).Text, normfont, Brushes.Blue, x, y)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; x += 220    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Graphics.DrawString(Me.LsvCDs.Items.Item(i).SubItems(2).Text, normfont, Brushes.Blue, x, y) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8217;setting the y value to point to the next line   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;reseting the x value to the margin    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; y += 30    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; x = 33 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;checking to see if the current page is full   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; If y + normfont.Height &#62; e.PageSettings.PaperSize.Height Then    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; count = i + 1    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.HasMorePages = True    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Return </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; End If   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Next </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; count = 0   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.HasMorePages = False    <br />&#160;&#160;&#160; End Sub</p>
</p>
<p>Also add the code below to a button click event and you are good to go.</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:&#39;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;margin:20px 0 10px;padding:4px;" id="codeSnippetWrapper">
<div style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;" id="codeSnippet">
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum1">   1:</span> <span style="color:#0000ff;">Dim</span> pd <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">New</span> PrintDocument()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum2">   2:</span> <span style="color:#008000;">'adding the print method created to the printdocument printpage event</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum3">   3:</span> <span style="color:#0000ff;">AddHandler</span> pd.PrintPage, <span style="color:#0000ff;">AddressOf</span> disksreport_PrintPage</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum4">   4:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum5">   5:</span> <span style="color:#008000;">'passing the print doucument to the PrintPreviewDialog</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum6">   6:</span> PrintPreview1.Document = pd</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&#39;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;" id="lnum7">   7:</span> PrintPreview1.ShowDialog()</pre>
<p><!--CRLF--></div>
</div>
<p>Below are sample interfaces, using printDocument to generate reports</p>
<p><a href="http://gilbertadjin.files.wordpress.com/2009/11/image4.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://gilbertadjin.files.wordpress.com/2009/11/image_thumb4.png?w=433&#038;h=220" width="433" height="220" /></a> </p>
<p><a href="http://gilbertadjin.files.wordpress.com/2009/11/image5.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://gilbertadjin.files.wordpress.com/2009/11/image_thumb5.png?w=432&#038;h=191" width="432" height="191" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Extensibility Series - WPF &amp; Silverlight Design-Time Code Sharing - Part I]]></title>
<link>http://karlshifflett.wordpress.com/2009/11/20/extensibility-series-wpf-silverlight-design-time-code-sharing-part-i/</link>
<pubDate>Sat, 21 Nov 2009 04:12:31 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/11/20/extensibility-series-wpf-silverlight-design-time-code-sharing-part-i/</guid>
<description><![CDATA[This is the first in series of posts called the “Extensibility Series.”&#160; This series will cover]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is the first in series of posts called the “Extensibility Series.”&#160; This series will cover writing design-times for WPF &#38; Silverlight custom controls for the WPF &#38; Silverlight Designer for Visual Studio 2010 that target .NET 4.0 and Silverlight 3 and 4.&#160; I will use the term Designer for the rest of this article.</p>
<p>Normally in a series you start with a simple example and article.&#160; For this series I need to start with a level 300-400 example because this article and code is for the Development Tools Ecosystem Summit presentation that Mark Boulter and I did.</p>
<p>The presentation was on how to write a design-time assembly that could be shared between WPF and Silverlight custom controls.</p>
<p>Part I of this post covers Feedback and Rating control, design-time assembly discovery, loading and metadata creation.</p>
<p>Part II of this post will cover the control design-time code. (coming after Thanksgiving break)</p>
<p>The code in this post is C#.&#160; (Yes… Karl is now a member of the dark side, but will remain faithful to the bright side.)&#160; The example code is C#.&#160; I will post VB.NET example code after the Thanksgiving break.</p>
<h4>Tutorial Breadcrumb Trail</h4>
<p>When you open the source code solution, be sure to open your Task List window so that you can view and walk the step by step tutorial breadcrumb trail I’ve added to the solution.&#160; When you click on each TODO you’ll be taken to that section of code.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/breadcrumbtrail.png"><img style="display:inline;border-width:0;" title="BreadcrumbTrail" border="0" alt="BreadcrumbTrail" src="http://karlshifflett.files.wordpress.com/2009/11/breadcrumbtrail_thumb.png?w=668&#038;h=227" width="668" height="227" /></a> </p>
<h4>Background</h4>
<p>For the purpose of this article and the code, our fictitious company name is, Cider Controls.&#160; The first control we have ready for release is our WPF &#38; Silverlight Feedback control.&#160; The Feedback control contains our Rating control that allows a value to be selected at run-time using the mouse.&#160; Our assignment is to write a design-time for Visual Studio 2010 for this control.</p>
<p>Note: Setting the rating value at design-time is probably something the control does not actually need.&#160; However, it serves its purpose by illustrating how to use the extensibility features of the Designer. </p>
<h4>WPF &#38; Silverlight Feedback Control</h4>
<table border="0" cellspacing="10" cellpadding="5">
<tbody>
<tr>
<td valign="top"><a href="http://karlshifflett.files.wordpress.com/2009/11/feedbackcontrol.png"><img style="display:inline;border-width:0;" title="FeedbackControl" border="0" alt="FeedbackControl" src="http://karlshifflett.files.wordpress.com/2009/11/feedbackcontrol_thumb.png?w=317&#038;h=189" width="317" height="189" /></a> </td>
<td valign="top"><a href="http://karlshifflett.files.wordpress.com/2009/11/feedbackcontrolclassdiagram.png"><img style="display:inline;border-width:0;" title="FeedbackControlClassDiagram" border="0" alt="FeedbackControlClassDiagram" src="http://karlshifflett.files.wordpress.com/2009/11/feedbackcontrolclassdiagram_thumb.png?w=190&#038;h=288" width="190" height="288" /></a> </td>
</tr>
</tbody>
</table>
<p>The blue text is the Header property.&#160; This property is of type Object.&#160; Developers can supply simple text or use nested XAML to create any type of Header they want.</p>
<p>The text under the Header is the CommentHeading property which is a String.</p>
<p>The TextBox is bound to the Comment property which is a String.</p>
<p>The <strong><font size="5">. . . . .</font></strong> is the Rating control.&#160; This is bound to the Value property which is an Integer.</p>
<p>The CornerRadius property binds to the Border control in the control template.</p>
<p>The Submit Button is enabled when the Value is greater than zero and the Comment is not empty or null.</p>
<h4>Required Design-Time Features</h4>
<ul>
<li>Support both the WPF &#38; Silverlight versions of the Feedback control </li>
<li>Set control value at design-time using a context menu </li>
<li>Set control value at design-time using the Rating control in an adorner </li>
<li>Set control value at design-time using the Rating control is the properties window </li>
<li>Set all control properties in the properties window </li>
<li>Provide a Category Editor for the properties window that allows editing the Feedback control properties assigned to the Custom category </li>
</ul>
<h5>Features</h5>
<h6>Menu Action</h6>
<p>The Feedback Value property is zero.&#160; </p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/menuaction.png"><img style="display:inline;border-width:0;" title="MenuAction" border="0" alt="MenuAction" src="http://karlshifflett.files.wordpress.com/2009/11/menuaction_thumb.png?w=443&#038;h=497" width="443" height="497" /></a></p>
<h6>Adorner</h6>
<p>After the Feedback Value property has been set, both the control and adorner display the value.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/adorner.png"><img style="display:inline;border-width:0;" title="Adorner" border="0" alt="Adorner" src="http://karlshifflett.files.wordpress.com/2009/11/adorner_thumb.png?w=373&#038;h=281" width="373" height="281" /></a> </p>
<h6>Inline Value Editor</h6>
<p>Inline Value editor uses the Rating control just like the Feedback control and adorner.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/valueeditor.png"><img style="display:inline;border-width:0;" title="ValueEditor" border="0" alt="ValueEditor" src="http://karlshifflett.files.wordpress.com/2009/11/valueeditor_thumb.png?w=381&#038;h=109" width="381" height="109" /></a></p>
<h6>Category Editor</h6>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/categoryview.png"><img style="display:inline;border-width:0;" title="CategoryView" border="0" alt="CategoryView" src="http://karlshifflett.files.wordpress.com/2009/11/categoryview_thumb.png?w=382&#038;h=193" width="382" height="193" /></a>&#160; </p>
<h6>Design-time XAML</h6>
<p>Notice the Feedback Header that takes XAML.&#160; You could easily add a Grid or StackPanel and then display and image and text if you wanted.</p>
<div class="code">
<pre><span style="color:blue;">&#60;</span><span style="color:#a31515;">cc</span><span style="color:blue;">:</span><span style="color:#a31515;">Feedback
    </span><span style="color:red;">HorizontalAlignment</span><span style="color:blue;">=&#34;Left&#34; </span><span style="color:red;">Grid.Column</span><span style="color:blue;">=&#34;1&#34;
    </span><span style="color:red;">VerticalAlignment</span><span style="color:blue;">=&#34;Top&#34; </span><span style="color:red;">Height</span><span style="color:blue;">=&#34;176&#34; </span><span style="color:red;">Width</span><span style="color:blue;">=&#34;304&#34;
    </span><span style="color:red;">CommentHeading</span><span style="color:blue;">=&#34;Write a design time for your control today.&#34;
    </span><span style="color:red;">CornerRadius</span><span style="color:blue;">=&#34;10&#34;
    </span><span style="color:red;">Padding</span><span style="color:blue;">=&#34;3&#34;
    </span><span style="color:red;">BorderBrush</span><span style="color:blue;">=&#34;DarkGray&#34;
    </span><span style="color:red;">BorderThickness</span><span style="color:blue;">=&#34;3&#34;
    </span><span style="color:red;">Background</span><span style="color:blue;">=&#34;WhiteSmoke&#34; </span><span style="color:red;">Value</span><span style="color:blue;">=&#34;3&#34; </span><span style="color:red;">Margin</span><span style="color:blue;">=&#34;12,24,0,0&#34;&#62;

    &#60;</span><span style="color:#a31515;">cc</span><span style="color:blue;">:</span><span style="color:#a31515;">Feedback.Header</span><span style="color:blue;">&#62;
        &#60;</span><span style="color:#a31515;">TextBlock
            </span><span style="color:red;">Foreground</span><span style="color:blue;">=&#34;Blue&#34; </span><span style="color:red;">FontSize</span><span style="color:blue;">=&#34;16&#34; </span><span style="color:red;">FontWeight</span><span style="color:blue;">=&#34;Bold&#34;
            </span><span style="color:red;">Text</span><span style="color:blue;">=&#34;Control Design Time Example&#34; /&#62;
    &#60;/</span><span style="color:#a31515;">cc</span><span style="color:blue;">:</span><span style="color:#a31515;">Feedback.Header</span><span style="color:blue;">&#62;

&#60;/</span><span style="color:#a31515;">cc</span><span style="color:blue;">:</span><span style="color:#a31515;">Feedback</span><span style="color:blue;">&#62;

</span></pre>
</div>
<h4>Design-Time Assembly Locating</h4>
<p>Writing a design-time for a control is actually pretty simple and the code tends to be small blocks since each individual feature you add is almost self-contained.</p>
<p>There are two complicated pieces, metadata loading and Toolbox installation.&#160; </p>
<p>Simplified:&#160; Metadata loading is the design-time process that Visual Studio uses to discover and associate your design-time code with your control so that the Designer will run it at design-time when you want it to.</p>
<p>I’ll cover Toolbox installation in my next Extensibility Series post.</p>
<p>These two can be complicated because there are different ways to do both, some can involve the registry, some involve multiple assemblies and both depend on a naming convention.&#160; In other words, when you first look at this, you’ll think there are a number of moving parts, but after you’ve done this a few times, you’ll have it down.</p>
<h5>Design-Time Load Scenarios</h5>
<ul>
<li>WPF Custom Control Designer &#8211; (single design assembly) </li>
<li>Silverlight Custom Control Designer &#8211; (single or two design assemblies) </li>
<li>Code Sharing for WPF &#38; Silverlight controls (five design assemblies) </li>
</ul>
<p><strong>Note</strong>:&#160; You can use other techniques for reducing the number of assemblies when doing multi-platform design-times, but they can lead to bugs and confusion due to platform mixing and won’t be discussed here.</p>
<p>For this post I’ll only cover the, “Code Sharing for WPF &#38; Silverlight controls” scenario.&#160; The techniques that I’ll describe here are used in Microsoft production code and simplify code sharing.&#160; In future posts I’ll cover the other design-time load scenarios and techniques.</p>
<h5>Design-Time Assembly Naming and Location</h5>
<table border="1" cellspacing="1" cellpadding="3">
<tbody>
<tr>
<td valign="top"><strong>Assembly name</strong></td>
<td valign="top"><strong>Notes</strong></td>
</tr>
<tr>
<td valign="top">CiderControls.WPF.dll</td>
<td valign="top">Custom Control Run-Time Assembly</td>
</tr>
<tr>
<td valign="top">CiderControls.WPF.Design.*.dll</td>
<td valign="top">Loaded by Visual Studio and Blend</td>
</tr>
<tr>
<td valign="top">\Design\CiderControls.WPF.Design.*.dll</td>
<td valign="top">Located in the \Design sub folder.&#160; Loaded by Visual Studio and Blend</td>
</tr>
<tr>
<td valign="top">CiderControls.WPF.VisualStudio.Design.*.dll</td>
<td valign="top">Loaded only by Visual Studio</td>
</tr>
<tr>
<td valign="top">CiderControls.WPF.Expression.Design.*.dll</td>
<td valign="top">Loaded only by Blend</td>
</tr>
<tr>
<td valign="top">\Design\CiderControls.WPF.VisualStudio.Design.*.dll</td>
<td valign="top">Loaded only by Visual Studio</td>
</tr>
<tr>
<td valign="top">\Design\CiderControls.WPF.Expression.Design.*.dll</td>
<td valign="top">Loaded only by by Blend</td>
</tr>
</tbody>
</table>
<p>Looking closely at the above table, you’ll see a naming pattern.&#160; The control assembly can be named whatever the control author wants.&#160; Typically you’ll see the vendor name followed by the product and possibly version number. </p>
<p>The design-time assemblies must be named according to the above table in order for Visual Studio to load them.</p>
<p>For metadata loading Visual Studio loads the .dll’s in the above order.&#160; Meaning .VisualStudio.Design. qualified .dll’s will load second and overwrite metadata in the .Design dll. </p>
<p>The “*” represents optional additional name text that the design-time assembly author can add.&#160; Normally this is not used.&#160; This provides a way to ship additional design assemblies that follow the above naming convention.&#160; (See next paragraph.)</p>
<p>When the metadata is loaded there is one more consideration that is taken into account.&#160; The version number of the Microsoft.Windows.Design.Extensibility.dll or Microsoft.Windows.Design.Interaction.dll that the design-time assembly is compiled against will be compared to those versions on the target machine.</p>
<p>For readability I’ll use MWD in place of Microsoft.Windows.Design.Extensibility.dll in the next short section.</p>
<p>The Design.*.dll nomenclature allows for multiple design assemblies fitting a pattern such as “foo.Design.*.dll”, one for each version of the MWD interface.&#160; Zero or one assembly fitting a pattern will load: </p>
<ul>
<li>If the MWD version referenced by the design-time assembly has a different major version number than the user’s machine MWD version, then the design-time assembly will not load and is bypassed. </li>
<li>If more than one design-time assembly is compatible with the user’s machine MWD version, the Designer loads the version compiled against the highest MWD version that is less than or equal to the user’s machine MWD version. </li>
</ul>
<p>For instance, if the user’s machine MWD version is 4.1.3.0 and there are 4 design-time assemblies matching the pattern “foo.design*.dll”, each compiled against the below MWD versions, the designer reacts as follows: </p>
<ul>
<li>3.0.1.0: Will not load.&#160; Incompatible API version. </li>
<li>4.0.1.0: Would load if there were not a higher matching version, but since 4.1.1.0 exists it does not load&#160; </li>
<li>4.1.1.0: Version loaded as it is closest to the current version number without exceeding it </li>
<li>4.3.0.0: Will not load in the Designer as it was built against a newer version of the MWD’s </li>
</ul>
<h5>Metadata and Design Code</h5>
<p>The design-time assembly does not have to actually have any design time code in it.&#160; In fact as you’ll see shortly, the two design-time assemblies that our solution has that follow the above naming convention only serve as shims between Visual Studio 2010 and our common WPF and Silverlight design-time assembly that does all the work.</p>
<p><strong>WPF</strong></p>
<p>The below screen shot pictures the WPF run-time custom control folder and contents.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/cidercontrolsfolderone.png"><img style="display:inline;border-width:0;" title="CiderControlsFolderOne" border="0" alt="CiderControlsFolderOne" src="http://karlshifflett.files.wordpress.com/2009/11/cidercontrolsfolderone_thumb.png?w=655&#038;h=86" width="655" height="86" /></a></p>
<p>The below screen shot pictures the contents of the \Design\ subfolder. </p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/cidercontrolsfoldertwo.png"><img style="display:inline;border-width:0;" title="CiderControlsFolderTwo" border="0" alt="CiderControlsFolderTwo" src="http://karlshifflett.files.wordpress.com/2009/11/cidercontrolsfoldertwo_thumb.png?w=679&#038;h=115" width="679" height="115" /></a> </p>
<p>In the above image, CiderControls.WPF.VisualStudio.Design.dll is the assembly that Visual Studio will discover and load the design-time metadata from.&#160; </p>
<p>CiderControls.Common.VisualStudio.Design.dll is in this folder because it is referenced by CiderControls.WPF.VisualStudio.Design.dll.</p>
<p>CiderControls.WPF.dll is in this folder because it is referenced by the common design-time assembly CiderControls.Common.VisualStudio.Design.dll.</p>
<p><strong>Silverlight</strong></p>
<p>The below screen shot pictures the Silverlight run-time custom control folder and contents.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/cidercontrolsslfolderone.png"><img style="display:inline;border-width:0;" title="CiderControlsSLFolderOne" border="0" alt="CiderControlsSLFolderOne" src="http://karlshifflett.files.wordpress.com/2009/11/cidercontrolsslfolderone_thumb.png?w=663&#038;h=82" width="663" height="82" /></a> </p>
<p>The below screen shot pictures the contents of the \Design\ subfolder.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/cidercontrolsslfoldertwo.png"><img style="display:inline;border-width:0;" title="CiderControlsSLFolderTwo" border="0" alt="CiderControlsSLFolderTwo" src="http://karlshifflett.files.wordpress.com/2009/11/cidercontrolsslfoldertwo_thumb.png?w=700&#038;h=134" width="700" height="134" /></a> </p>
<p>In the above image, CiderControls.Silverlight.VisualStudio.Design.dll is the assembly that Visual Studio will discover and load the design-time metadata from.&#160; </p>
<p>CiderControls.Common.VisualStudio.Design.dll is in this folder because it is referenced by CiderControls.Silverlight.VisualStudio.Design.dll.</p>
<p>CiderControls.Silverlight.VisualStudio.Design.Types.dll is in this folder because it is referenced by CiderControls.Common.VisualStudio.Design.dll and CiderControls.Silverlight.VisualStudio.Design.dll.&#160; </p>
<blockquote>
<p>The above two file references are not a project references but a file or binary references.&#160; When this reference is added, the browse button is used to browse to the CiderControls.Silverlight.dll and the reference added to the file.</p>
</blockquote>
<p>CiderControls.Silverlight.dll is in this folder because it is referenced by CiderControls.Silverlight.VisualStudio.Design.Types.dll.</p>
<p>CiderControls.WPF.dll is in this folder because it is referenced by the common design-time assembly CiderControls.Common.VisualStudio.Design.dll.</p>
<p><strong>Note</strong>: CiderControls.Silverlight.dll and CiderControls.Silverlight.VisualStudio.Design.Types.dll are the only two assemblies that actually reference Silverlight, the remaining assemblies are all WPF assemblies.</p>
<h5>Design Subfolder</h5>
<p>In both of the above series of images, the \Design subfolder is under the \Bin\Debug folder for each custom control assembly.&#160; During development, the best way to populate the \Design subfolder is to set up a Post-build event.&#160; Now your design-time test projects only need to reference the design-time assembly and Visual Studio will automatically load your design-time assembly for you.</p>
<p>For the CiderControls.WPF.VisualStudio.Design.dll project I’m using the following Post-build event command line:</p>
<p>&#160;&#160;&#160; xcopy &#34;$(TargetDir)*.*&#34;&#160;&#160; &#34;$(SolutionDir)\CiderControls.WPF\Bin\Debug\Design&#34; /S /I /Y</p>
<p>For the CiderControls.Silverlight.VisualStudio.Design.dll project I’m using the following Post-build event command line:</p>
<p>&#160;&#160;&#160; xcopy &#34;$(TargetDir)*.*&#34;&#160;&#160; &#34;$(SolutionDir)\CiderControls.Silverlight\Bin\Debug\Design&#34; /S /I /Y</p>
<h4>WPF Metadata Loading</h4>
<p>Visual Studio locating your correctly named design-time assembly is step one.&#160; That assembly must also decorated with the ProvideMetadata attribute: </p>
<p>&#160; <font face="Consolas">[</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas">assembly</font></font><font face="Consolas">: </font><font color="#2b91af" face="Consolas"><font color="#2b91af" face="Consolas">ProvideMetadata</font></font><font face="Consolas">(</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas">typeof</font></font><font face="Consolas">(</font><font color="#2b91af" face="Consolas"><font color="#2b91af" face="Consolas">RegisterMetadata</font></font><font face="Consolas">))]</font></p>
<p>The ProvideMetadata constructor requires that a type be passed in.&#160; That type must implement the IProvideAttributeTable interface.</p>
<p>IProvideAttributeTable interface has a single read-only property AttributeTable that returns an AttributeTable.</p>
<p>Below is the RegisterMetadata class that is in the CiderControls.WPF.VisualStudio.Design project.</p>
<div class="code">
<pre><span style="color:blue;">using </span>CiderControls.Common.VisualStudio.Design.Registration;
<span style="color:blue;">using </span>CiderControls.WPF.VisualStudio.Design;
<span style="color:blue;">using </span>Microsoft.Windows.Design.Metadata;

[<span style="color:blue;">assembly</span>: <span style="color:#2b91af;">ProvideMetadata</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">RegisterMetadata</span>))]

<span style="color:blue;">namespace </span>CiderControls.WPF.VisualStudio.Design {

  <span style="color:blue;">internal class </span><span style="color:#2b91af;">RegisterMetadata </span>: <span style="color:#2b91af;">IProvideAttributeTable </span>{

    <span style="color:#2b91af;">AttributeTable IProvideAttributeTable</span>.AttributeTable {
      <span style="color:blue;">get </span>{
        <span style="color:#2b91af;">CiderControlsAttributeTableBuilder </span>builder =
            <span style="color:blue;">new </span><span style="color:#2b91af;">CiderControlsAttributeTableBuilder</span>(<span style="color:blue;">new </span><span style="color:#2b91af;">WPFTypeResolver</span>());
        <span style="color:blue;">return </span>builder.CreateTable();
      }
    }
  }
}</pre>
</div>
<p>Within the AttributeTable property we instantiate the CiderControlsAttributeTableBuilder class that derives from AttributeTableBuilder.&#160; AttributeTableBuilder provides the CreateTable method.&#160; </p>
<p>The CiderControlsAttributeTableBuilder is located in the “platform neutral” CiderControls.Common.VisualStudio.Design assembly. </p>
<p>The WPFTypeResolver is passed into the CiderControlsAttributeTableBuilder constructor.&#160; This class allows the “platform neutral” CiderControls.Common.VisualStudio.Design assembly to resolve WPF types in our run-time control assembly by referring to them with platform neutral <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.metadata.typeidentifier(VS.100).aspx" target="_blank">TypeIdentifiers</a>.&#160; The WPFTypeResolver is located in the CiderControls.WPF.VisualStudio.Design project.</p>
<p>The CiderControlsAttributeTableBuilder is the platform neutral class that does all the heavy lifting for creating the required AttributeTable; also know as our metadata.</p>
<p>Below is the WPFTypeResolver class that is in the CiderControls.WPF.VisualStudio.Design project.&#160; The GetPlatformType method takes a platform neutral TypeIdentifier and returns a platform specific type.</p>
<div class="code">
<pre><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>CiderControls.Common.VisualStudio.Design.Infrastructure;
<span style="color:blue;">using </span>CiderControls.Common.VisualStudio.Design.Registration;
<span style="color:blue;">using </span>Microsoft.Windows.Design.Metadata;

<span style="color:blue;">namespace </span>CiderControls.WPF.VisualStudio.Design {

  <span style="color:blue;">internal class </span><span style="color:#2b91af;">WPFTypeResolver </span>: <span style="color:#2b91af;">RegistrationTypeResolver </span>{

    <span style="color:blue;">public override </span><span style="color:#2b91af;">Type </span>GetPlatformType(<span style="color:#2b91af;">TypeIdentifier </span>id) {
      <span style="color:blue;">switch </span>(id.Name) {

        <span style="color:blue;">case </span><span style="color:#2b91af;">Constants</span>.STR_CIDERCONTROLSFEEDBACK:
          <span style="color:blue;">return typeof</span>(CiderControls.<span style="color:#2b91af;">Feedback</span>);

        <span style="color:blue;">case </span><span style="color:#2b91af;">Constants</span>.STR_CIDERCONTROLSRATING:
          <span style="color:blue;">return typeof</span>(CiderControls.<span style="color:#2b91af;">Rating</span>);
      }

      <span style="color:blue;">throw new </span><span style="color:#2b91af;">ArgumentOutOfRangeException</span>(<span style="color:#a31515;">&#34;id.Name&#34;</span>, id.Name, message...);
    }
  }
}</pre>
</div>
<h4>Silverlight Metadata Loading</h4>
<p>Visual Studio locating your correctly named design-time assembly is step one.&#160; That assembly must also decorated with the ProvideMetadata attribute: </p>
<p>&#160; <font face="Consolas">[</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas">assembly</font></font><font face="Consolas">: </font><font color="#2b91af" face="Consolas"><font color="#2b91af" face="Consolas">ProvideMetadata</font></font><font face="Consolas">(</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas">typeof</font></font><font face="Consolas">(</font><font color="#2b91af" face="Consolas"><font color="#2b91af" face="Consolas">RegisterMetadata</font></font><font face="Consolas">))]</font></p>
<p>The ProvideMetadata constructor requires that a type be passed in.&#160; That type must implement the IProvideAttributeTable interface.</p>
<p>IProvideAttributeTable interface has a single read-only property AttributeTable that returns an AttributeTable.</p>
<p>Below is the RegisterMetadata class that is in the CiderControls.Silverlight.VisualStudio.Design project.</p>
<div class="code">
<pre><span style="color:blue;">using </span>CiderControls.Common.VisualStudio.Design.Registration;
<span style="color:blue;">using </span>CiderControls.Silverlight.VisualStudio.Design;
<span style="color:blue;">using </span>Microsoft.Windows.Design.Metadata;

[<span style="color:blue;">assembly</span>: <span style="color:#2b91af;">ProvideMetadata</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">RegisterMetadata</span>))]

<span style="color:blue;">namespace </span>CiderControls.Silverlight.VisualStudio.Design {

  <span style="color:blue;">internal class </span><span style="color:#2b91af;">RegisterMetadata </span>: <span style="color:#2b91af;">IProvideAttributeTable </span>{

    <span style="color:#2b91af;">AttributeTable IProvideAttributeTable</span>.AttributeTable {
      <span style="color:blue;">get </span>{
        <span style="color:#2b91af;">CiderControlsAttributeTableBuilder </span>builder =
          <span style="color:blue;">new </span><span style="color:#2b91af;">CiderControlsAttributeTableBuilder</span>(<span style="color:blue;">new </span><span style="color:#2b91af;">SilverlightTypeResolver</span>());
        <span style="color:blue;">return </span>builder.CreateTable();
      }
    }
  }
}</pre>
</div>
<p>Within the AttributeTable property we instantiate the CiderControlsAttributeTableBuilder class that derives from AttributeTableBuilder.&#160; AttributeTableBuilder provides the CreateTable method.&#160; </p>
<p>The CiderControlsAttributeTableBuilder is located in the “platform neutral” CiderControls.Common.VisualStudio.Design assembly. </p>
<p>The SilverlightTypeResolver is passed into the CiderControlsAttributeTableBuilder constructor.&#160; This class allows the “platform neutral” CiderControls.Common.VisualStudio.Design assembly to resolve Silverlight types in our run-time control assembly by referring to them with platform neutral <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.metadata.typeidentifier(VS.100).aspx" target="_blank">TypeIdentifiers</a>.&#160; The SilverlightTypeResolver is located in the CiderControls.Silverlight.VisualStudio.Design project.</p>
<p>The CiderControlsAttributeTableBuilder is the platform neutral class that does all the heavy lifting for creating the required AttributeTable; also know as our metadata.</p>
<p>Below is the SilverlightTypeResolver class that is in the CiderControls.Silverlight.VisualStudio.Design project.&#160; The GetPlatformType method takes a platform neutral TypeIdentifier and returns a platform specific type.</p>
<div class="code">
<pre><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>CiderControls.Common.VisualStudio.Design.Infrastructure;
<span style="color:blue;">using </span>CiderControls.Common.VisualStudio.Design.Registration;
<span style="color:blue;">using </span>CiderControls.Silverlight.VisualStudio.Design.Types;
<span style="color:blue;">using </span>Microsoft.Windows.Design.Metadata;

<span style="color:blue;">namespace </span>CiderControls.Silverlight.VisualStudio.Design {

  <span style="color:blue;">internal class </span><span style="color:#2b91af;">SilverlightTypeResolver </span>: <span style="color:#2b91af;">RegistrationTypeResolver </span>{

    <span style="color:blue;">public override </span><span style="color:#2b91af;">Type </span>GetPlatformType(<span style="color:#2b91af;">TypeIdentifier </span>id) {
      <span style="color:blue;">switch </span>(id.Name) {

        <span style="color:blue;">case </span><span style="color:#2b91af;">Constants</span>.STR_CIDERCONTROLSFEEDBACK:
          <span style="color:blue;">return </span><span style="color:#2b91af;">SilverlightTypes</span>.FeedbackControlType;

        <span style="color:blue;">case </span><span style="color:#2b91af;">Constants</span>.STR_CIDERCONTROLSRATING:
          <span style="color:blue;">return </span><span style="color:#2b91af;">SilverlightTypes</span>.RatingControlType;

      }

      <span style="color:blue;">throw new </span><span style="color:#2b91af;">ArgumentOutOfRangeException</span>(<span style="color:#a31515;">&#34;id.Name&#34;</span>, id.Name, message...);
    }
  }
}</pre>
</div>
<p>This assembly, CiderControls.Silverlight.VisualStudio.Design is a WPF assembly.&#160; Notice that we are not directly returning a Silverlight type by using the typeof method.&#160; Instead we are returning a type that is located in the CiderControls.Silverlight.VisualStudio.Design.Types assembly and is exposed by static properties in the SivlerlightTypes class below.</p>
<p>The CiderControls.Silverlight.VisualStudio.Design.Types assembly has a project reference to the Sivlerlight controls run-time assembly.</p>
<pre class="code"><span style="color:blue;">using </span>System;

[<span style="color:blue;">assembly</span>:
  System.Runtime.CompilerServices.<span style="color:#2b91af;">InternalsVisibleTo</span>(<span style="color:#a31515;">&#34;CiderControls.Silverlight.VisualStudio.Design&#34;</span>)]

[<span style="color:blue;">assembly</span>:
  System.Runtime.CompilerServices.<span style="color:#2b91af;">InternalsVisibleTo</span>(<span style="color:#a31515;">&#34;CiderControls.Common.VisualStudio.Design&#34;</span>)]

<span style="color:blue;">namespace </span>CiderControls.Silverlight.VisualStudio.Design.Types {

  <span style="color:blue;">internal class </span><span style="color:#2b91af;">SilverlightTypes </span>{

    <span style="color:blue;">public static readonly </span><span style="color:#2b91af;">Type </span>FeedbackControlType = <span style="color:blue;">typeof</span>(CiderControls.<span style="color:#2b91af;">Feedback</span>);
    <span style="color:blue;">public static readonly </span><span style="color:#2b91af;">Type </span>RatingControlType = <span style="color:blue;">typeof</span>(CiderControls.<span style="color:#2b91af;">Rating</span>);
  }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>I’ve made use of the <a href="http://msdn.microsoft.com/en-us/library/0tke9fxk(VS.100).aspx" target="_blank">Friend Assemblies</a> feature that allows all my classes in the solution to be internal.&#160; For VB.NET they will all be scoped as Friend.</p>
<h5>Silverlight Type Resolution </h5>
<p>By now you understand that the CiderControlsAttributeTableBuilder is “platform neutral” and is located in the CiderControls.Common.VisualStudio.Design assembly.</p>
<p>You know that the SiverlightTypeResolver will be pass into the CiderControlsAttributeTableBuilder constructor.&#160; CiderControlsAttributeTableBuilder is the same class that the WPFTypeResolver will be passed into also.</p>
<p>When the CiderControlsAttributeTableBuilder needs to resolve a type it will pass a platform neutral TypeIdentifier to one of the TypeResolvers, they in turn will return a platform specific type.</p>
<p>For Silverlight only, the SiverlightTypeResolver will use the SilverlightTypes class to perform the actual type resolution.</p>
<p>While this seems confusing at first, it is the best way to allow Silverlight types to be resolved in a platform neutral fashion and without polluting a WPF assembly with Silverlight types.</p>
<h4>Metadata Building</h4>
<p>CiderControlsAttributeTableBuilder does the heavy lifting and is responsible for creating the AttributeTable required by Visual Studio.&#160; This code is platform neutral, meaning it returns an AttributeTable for WPF or Silverlight without having to directly reference the run-time assembly controls inside its code.</p>
<p>For the below code, I left the comments in place to make reading a large section of code much easier.&#160; The comments inline explain what is going on.</p>
<p>You’ll notice how the WPFTypeResolver and the SiverlightTypeResolver are used in this code.&#160; The module level variable _registrationTypeResolver holds a reference to the TypeResolver that is used to resolve platform specific types using the platform neutral TypeIdentifier.</p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>System.ComponentModel;
<span style="color:blue;">using </span>CiderControls.Common.VisualStudio.Design.Controls;
<span style="color:blue;">using </span>CiderControls.Common.VisualStudio.Design.Infrastructure;
<span style="color:blue;">using </span>Microsoft.Windows.Design.Features;
<span style="color:blue;">using </span>Microsoft.Windows.Design.Metadata;
<span style="color:blue;">using </span>Microsoft.Windows.Design.PropertyEditing;
<span style="color:blue;">using </span>Microsoft.Windows.Design;

<span style="color:green;">//
// This should be in AssemblyInfo.cs - declaring here to make it obvious
//

</span>[<span style="color:blue;">assembly</span>:
  System.Runtime.CompilerServices.<span style="color:#2b91af;">InternalsVisibleTo</span>(<span style="color:#a31515;">&#34;CiderControls.WPF.VisualStudio.Design&#34;</span>)]

[<span style="color:blue;">assembly</span>:
  System.Runtime.CompilerServices.<span style="color:#2b91af;">InternalsVisibleTo</span>(<span style="color:#a31515;">&#34;CiderControls.Silverlight.VisualStudio.Design&#34;</span>)]

<span style="color:blue;">namespace </span>CiderControls.Common.VisualStudio.Design.Registration {

  <span style="color:green;">//TODO  5 - CiderControlsAttributeTableBuilder

  </span><span style="color:gray;">/// &#60;summary&#62;
  /// </span><span style="color:green;">Platform neutral class that builds platform specific metadata
  </span><span style="color:gray;">/// &#60;/summary&#62;
  </span><span style="color:blue;">internal class </span><span style="color:#2b91af;">CiderControlsAttributeTableBuilder </span>: <span style="color:#2b91af;">AttributeTableBuilder </span>{

    <span style="color:green;">// allows for Platform specific Types to be used without directly referencing Silverlight
    </span><span style="color:blue;">private </span><span style="color:#2b91af;">RegistrationTypeResolver </span>_registrationTypeResolver;

    <span style="color:green;">//TODO  6 - registrationTypeResolver resolves the platform specific Types in the platform neutral
    //          metadata builder
    </span><span style="color:blue;">public </span>CiderControlsAttributeTableBuilder(<span style="color:#2b91af;">RegistrationTypeResolver </span>registrationTypeResolver) {
      _registrationTypeResolver = registrationTypeResolver;

      AddFeedbackControlAttributes();
      AddRatingControlAttributes();
    }

    <span style="color:gray;">/// &#60;summary&#62;
    /// </span><span style="color:green;">Builds Feedback control metedata
    </span><span style="color:gray;">/// &#60;/summary&#62;
    </span><span style="color:blue;">private void </span>AddFeedbackControlAttributes() {

      <span style="color:green;">//TODO  7 - Resolve the Platform specific Feedback control from the platform neutral
      //          TypeIdentifier
      </span><span style="color:#2b91af;">Type </span>feebackType = _registrationTypeResolver.GetPlatformType(<span style="color:#2b91af;">MyPlatformTypes</span>.<span style="color:#2b91af;">Feedback</span>.TypeId);

      <span style="color:green;">//TODO  9 - Using the above feedbackType, create platform specific metadata for the Feedback
      //          control the below code adds features, catetory editor, inline editor, type converter
      //          and assigns a Category to each Feedback control property

      </span>AddTypeAttributes(feebackType,
          <span style="color:blue;">new </span><span style="color:#2b91af;">FeatureAttribute</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">FeedbackControlInitializer</span>)),
          <span style="color:blue;">new </span><span style="color:#2b91af;">FeatureAttribute</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">FeedbackControlContextMenuProvider</span>)),
          <span style="color:blue;">new </span><span style="color:#2b91af;">FeatureAttribute</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">FeedbackControlAdornerProvider</span>))
          );

      AddCategoryEditor(feebackType,
          <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">FeedbackControlCategoryEditor</span>));

      AddMemberAttributes(feebackType,
          <span style="color:#2b91af;">Constants</span>.STR_CORNERRADIUS,
          <span style="color:blue;">new </span><span style="color:#2b91af;">CategoryAttribute</span>(<span style="color:#2b91af;">Constants</span>.STR_COMMON));

      <span style="color:green;">// since the below Header property is of type object, it requires this
      // StringConverter to enable editing of simple string values in the properties window.
      </span>AddMemberAttributes(feebackType,
          <span style="color:#2b91af;">Constants</span>.STR_HEADER,
          <span style="color:blue;">new </span><span style="color:#2b91af;">CategoryAttribute</span>(<span style="color:#2b91af;">Constants</span>.STR_CUSTOM),
          <span style="color:blue;">new </span><span style="color:#2b91af;">TypeConverterAttribute</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">StringConverter</span>)));

      AddMemberAttributes(feebackType,
          <span style="color:#2b91af;">Constants</span>.STR_VALUE,
          <span style="color:blue;">new </span><span style="color:#2b91af;">CategoryAttribute</span>(<span style="color:#2b91af;">Constants</span>.STR_CUSTOM),
          <span style="color:#2b91af;">PropertyValueEditor</span>.CreateEditorAttribute(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">RatingSelectorInlineEditor</span>)));

      AddMemberAttributes(feebackType,
          <span style="color:#2b91af;">Constants</span>.STR_COMMENT,
          <span style="color:blue;">new </span><span style="color:#2b91af;">CategoryAttribute</span>(<span style="color:#2b91af;">Constants</span>.STR_CUSTOM));

      AddMemberAttributes(feebackType,
          <span style="color:#2b91af;">Constants</span>.STR_COMMENTHEADING,
          <span style="color:blue;">new </span><span style="color:#2b91af;">CategoryAttribute</span>(<span style="color:#2b91af;">Constants</span>.STR_CUSTOM));

    }

    <span style="color:gray;">/// &#60;summary&#62;
    /// </span><span style="color:green;">Builds Rating control metedata
    </span><span style="color:gray;">/// &#60;/summary&#62;
    </span><span style="color:blue;">private void </span>AddRatingControlAttributes() {

      <span style="color:green;">//TODO  7.1 - Resolve the Platform specific Rating control from the platform neutral
      //            TypeIdentifier
      </span><span style="color:#2b91af;">Type </span>ratingType = _registrationTypeResolver.GetPlatformType(<span style="color:#2b91af;">MyPlatformTypes</span>.<span style="color:#2b91af;">Rating</span>.TypeId);

      <span style="color:green;">//TODO  9.1 - Using the above ratingType, create platform specific metadata for the Rating
      //            control the below code keeps the Rating control from appearing in the
      //            Choose Items dialog after the CiderControls.WPF or CiderControls.Siverlight
      //            assembly is added.
      //
      // this is only done for illustration, there is no actual reason to keep the Rating control
      // out of the Choose Items dialog.
      </span>AddTypeAttributes(ratingType,
          <span style="color:blue;">new </span><span style="color:#2b91af;">ToolboxBrowsableAttribute</span>(<span style="color:blue;">false</span>)
          );
    }

    <span style="color:blue;">private void </span>AddTypeAttributes(<span style="color:#2b91af;">Type </span>type, <span style="color:blue;">params </span><span style="color:#2b91af;">Attribute</span>[] attribs) {
      <span style="color:blue;">base</span>.AddCallback(type, builder =&#62; builder.AddCustomAttributes(attribs));
    }

    <span style="color:blue;">private void </span>AddCategoryEditor(<span style="color:#2b91af;">Type </span>type, <span style="color:#2b91af;">Type </span>editorType) {
      <span style="color:blue;">base</span>.AddCallback(type, builder =&#62;
         builder.AddCustomAttributes(<span style="color:#2b91af;">CategoryEditor</span>.CreateEditorAttribute(editorType)));
    }

    <span style="color:blue;">private void </span>AddMemberAttributes(<span style="color:#2b91af;">Type </span>type, <span style="color:blue;">string </span>memberName, <span style="color:blue;">params </span><span style="color:#2b91af;">Attribute</span>[] attribs) {
      <span style="color:blue;">base</span>.AddCallback(type, builder =&#62; builder.AddCustomAttributes(memberName, attribs));
    }
  }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The last three methods are helper methods that make the metadata code cleaner and easier to read.</p>
<p>In the next Part II of this article, I’ll tie the above attributes to each of the design-time features.</p>
<h4>Downloads</h4>
<p><a href="http://code.msdn.microsoft.com/DesignerExtensbility/Release/ProjectReleases.aspx?ReleaseId=3583" target="_blank">Source Code Download</a></p>
<p><a href="http://cid-51de981e071f222b.skydrive.live.com/self.aspx/Public/ExtensibilityPresentationSlides/ControlDesigntimesForSilverlightAndWPF.zip" target="_blank">PowerPoint Slides from the Development Tools Ecosystem Summit Presentation</a></p>
<h4>Online Documentation Status</h4>
<p>Almost all of MSDN and most examples you’ll see on the Internet use the interfaces from Visual Studio 2008.&#160; When you see IRegisterMetadata used in an example, you know you’re looking at old code.&#160; Overtime this will change, new examples will be posted and MSDN updated.</p>
<p>Remember IRegisterMetadata has been replaced with IProvideAttributeTable in Visual Studio 2010.&#160; Most of old the code and the substance of the example or documentation you are viewing is probably correct and good to learn from.&#160; You just need to be aware that you are looking at older code and that example won’t compile under Visual Studio 2010.</p>
<h4>More Information Links</h4>
<p><a href="http://msdn.microsoft.com/en-us/library/bb546938(VS.100).aspx" target="_blank">MSDN: WPF Designer Extensibility</a>&#160; (This is the best extensibility reference.)</p>
<p><a href="http://code.msdn.microsoft.com/DesignerExtensbility" target="_blank">WPF and Silverlight Designer Extensibility Samples</a></p>
<p><a href="http://blog.ningzhang.org/2009/10/silverlight-design-time-toolkit-october.html" target="_blank">Ning Zhang&#8217;s Blog: Silverlight Design Time: Toolkit October 2009 Release Update</a></p>
<p><a href="http://blog.ningzhang.org/2009/03/how-to-write-silverlight-design-time.html" target="_blank">How to Write Silverlight Design Time for All Designers: Visual Studio 2008, Blend 2; Blend 3, and Visual Studio 2010</a></p>
<h4>Close</h4>
<p>Hope each of you have a wonderful Thanksgiving.&#160; </p>
<p>I’m going out to sea again to write code for a week.&#160; You can follow my cruise Tweets @kdawg02.</p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Silverlight 3 &amp; 4 Library Sharing with .NET 4.0 Library or WPF]]></title>
<link>http://karlshifflett.wordpress.com/2009/11/19/silverlight-3-4-library-sharing-with-net-4-0-library-or-wpf/</link>
<pubDate>Thu, 19 Nov 2009 13:15:16 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/11/19/silverlight-3-4-library-sharing-with-net-4-0-library-or-wpf/</guid>
<description><![CDATA[As if you need “another” reason to start running Visual Studio 2010 Beta2, here is another for all t]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://karlshifflett.files.wordpress.com/2009/11/slwpfapplication.png"><img style="display:inline;border-width:0;" title="slwpfapplication" border="0" alt="slwpfapplication" src="http://karlshifflett.files.wordpress.com/2009/11/slwpfapplication_thumb.png?w=433&#038;h=224" width="433" height="224" /></a> </p>
<p>As if you need “another” reason to start running Visual Studio 2010 Beta2, here is another for all the cross platform .NET Line of Business application developers.</p>
<p>Silverlight 3 &#38; 4 Library assemblies can be referenced in .NET 4.0 applications and used.&#160; </p>
<p>The above WPF application has a file reference also known as a binary reference (as opposed to a project reference) to the BusinessEntities.Silverlight.dll and has instantiated the Customer class and used it for the DataContext for the above MainWindow.</p>
<h4>How To Do It</h4>
<p>The steps are simple, but you need to follow the workflow to avoid issues.</p>
<p>1.&#160; Your Silverlight <u>Library</u> can’t have any “Silverlight specific” code in it.&#160; I have been able to share my own framework code (Ocean) and business entities without any issues.&#160; </p>
<p>Now that Silverlight 4 has shipped and IDataErrorInfo has been added this enables entity sharing between Silverlight and WPF much easier since you no longer have to implement this interface youself just to get code compatibility with your business objects. </p>
<p>2.&#160; Set up a file reference (as opposed to a project reference) between the .NET 4.0 project and your Silverlight 3 or 4 class library .dll.&#160; In the add reference dialog, use the Browse button to locate the target .dll.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/slwpfsolution.png"><img style="display:inline;border-width:0;" title="slwpfsolution" border="0" alt="slwpfsolution" src="http://karlshifflett.files.wordpress.com/2009/11/slwpfsolution_thumb.png?w=317&#038;h=628" width="317" height="628" /></a></p>
<p>3.&#160; If you have the Silverlight 3 or 4 library in the same solution as the consuming .NET 4.0 project(s) it is important that you establish the correct project dependencies and build order.&#160; By default, Visual Studio will not alter your project build order when a file reference is make.</p>
<p>In our case, we need the project build order to look like the below image.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/projectdependencies.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="ProjectDependencies" border="0" alt="ProjectDependencies" src="http://karlshifflett.files.wordpress.com/2009/11/projectdependencies_thumb.png?w=483&#038;h=443" width="483" height="443" /></a> </p>
<p>To establish the above build order, switch to the Dependencies tab, select the other solution projects that depend on the Silverlight 3 or 4 class library and check the Silverlight 3 or 4 library as pictured below.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/buildorder.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="BuildOrder" border="0" alt="BuildOrder" src="http://karlshifflett.files.wordpress.com/2009/11/buildorder_thumb.png?w=480&#038;h=453" width="480" height="453" /></a> </p>
<h4>A Few Thoughts</h4>
<p>If you have never used file reference projects in your solution a few things in the user experience are slightly different.&#160; </p>
<p><strong>IntelliSense</strong></p>
<p>If you edit the Silverlight 3 or 4 class library, don’t expect those changes to be picked up by the .NET 4.0 project(s) until after you build.&#160; This means, if you added a property or method in the code editor, IntelliSense in the .NET 4.0 project won’t “list it” until you build the <u>solution</u>.</p>
<p><strong>Build Order</strong></p>
<p>Its easy to overlook manually setting the project dependencies to ensure the correct build order since for all other projects you have ever created Visual Studio did this for you.</p>
<p>Also, don’t overlook this step after adding a new project to an existing solution that you’ve already set the build order on.</p>
<p><strong>Clean Solution</strong></p>
<p>If you have the Silverlight 3 or 4 class library in the solution and you clean the solution, the library assembly .dll will be removed from output folder.&#160; This will cause Visual Studio to add some errors to your Error List since it can no long find the referenced assembly.&#160; After building the solution, these errors will be removed from the Error List.</p>
<p>So… if you clean your solution and send it to someone like on a blog post, developers that open your solution will see these errors.&#160; Again, build and all is well.</p>
<h4><strong>Service References</strong></h4>
<p>Now that you can put your business entities in a Silverlight 3 or 4 class library and your .NET 4.0 service, business and data layers can consume those entities, take full advantage of service reference dialog Advanced settings.&#160; Advanced button is located in the lower left corner of the Add Service Reference dialog.</p>
<p>I have had issues with the Add Service Reference feature when trying to get it to reuse my existing types.&#160; So I always elect to help the wizard and specifically select the assemblies that contain my business entities as I’ve done in the below image.</p>
<p>Note:&#160; The project download does not have a service reference, the below image is from another project.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/11/servicereference.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="ServiceReference" border="0" alt="ServiceReference" src="http://karlshifflett.files.wordpress.com/2009/11/servicereference_thumb.png?w=669&#038;h=622" width="669" height="622" /></a> </p>
<p>I love this feature because it allows me to use my business entities that have code in them in all the layers of my application without any duplication of code.&#160; This also easily enables entity sharing between Silverlight 3 OR 4 and WPF.</p>
<h4>Download</h4>
<p>The project source code can be downloaded from my SkyDrive.</p>
<p><a href="http://cid-51de981e071f222b.skydrive.live.com/self.aspx/Public/WPFSilverlightLibrarySharing/WPFSilverlightLibrarySharing.zip" target="_blank">Source Code (97KB)</a></p>
<h4>Close</h4>
<p>Hope you like the new developer productivity capabilities of Visual Studio 2010.</p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Visual Studio 2010 - Visual Basic New Feature &ndash; NonSerialized Events]]></title>
<link>http://karlshifflett.wordpress.com/2009/11/17/visual-studio-2010-visual-basic-new-feature-nonserialized-events/</link>
<pubDate>Tue, 17 Nov 2009 14:54:27 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/11/17/visual-studio-2010-visual-basic-new-feature-nonserialized-events/</guid>
<description><![CDATA[A long time feature request has been added to Visual Basic 10 that ships with Visual Studio 2010; de]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>A long time feature request has been added to Visual Basic 10 that ships with Visual Studio 2010; decorating an Event as NonSerialized.</p>
<p>In prior versions of Visual Basic developers had to implement a Custom Event or another workaround when their types needed to expose an Event and they had to be Serializable.&#160; C# had this capability, now Visual Basic does too!</p>
<p>A very common scenario is a class that implements INotifyPropertyChanged and must also be Serializable.&#160; </p>
<p>Visual Basic developers can now decorate the Event with the NonSerialized attribute.&#160; The compiler does the rest for you.</p>
<div class="code">
<pre><span style="color:blue;">Imports </span>System.ComponentModel

&#60;<span style="color:#2b91af;">Serializable</span>()&#62;
<span style="color:blue;">Public Class </span><span style="color:#2b91af;">Customer
    </span><span style="color:blue;">Implements </span><span style="color:#2b91af;">INotifyPropertyChanged

</span><span style="color:blue;">#Region </span><span style="color:#a31515;">&#34; INotifyPropertyChanged Serializable &#34;

    </span><span style="color:green;">'New VB 10 feature!
    </span>&#60;<span style="color:#2b91af;">NonSerialized</span>()&#62;
    <span style="color:blue;">Public Event </span>PropertyChanged(
                  <span style="color:blue;">ByVal </span>sender <span style="color:blue;">As Object</span>,
                  <span style="color:blue;">ByVal </span>e <span style="color:blue;">As </span>System.ComponentModel.<span style="color:#2b91af;">PropertyChangedEventArgs</span>) _
                  <span style="color:blue;">Implements </span>System.ComponentModel.<span style="color:#2b91af;">INotifyPropertyChanged</span>.PropertyChanged

    <span style="color:blue;">Protected Sub </span>OnPropertyChanged(<span style="color:blue;">ByVal </span>strPropertyName <span style="color:blue;">As String</span>)
        <span style="color:blue;">If Me</span>.PropertyChangedEvent <span style="color:blue;">IsNot Nothing Then
            RaiseEvent </span>PropertyChanged(<span style="color:blue;">Me</span>, <span style="color:blue;">New </span><span style="color:#2b91af;">PropertyChangedEventArgs</span>(strPropertyName))
        <span style="color:blue;">End If
    End Sub

#End Region

End Class
</span></pre>
</div>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Hosting Winforms in Firefox]]></title>
<link>http://anoriginalidea.wordpress.com/2009/11/16/hosting-winforms-in-firefox/</link>
<pubDate>Mon, 16 Nov 2009 01:42:39 +0000</pubDate>
<dc:creator>anoriginalidea</dc:creator>
<guid>http://anoriginalidea.wordpress.com/2009/11/16/hosting-winforms-in-firefox/</guid>
<description><![CDATA[&#160; I have a strange fascination with hybrids.&#160; Combining old and new technologies in bizarr]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>&#160;<a href="http://anoriginalidea.files.wordpress.com/2009/11/image.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://anoriginalidea.files.wordpress.com/2009/11/image_thumb.png?w=239&#038;h=244" width="239" height="244" /></a> </p>
<p>I have a strange fascination with hybrids.&#160; Combining old and new technologies in bizarre and interesting ways.&#160;&#160; Why must developers make “the choice” between a web or native technology? It would be great to build applications that would increase or decrease in features depending on the platform they were run on.</p>
<p>&#160;</p>
<p><a href="http://anoriginalidea.files.wordpress.com/2009/11/clip_image002.jpg"><img style="display:inline;border-width:0;" title="clip_image002" border="0" alt="clip_image002" src="http://anoriginalidea.files.wordpress.com/2009/11/clip_image002_thumb.jpg?w=244&#038;h=163" width="244" height="163" /></a></p>
<p>Do you have a Winforms application that you’d like to host in a web browser?&#160; There’s an interesting technique you can use to do this enabled by .net Framework 3.5.</p>
<p>The .net framework provides the ability to create WPF web applications (commonly called XBAP).&#160; WPF has the ability, in turn, to host Winforms.&#160; </p>
<p><strong>Security</strong></p>
<p>It appears that in order to do this effectively, it’s necessary to deploy your XBAP application as a “Full Trust” application.</p>
<p><a href="http://anoriginalidea.files.wordpress.com/2009/11/image1.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://anoriginalidea.files.wordpress.com/2009/11/image_thumb1.png?w=244&#038;h=118" width="244" height="118" /></a> </p>
<p><strong>The code</strong></p>
<p>To use this, create an XBAP project, then a page a “WinformHost” control on it.&#160;&#160; The XAML could look like this:</p>
<p> <code>
<p>&#60;Page x:Class=&#34;Page1&#34;      <br />&#160;&#160;&#160; xmlns=&#34;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;">http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</a>       <br />&#160;&#160;&#160; xmlns:x=&#34;<a href="http://schemas.microsoft.com/winfx/2006/xaml&#34;">http://schemas.microsoft.com/winfx/2006/xaml&#34;</a>       <br />&#160;&#160;&#160; Title=&#34;Page1&#34;&#62;       <br />&#160;&#160;&#160; &#60;DockPanel LastChildFill=&#34;True&#34;&#62;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;Button Name=&#34;Button1&#34;&#160; DockPanel.Dock=&#34;Bottom&#34;&#160; &#62;This is a WPF Button&#60;/Button&#62;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;WindowsFormsHost Name=&#34;WinformHost&#34;&#160;&#160; /&#62;       <br />&#160;&#160;&#160; &#60;/DockPanel&#62;       <br />&#60;/Page&#62;</p>
<p> </code>
<p>Then, create some code to instantiate your winform and show it on the Winform host:</p>
<p> <code>
<p>Class Page1 </p>
<p>&#160;&#160;&#160; Private Sub Page1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim loForm As New HelloWorldWinform </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; WinformHost.Child = WinformToUserControl.GetWrapper(loForm)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; loForm.Show() </p>
<p>&#160;&#160;&#160; End Sub      <br />End Class</p>
<p> </code>
<p>Here’s the subroutine:</p>
<p> <code>
<p>Public NotInheritable Class WinformToUserControl      </p>
<p>&#160;&#160;&#160; Public Shared Function GetWrapper(ByVal form As System.Windows.Forms.Form) As System.Windows.Forms.Control       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim loPanel As New System.Windows.Forms.Panel       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; loPanel.Dock = Forms.DockStyle.Fill       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ShowFormInControl(loPanel, form)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Return loPanel       <br />&#160;&#160;&#160; End Function</p>
<p>&#160;&#160;&#160; Private Shared Sub ShowFormInControl(ByVal ctl As System.Windows.Forms.Control, ByVal frm As System.Windows.Forms.Form) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; frm.TopLevel = False      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; frm.AutoScaleMode = Forms.AutoScaleMode.Dpi       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ctl.Controls.Add(frm) </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; frm.Dock = Forms.DockStyle.Fill      </p>
<p>&#160;&#160;&#160; End Sub      <br />End Class</p>
</p>
<p>&#160;&#160;&#160; </code>
<p><strong>Interesting bits and pieces</strong></p>
<p>We found that in order for the items inside the control to scale properly, the AutoScaleMode property on the Winform must be set to Dpi instead of the default, which is Font.&#160; I have a feeling this is because Dpi is the mode preferred for WPF, but I am uncertain.</p>
<p>In the sample WinformToUserControl class I found it better to contain the Winform inside a panel rather than exposing the Winform directly.&#160; It seemed to make it more stable.&#160; Feel free to experiment with taking it off.</p>
<p><strong>Gotchas</strong></p>
<p>As of time of writing, Firefox on my Windows 7 64 bit machine steadfastly refuses to run xbap.&#160; It appears the “Windows Presentation Foundation” addin has not been automatically installed.&#160; I have no idea how to install it.&#160; There&#8217; appears to be no information about how to do so.&#160; So if you have it, good for you.&#160; If you don’t….try re-installing the .net framework 3.51 (which didn’t work for me…)</p>
<p>I do know there was some controversy about this addin being temporarily blacklisted by Mozilla due to security concerns last month, but that’s all over now isn’t it?&#160;&#160; </p>
<p>&#160;</p>
<h4>Download</h4>
<p>You can download a <a href="http://cid-5f1708eb705d1c65.skydrive.live.com/self.aspx/Public/HostingWinformsInFirefox.zip">sample project here</a>.</p>
<p><a href="http://anoriginalidea.files.wordpress.com/2009/11/image2.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://anoriginalidea.files.wordpress.com/2009/11/image_thumb2.png?w=231&#038;h=162" width="231" height="162" /></a> </p>
<h4>Links</h4>
<ul>
<li>I didn’t use anything from this project, but you might find it interesting <a href="http://mdiwinman.codeplex.com">MdiWindowManager</a> </li>
<li>StackOverflow <a href="http://stackoverflow.com/questions/543087/custom-class-for-dealing-with-embedding-in-forms">post on Embedding winforms in usercontrols</a> </li>
</ul>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Walkin on November 14/15 - Saturday and Sunday]]></title>
<link>http://walkinjobs.wordpress.com/2009/11/13/walkin-on-november-1415-saturday-and-sunday/</link>
<pubDate>Fri, 13 Nov 2009 18:05:03 +0000</pubDate>
<dc:creator>Walkin Jobs</dc:creator>
<guid>http://walkinjobs.wordpress.com/2009/11/13/walkin-on-november-1415-saturday-and-sunday/</guid>
<description><![CDATA[Hi Friends, Walk-in interviews for jobs &#8211; 14/11/09 and 15/11/09 &#8211; Nov 14/15 &#8211; Sat/]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hi Friends, Walk-in interviews for jobs &#8211; 14/11/09 and 15/11/09 &#8211; Nov 14/15 &#8211; Sat/sun.</p>
<p><strong>Hot Walkins [Sourced by Company HR Directly]:</strong></p>
<table style="width:564px;height:148px;">
<tbody>
<tr>
<td valign="top"><a title="Designer (Flash Designing , Web Designing , Logo and Image Designing ) Skills : latest, creative and innovative design making with quality and international standards Exp : 1 - 2 yrs Location : chennai Walkin on 11-14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Designer-Flash-Designing-Web-Designing-Logo-and-Image-Designing.html" target="_blank"><strong>Designer (Flash Designing , Web Designing , Logo and Image Designing )</strong></a><br />
<a title="Fresher/Trainee/Career/Final year students Skills : java,j2ee,.net,c,c++,php Exp : Freshers Location : chennai Walkin on 11-11/12/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Fresher-Trainee-Career-Final-year-students-Chennai.html" target="_blank"><strong>Fresher/Trainee/Career/Final year students</strong></a><br />
<a title="WALK-IN Cash Posters/Charge Entry Specialists Skills : MS Word/Excel Exp : 1 - 3 yrs Location : Chennai Walkin on 11-14/11/2009" href="http://www.walkinsindia.com/non_it_walkin/walkins/WALK-IN-Cash-Posters-Charge-Entry-Specialists.html" target="_blank"><strong>WALK-IN Cash Posters/Charge Entry Specialists</strong></a><br />
<a title="WALK-IN Call Centre Executives - Chennai Skills : MS Word/Excel Exp : 1 - 3 yrs Location : Chennai Walkin on 11-14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/WALK-IN-Call-Centre-Executives-Chennai-Nov11-14.html" target="_blank"><strong>WALK-IN Call Centre Executives &#8211; Chennai</strong></a><br />
<a title="WALK-IN FOR AR Analysts - Chennai Skills : Good Communication/Typing Skills/MS Word/Excel Exp : 1 - 3 yrs Location : Chennai Walkin on 11-14/11/2009" href="http://www.walkinsindia.com/non_it_walkin/walkins/WALK-IN-FOR-AR-Analysts-Chennai-Nov-11-14.html" target="_blank"><strong>WALK-IN FOR AR Analysts &#8211; Chennai</strong></a><br />
<a title="FRESHERS OPENING IN CMC - Chennai - Nov 6-14 Skills : C,C++ Exp : Freshers Location : Chennai Walkin on 06-14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/FRESHERS-OPENING-IN-CMC-Chennai-Nov-6-14.html" target="_blank"><strong>FRESHERS OPENING IN CMC &#8211; Chennai &#8211; Nov 6-14</strong></a><br />
<a title="Walkin for .Net Developer Chennai - Nov 5 to Dec 4 Skills : .Net, C#, SQL Server Exp : 2 - 5 yrs Location : Chennai Walkin on 05-04/12/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Walkin-for-Net-Developer-Chennai-Nov-5-to-Dec-4.html" target="_blank"><strong>Walkin for .Net Developer Chennai &#8211; Nov 5 to Dec 4</strong></a><br />
<a title="Walkin - Software Engineer - PHP - Nov 15 Pune Skills : PHP, LAMP, Web Development, JavaScript, HTML, CSS, .NET, PERL, Web Services, Web 2.0, MySql, SQL Exp : 4 - 10 yrs Location : Mumbai Walkin on 15/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Walkin-SoftwareEngineer-PHP-Nov-15-Pune.html" target="_blank"><strong>Walkin &#8211; Software Engineer &#8211; PHP &#8211; Nov 15 Pune</strong></a><br />
<a title="IBM DB2DBA , DataStage professionals required - Urgent Skills : IBM DB2DBA , DataStage professionals required - Urgent Exp : Freshers Location : chennai,tamilnadu,india Walkin on 29-28/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/IBM-DB2DBA-DataStage-professionals-required-Urgent.html" target="_blank"><strong>IBM DB2DBA , DataStage professionals required &#8211; Urgent</strong></a></td>
</tr>
</tbody>
</table>
<p>Walkin Interviews at TOP companies of India &#8211; November 14/15 2009 (nov 14th/15th &#8211; sat/sun)</p>
<table border="0" cellspacing="0" cellpadding="3" width="98%" align="center">
<tbody>
<tr>
<td valign="top"><a title="Dot net / Sharepoint / Flex Walkin @ Gateway in Ahmedabad on 13/14/15 Nov 2009 Skills : Dot net / Sharepoint/ Flex Exp : 3 - 6 yrs Location : Ahmedabad Walkin on 13-15/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Dot-net-Sharepoint-Flex-Walkin-at-Gateway-in-Ahmedabad-on-13-14-15-Nov-2009.html" target="_blank"><strong>Dot net / Sharepoint / Flex Walkin @ Gateway in Ahmedabad on 13/14/15 Nov 2009</strong></a><br />
<a title="Walkin @ CTS in Bangalore on 14th Nov 2009 Skills : WebMoethods / Telecom Testing / DotNet / Java Exp : 5 - 10 yrs Location : Bengaluru/Bangalore Walkin on 14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Walkin-at-CTS-in-Bangalore-on-14th-Nov-2009.html" target="_blank"><strong>Walkin @ CTS in Bangalore on 14th Nov 2009</strong></a><br />
<a title="Walkin for Senior JAVA J2EE Professionals on SATURDAY ( 14 Nov) Skills : JAVA Exp : 8 - 13 yrs Location : Bangalore Walkin on 14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Walkin-for-Senior-JAVA-J2EE-Professionals-on-SATURDAY-14-Nov.html" target="_blank"><strong>Walkin for Senior JAVA J2EE Professionals on SATURDAY ( 14 Nov)</strong></a><br />
<a title="Walkin for Senior .Net Professionals on SATURDAY ( 14 Nov ) Skills : .NET Exp : 8 - 13 yrs Location : Bangalore Walkin on 14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Walkin-for-Senior-Net-Professionals-on-SATURDAY-14-Nov.html" target="_blank"><strong>Walkin for Senior .Net Professionals on SATURDAY ( 14 Nov )</strong></a><br />
<a title="WALK-IN AT HCL HYD FOR .NET,SDET PROFESSIONALS ON 14 NOV Skills : C#, .NET, SQL Server / SDET / SQL DBA / MOSS Exp : 3 - 8 yrs Location : Hyderabad / Noida Walkin on 14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/WALK-IN-AT-HCL-HYD-FOR-NET-SDET-PROFESSIONALS-ON-14-NOV.html" target="_blank"><strong>WALK-IN AT HCL HYD FOR .NET,SDET PROFESSIONALS ON 14 NOV</strong></a><br />
<a title=".NET Walkin at HCL Chennai - Nov 14 " href="http://www.walkinsindia.com/it_walkin/walkins/DOT-NET-Walkin-at-HCL-Chennai-Nov-14-09.html" target="_blank"><strong>.NET Walkin at HCL Chennai &#8211; Nov 14 &#8216;09</strong></a><br />
<a title="Customer Care Executive - Voice - Walkin at Patni - Nov 11-18 Skills : Voice - Excellent English Communication Skills Exp : 0 - 2 yrs Location : Delhi, Delhi/NCR Walkin on 12-18/11/2009" href="http://www.walkinsindia.com/non_it_walkin/walkins/Customer-Care-Executive-Voice-Walkin-at-Patni-Nov-11-18.html" target="_blank"><strong>Customer Care Executive &#8211; Voice &#8211; Walkin at Patni &#8211; Nov 11-18</strong></a><br />
<a title="Core JAVA Walkin (n/w domain) - HCL Chennai - Nov 14 " href="http://www.walkinsindia.com/it_walkin/walkins/Core-JAVA-Walkin-n-w-domain-HCL-Chennai-Nov-14-09.html" target="_blank"><strong>Core JAVA Walkin (n/w domain) &#8211; HCL Chennai &#8211; Nov 14 &#8216;09</strong></a><br />
<a title="Walk-ins for Mainframe Professionals @ iGATE Hyd - 10th-14th Nov 09 Skills : COBOL, JCL, DB2 Exp : 2 - 4 yrs Location : Hyderabad Walkin on 10-14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Walk-ins-for-Mainframe-Professionals-iGATE-Hyd-10th-14th-Nov-09.html" target="_blank"><strong>Walk-ins for Mainframe Professionals @ iGATE Hyd &#8211; 10th-14th Nov 09</strong></a><br />
<a title="Walkin - Insurance ( Voice) - Bangalore - Nov 10 11 Skills : Insurance ( Voice) Exp : 1 - 2 yrs Location : Bangalore Walkin on 10,11/11/2009" href="http://www.walkinsindia.com/non_it_walkin/walkins/Walkin-Insurance-Voice-Bangalore-Nov-10-11.html" target="_blank"><strong>Walkin &#8211; Insurance ( Voice) &#8211; Bangalore &#8211; Nov 10 11</strong></a><br />
<a title="Walkin for Freshers - Infy BPO Bhubaneswar - Nov 14 15 - for Bangalore n Pune Skills : BPO - Voice Process / Accounts n Finance Process Exp : 0 - 2 yrs Location : Bangalore / Pune Walkin on 14,15/11/2009" href="http://www.walkinsindia.com/non_it_walkin/walkins/Walkin-for-Freshers-Infy-BPO-Bhubaneswar-Nov-14-15-for-Bangalore-n-Pune.html" target="_blank"><strong>Walkin for Freshers &#8211; Infy BPO Bhubaneswar &#8211; Nov 14 15 &#8211; for Bangalore n Pune</strong></a><br />
<a title="Walkin for Sr .Net Professionals - Bangalore - Nov 14 Skills : Asp.net, c#, silverlight, wcf, wpf Exp : 4 - 8 yrs Location : Bangalore Walkin on 14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Walkin-for-Sr-Net-Professionals-Bangalore-Nov-14.html" target="_blank"><strong>Walkin for Sr .Net Professionals &#8211; Bangalore &#8211; Nov 14</strong></a><br />
<a title="Scheduled Walk-in for Siebel EAI/ Siebel Config/Siebel EIM - CTS - Blr Nov 14 Skills : Siebel EAI/ Siebel Config/Siebel EIM Exp : 3 - 10 yrs Location : Bangalore Walkin on 14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Scheduled-Walk-in-for-Siebel-EAI-Siebel-Config-Siebel-EIM-CTS-Blr-Nov-14.html" target="_blank"><strong>Scheduled Walk-in for Siebel EAI/ Siebel Config/Siebel EIM &#8211; CTS &#8211; Blr Nov 14</strong></a><br />
<a title="Desktop Engineer Walkin @ PCS in Bangalore on 9/10/11/12/13/14 Nov 2009 Skills : Desktop Support Engineer Exp : 2 - 4 yrs Location : Bangalore and kerala Walkin on 09-14/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Desktop-Engineer-Walkin-at-PCS-in-Bangalore-on-9-10-11-12-13-14-Nov-2009.html" target="_blank"><strong>Desktop Engineer Walkin @ PCS in Bangalore on 9/10/11/12/13/14 Nov 2009</strong></a><br />
<a title="Freshers Walkin @ Capgemini in Bangalore Skills : Java/.net/Oracle Exp : 0 - 1 yrs Location : Bangalore, Chennai, Hyderabad, Mumbai Walkin on 28-10/11/2009" href="http://www.walkinsindia.com/it_walkin/walkins/Freshers-Walkin-at-Capgemini-in-Bangalore.html" target="_blank"><strong>Freshers Walkin @ Capgemini in Bangalore</strong></a></td>
</tr>
</tbody>
</table>
<p>More Walkins ? <a href="http://jumbowalkin.com"><strong>http://jumbowalkin.com</strong></a></p>
<p>Good luck and a great weekend!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[the status of .netSavant...]]></title>
<link>http://hurtsmybrains.wordpress.com/2009/11/11/the-status-of-netsavant/</link>
<pubDate>Wed, 11 Nov 2009 22:40:08 +0000</pubDate>
<dc:creator>Joshua Gall</dc:creator>
<guid>http://hurtsmybrains.wordpress.com/2009/11/11/the-status-of-netsavant/</guid>
<description><![CDATA[I have this awesome little ADO.NET code generator called .netSavant.  It analyzes your stored proced]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I have this awesome little ADO.NET code generator called .netSavant.  It analyzes your stored procedures and generates an optimized wrapper class that encapsulates the logic for execution.  After using it myself for quite some time, I thought, oddly, that I could make a little extra cash from the endeavor.  Heh, sadly I was wrong.  Dispite a lot of interest, few people were interested in paying $50 for a visual studio addin that saved a LOT of time and buggy code.  Wierd, but whatever.</p>
<p>So, with mixed feelings I killed the project.  It simply cost too much money to maintain the website and merchant account for a product that only sold a handful of licenses over the 18-24 months.</p>
<p>I&#8217;m left wondering what to do with the project.  There are a few options:</p>
<ol>
<li>Create a codeplex project</li>
<li>Host the source code myself</li>
<li>Release the addin as freeware (no source code)</li>
<li>Release the addin as freeware with sponsorship (uhg, gross right?) (no source code)</li>
<li>Leave the project inactive and move on to other exciting technologies</li>
</ol>
<p>I&#8217;m wondering if I really want to spend more effort supporting the project as a whole, though with so much time invested, its hard to walk away from it.  Part of me would like to see more people use .netSavant, if only to justify the time I spent creating it.  I&#8217;d also like the challenge of updating some of the methodology used to generate the source code, and possibly provide some extensibility points to enhance the analysis features that it supports.</p>
<p>Perhaps some day .netSavant will be resurrected in a better form.  Until that time, thanks for your interest and support.</p>
<p>Joshua</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Get Max Request length from web.config]]></title>
<link>http://nitin646.wordpress.com/2009/11/03/get-max-request-length-from-web-config/</link>
<pubDate>Tue, 03 Nov 2009 10:34:17 +0000</pubDate>
<dc:creator>Nitin</dc:creator>
<guid>http://nitin646.wordpress.com/2009/11/03/get-max-request-length-from-web-config/</guid>
<description><![CDATA[For retrieving maxrequest length from web.config use following function: public int GetMaxLength() {]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><code></p>
<p></code></p>
<p><strong>For retrieving maxrequest length from web.config use following function:</strong></p>
<p><code>public int GetMaxLength()<br />
{<br />
        HttpRuntimeSection httpRuntime =<br />
(HttpRuntimeSection)ConfigurationManager.GetSection("system.web/httpRuntime");<br />
        return httpRuntime.MaxRequestLength;<br />
}</code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Dependency Injection]]></title>
<link>http://carlossantos.wordpress.com/2009/11/01/dependency-injection/</link>
<pubDate>Mon, 02 Nov 2009 01:36:11 +0000</pubDate>
<dc:creator>Carlos Marcelo Santos</dc:creator>
<guid>http://carlossantos.wordpress.com/2009/11/01/dependency-injection/</guid>
<description><![CDATA[En el ámbito del desarrollo de software, siempre es bueno eliminar dependencias. En otros términos, ]]></description>
<content:encoded><![CDATA[En el ámbito del desarrollo de software, siempre es bueno eliminar dependencias. En otros términos, ]]></content:encoded>
</item>
<item>
<title><![CDATA[Obtener los Forms en vb.net]]></title>
<link>http://galguera.wordpress.com/2009/10/31/obtener-los-forms-en-vb-net/</link>
<pubDate>Sat, 31 Oct 2009 20:11:58 +0000</pubDate>
<dc:creator>galguera</dc:creator>
<guid>http://galguera.wordpress.com/2009/10/31/obtener-los-forms-en-vb-net/</guid>
<description><![CDATA[Me he andado matando con esto&#8230; pero al final lo encontré&#8230; funciona solo con .net, no jal]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Me he andado matando con esto&#8230; pero al final lo encontré&#8230; funciona solo con .net, no jala con versiones vb 6 (bendito Dios jajaja)</p>
<p><span style="color:#808080;"><strong>Dim fm As FormCollection<br />
fm = Application.OpenForms</strong></span></p>
<p><span style="color:#808080;"><strong> For i As Integer = 0 To fm.Count &#8211; 1</strong></span></p>
<p style="padding-left:30px;"><span style="color:#808080;"><strong> Dim f As Form<br />
f = fm.Item(i)</strong></span></p>
<p><span style="color:#808080;"><strong> Next</strong></span></p>
<p>&#8230; con eso basta&#8230;<br />
PD solo se opbtienen los forms de la aplicación de la cual se llama&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[T4 Preprocessed Text Templates in Visual Studio 2010]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/30/t4-preprocessed-text-templates-in-visual-studio-2010/</link>
<pubDate>Fri, 30 Oct 2009 16:23:23 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/30/t4-preprocessed-text-templates-in-visual-studio-2010/</guid>
<description><![CDATA[The best kept secret in Redmond, WA are the new T4 Preprocess Text Templates that shipped in Visual ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The best kept secret in Redmond, WA are the new T4 Preprocess Text Templates that shipped in Visual Studio 2010 Beta1 and Beta2.&#160; In just a few minutes you’ll be in the know and using them.</p>
<h4>Background – Condensed </h4>
<p><strong>T4</strong> = text template transformation toolkit</p>
<p>T4 templates have been available since Visual Studio 2005 and are part of DSL (Domain Specific Languages) documentation.</p>
<p>In Visual Studio 2010 the templates are MUCH easier to use because they are preprocessed.&#160; When you save your T4 template, it is compiled.&#160; The T4 template is now “processed” at compile time.&#160; This was not the case in previous releases. </p>
<p>Your compiled template is just another type in an assembly that you can now instantiate and call its single method, TransformText.&#160; The only run-time requirement to use T4 templates is the .NET 2.0 Framework. </p>
<h4>Prerequisites</h4>
<ul>
<li>Visual Studio 2010 </li>
<li>T4 Editor Plug In&#160;
<ul>
<li>Visual Studio 2010 does not provide any editing assistance when editing T4 templates (.tt files).&#160; You can search the Internet for T4 Editor and you’ll find some information and products. </li>
<li>I’m currently using the Tangible T4 Editor (free) that you can get on the Visual Studio Gallery here:&#160;
<ul>
<li><a href="http://visualstudiogallery.msdn.microsoft.com/en-us/60297607-5fd4-4da4-97e1-3715e90c1a23" target="_blank">http://visualstudiogallery.msdn.microsoft.com/en-us/60297607-5fd4-4da4-97e1-3715e90c1a23</a> </li>
<li>The editor is an Alpha version, has a few limitations but I was able to author the below template in a few minutes. </li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Our Scenario</h4>
<p>We have been tasked with creating some code that we can pass data fields to and that code will create a VB.NET property.&#160; This code will be part of a larger program that is fed information and creates class files.</p>
<p>Before T4 Preprocessed templates we had several options available to us.&#160; Write code to spit out the required property, buy a 3rd party product, use CodeDom, etc.</p>
<p>Since we just installed Visual Studio 2010 Beta2, we are going for the productive, inexpensive, simple and out of the box solution, T4 Preprocessed Text Template.</p>
<h4>Our Test Bench</h4>
<p>This simple application simulates the data harness that will ultimately feed our T4 template and consume its output.&#160; Set a few data fields and press Generate Code.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/demoapplicaiton.png"><img style="display:inline;border-width:0;" title="demoApplicaiton" border="0" alt="demoApplicaiton" src="http://karlshifflett.files.wordpress.com/2009/10/demoapplicaiton_thumb.png?w=510&#038;h=572" width="510" height="572" /></a></p>
<h4>Code Generation – It’s all about the data</h4>
<p>Code generation requires metadata to drive the output.&#160; With the new T4 templates, getting metadata into your T4 template is a simple matter of a partial class.&#160; The members in the partial class are available at design time and run-time.&#160; I know this seems so simple, but T4 did not always work this way.&#160; Now you have full design time strong typing and instant compile time verification of your template and code.</p>
<p>To keep this example as simple as possible, I’ve exposed the metadata directly as properties and passed values for them in the constructor of our Partial Class PropertyTemplate.&#160; For simple scenarios this totally fine.&#160; For a larger or multi-language code generation applications, a better solution is to expose the metadata through an Interface.&#160; The Interface type can contain metadata and helper methods that can be used in your T4 template.</p>
<p><a href="http://msmvps.com/blogs/kathleen/" target="_blank">Kathleen Dollard</a> and I have spoken a good bit about this and think using Interfaces for metadata and helper methods makes the most sense.&#160; I’m sure Kathleen will write more on this subject and I know I will.</p>
<p>In the below T4TemplateLibrary project you can see how I’ve set up the project.&#160; I had to turn on “Show All Files” to see the hidden file, “PropertyTemplate.vb” below the “PropertyTemplate.tt” file. </p>
<blockquote><p>Open the hidden “PropertyTemplate.vb” file up and you will see the type of code you and I used to have to write to generate code.&#160; Now T4 does it for us!</p>
</blockquote>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/t4project.png"><img style="display:inline;border-width:0;" title="T4Project" border="0" alt="T4Project" src="http://karlshifflett.files.wordpress.com/2009/10/t4project_thumb.png?w=244&#038;h=211" width="244" height="211" /></a></p>
<p>The below partial class is overly simple and exposes metadata that will be consumed by the T4 template.</p>
<div class="code">
<pre><span style="color:blue;">Namespace My</span>.Templates

  <span style="color:blue;">Partial Public Class </span><span style="color:#2b91af;">PropertyTemplate

    </span><span style="color:blue;">Public Property </span>PropertyName <span style="color:blue;">As String </span>= <span style="color:blue;">String</span>.Empty
    <span style="color:blue;">Public Property </span>BackingField <span style="color:blue;">As String </span>= <span style="color:blue;">String</span>.Empty
    <span style="color:blue;">Public Property </span>TypeName <span style="color:blue;">As String </span>= <span style="color:blue;">String</span>.Empty
    <span style="color:blue;">Public Property </span>IsShared <span style="color:blue;">As Boolean </span>= <span style="color:blue;">False
    Public Property </span>RaisePropertyChangedMethodName <span style="color:blue;">As String </span>= <span style="color:blue;">String</span>.Empty
    <span style="color:blue;">Public Property </span>IsReadOnly <span style="color:blue;">As Boolean </span>= <span style="color:blue;">False
    Public Property </span>Scope <span style="color:blue;">As String </span>= <span style="color:blue;">String</span>.Empty
    <span style="color:blue;">Public Property </span>IsSetterPrivate <span style="color:blue;">As Boolean </span>= <span style="color:blue;">False

    Public Sub New</span>(<span style="color:blue;">ByVal </span>strScope <span style="color:blue;">As String</span>, <span style="color:blue;">ByVal </span>bolIsShared <span style="color:blue;">As Boolean</span>,
                   <span style="color:blue;">ByVal </span>bolIsReadOnly <span style="color:blue;">As Boolean</span>, <span style="color:blue;">ByVal </span>bolIsSetterPrivate <span style="color:blue;">As Boolean</span>,
                   <span style="color:blue;">ByVal </span>strPropertyName <span style="color:blue;">As String</span>, <span style="color:blue;">ByVal </span>strBackingField <span style="color:blue;">As String</span>,
                   <span style="color:blue;">ByVal </span>strTypeName <span style="color:blue;">As String</span>, <span style="color:blue;">ByVal </span>strRaisePropertyChangedMethodName <span style="color:blue;">As String</span>)
      <span style="color:blue;">Me</span>.Scope = strScope
      <span style="color:blue;">Me</span>.IsShared = bolIsShared
      <span style="color:blue;">Me</span>.IsReadOnly = bolIsReadOnly
      <span style="color:blue;">Me</span>.IsSetterPrivate = bolIsSetterPrivate
      <span style="color:blue;">Me</span>.PropertyName = strPropertyName
      <span style="color:blue;">Me</span>.BackingField = strBackingField
      <span style="color:blue;">Me</span>.TypeName = strTypeName
      <span style="color:blue;">Me</span>.RaisePropertyChangedMethodName = strRaisePropertyChangedMethodName
    <span style="color:blue;">End Sub

  End Class

End Namespace
</span></pre>
</div>
<h4>T4 Template</h4>
<p>To add a T4 template to your project, select Add New Item, then type “preprocessed” in the search box.&#160; Select the Preprocess Text Template.</p>
<p>If you used classic ASP, then T4 template editing is a skill you already have.&#160; In classic ASP we used &#60;% and &#60;%=.&#160; In T4 we use &#60;# and &#60;#=.&#160; The reason for this change is so that T4 can be used to generate classic ASP and ASP.NET code.&#160; If you didn’t have the joy of shipping classic ASP web sites, no worries.&#160; 15 minutes of trail and error and you’ll be fully qualified.</p>
<p>The below image shows the free Tangible T4 Editor Plug-In IntelliSense in action.&#160; It provides IntelliSense for T4 directives and template specific constructs like &#60;#.&#160; It also colorizes the template code.&#160; Colorizing makes editing the template much easier too.&#160; One current limitation is that its IntelliSense engine does list member properties defined in the partial class for the template.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/t4intellisense.png"><img style="display:inline;border-width:0;" title="T4IntelliSense" border="0" alt="T4IntelliSense" src="http://karlshifflett.files.wordpress.com/2009/10/t4intellisense_thumb.png?w=553&#038;h=263" width="553" height="263" /></a>&#160;</p>
<p>The below code block is the T4 template.&#160; It has a language directive at the top followed by static text and code blocks.</p>
<div class="code">
<pre style="overflow:auto;"><span style="color:black;">&#60;#@ </span><span style="color:brown;">template </span><span style="color:red;">language</span><span style="color:black;">=&#34;</span><span style="color:blue;">VB</span><span style="color:black;">&#34; #&#62;

&#60;#= </span><span style="color:blue;">Me</span><span style="color:black;">.Scope #&#62;&#60;#= </span><span style="color:blue;">IIF</span><span style="color:black;">(</span><span style="color:blue;">Me</span><span style="color:black;">.IsShared, </span><span style="color:maroon;">&#34; Shared&#34;</span><span style="color:black;">,</span><span style="color:maroon;">&#34;&#34;</span><span style="color:black;">) #&#62;&#60;#= </span><span style="color:blue;">IIF</span><span style="color:black;">(</span><span style="color:blue;">Me</span><span style="color:black;">.IsReadOnly, </span><span style="color:maroon;">&#34; ReadOnly&#34;</span><span style="color:black;">, </span><span style="color:maroon;">&#34;&#34;</span><span style="color:black;">) #&#62; Property &#60;#= </span><span style="color:blue;">Me</span><span style="color:black;">.PropertyName #&#62; As &#60;#= </span><span style="color:blue;">Me</span><span style="color:black;">.TypeName #&#62;
    Get
        Return &#60;#= </span><span style="color:blue;">Me</span><span style="color:black;">.BackingField #&#62;
    End Get
&#60;# </span><span style="color:blue;">If Not Me</span><span style="color:black;">.IsReadOnly </span><span style="color:blue;">Then </span><span style="color:black;">#&#62;
    &#60;#= </span><span style="color:blue;">IIF</span><span style="color:black;">(</span><span style="color:blue;">Me</span><span style="color:black;">.IsSetterPrivate, </span><span style="color:maroon;">&#34; Private &#34;</span><span style="color:black;">,</span><span style="color:maroon;">&#34;&#34;</span><span style="color:black;">) #&#62;Set(ByVal value As &#60;#= </span><span style="color:blue;">Me</span><span style="color:black;">.TypeName #&#62;)
&#60;# </span><span style="color:blue;">If String</span><span style="color:black;">.IsNullOrEmpty(</span><span style="color:blue;">Me</span><span style="color:black;">.RaisePropertyChangedMethodName) </span><span style="color:blue;">Then </span><span style="color:black;">#&#62;
        &#60;#= </span><span style="color:blue;">Me</span><span style="color:black;">.BackingField #&#62; = value
&#60;# </span><span style="color:blue;">Else </span><span style="color:black;">#&#62;
        &#60;#= </span><span style="color:blue;">Me</span><span style="color:black;">.BackingField #&#62; = value
        &#60;#= </span><span style="color:blue;">String</span><span style="color:black;">.Format(</span><span style="color:maroon;">&#34;{0}(&#34;&#34;{1}&#34;&#34;)&#34;</span><span style="color:black;">, </span><span style="color:blue;">Me</span><span style="color:black;">.RaisePropertyChangedMethodName, </span><span style="color:blue;">Me</span><span style="color:black;">.PropertyName) #&#62;
&#60;# </span><span style="color:blue;">End If </span><span style="color:black;">#&#62;
    End Set
&#60;# </span><span style="color:blue;">End If </span><span style="color:black;">#&#62;
End Property</span></pre>
</div>
<p>&#60;#=&#160; is the same as the ASP Response.Write.&#160; It writes the result of the expression into the template.&#160; For example, if the Scope is Public, &#60;#= Me.Scope #&#62; would yield Public when the template is transformed at run-time.</p>
<p>&#60;# is the beginning of a code block.&#160; Notice how the IsReadOnly property is tested.&#160; Basic on the result, an entire block of code can either run or be by-passed.&#160; This feature is so cool when you bring loops from LINQ queries into the picture.</p>
<p>One thing you’ll notice is that all the code blocks are left justified.&#160; Yes, this makes reading the template a little harder.&#160; However, if you don’t do this, the resulting code will be indented the same amount as the code block indentation.</p>
<p>So what I do when editing my templates is to indent everything to make it easier to edit the template.&#160; When I”m done, I go back and move the code to the left.</p>
<h4>Run-Time Rendering of T4 Templates</h4>
<div class="code">
<pre class="code"><span style="color:blue;">Dim </span>t <span style="color:blue;">As New </span><span style="color:#2b91af;">PropertyTemplate</span>(
    <span style="color:blue;">Me</span>.cboScope.SelectedItem.ToString,
    <span style="color:blue;">Me</span>.chkIsShared.IsChecked.Value,
    <span style="color:blue;">Me</span>.chkIsReadOnly.IsChecked.Value,
    <span style="color:blue;">Me</span>.chkIsSetterPrivate.IsChecked.Value,
    <span style="color:blue;">Me</span>.txtPropertyName.Text,
    <span style="color:blue;">Me</span>.txtBackingField.Text,
    <span style="color:blue;">Me</span>.cboTypeName.SelectedItem.ToString,
    <span style="color:blue;">Me</span>.cboRaisePropertyChangedMethodName.SelectedItem.ToString)

<span style="color:green;">'How cool is this?  Instantiate, call a single method, get the code!
</span><span style="color:blue;">Dim </span>strResult <span style="color:blue;">As String </span>= t.TransformText</pre>
</div>
<p>Instantiate the template, call the TransformText method.&#160; Not very sexy, but powerful!</p>
<h4>Download</h4>
<p><a href="http://cid-51de981e071f222b.skydrive.live.com/self.aspx/Public/T4%20Preprocessed%20Text%20Templates/GetYourT4On.zip" target="_blank">Get Your T4 On Demo Application (33KB)</a></p>
<p><strong>Alternate Download Site </strong></p>
<p>Some corporate firewalls do not allow access to Windows Live Sky Drive. You can download the installer here. Remember to rename the file from .doc to .zip. This is a requirement of WordPress.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/getyourt4on-zip.doc" target="_blank">Get Your T4 On Demo Application (33KB)</a></p>
<h4>Links</h4>
<p><a href="http://blogs.msdn.com/garethj/" target="_blank">Gareth Jones blog</a>&#160; Gareth works on the DSL Team at Microsoft and works with the Microsoft T4 product.</p>
<p><a href="http://msmvps.com/blogs/kathleen/" target="_blank">Kathleen Dollard’s blog</a> Kathleen has been doing code generation for a very long time and is an industry expert in this space.</p>
<p><a href="http://blogs.appventure.com/Kathleen/2009/09/04/WhyIsAPreprocessedTemplateTheCoolestThingSinceSlicedBread.aspx" target="_blank">Kathleen Dollard’s</a> work blog post on why T4 Templates are the best thing since sliced bread.</p>
<p><a href="http://www.olegsych.com/2009/09/t4-preprocessed-text-templates/" target="_blank">Oleg Sych</a> very nice blog post on T4 Preprocessed Text Templates</p>
<p><a href="http://www.clariusconsulting.net/blogs/pga/archive/2009/07/15/160836.aspx" target="_blank">Pablo Galiano</a> T4 Preprocessing Part 1</p>
<p><a href="http://www.clariusconsulting.net/blogs/pga/archive/2009/07/15/160853.aspx" target="_blank">Pablo Galiano</a> T4 Preprocessing Part 2</p>
<h4>Close</h4>
<p>There is a fair amount of information on Visual Studio 2005/2008 T4 templates.&#160; When reading these blog posts, magazine articles and MSDN Documentation, keep in mind that the new T4 templates do not have wide spread documentation yet.&#160; Most of what you will find is applicable to editing of the templates and directives used in the templates.&#160; Beyond that, just filter the information and you’ll stay on course.</p>
<p>Visual Studio 2010 T4 Preprocessed Text Templates are a great tool for your toolbox.&#160; Hope to see you use the best kept secret in Redmond.</p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Updated Code: Visual Studio 2010 Beta2 Sample Data Project Templates]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/28/updated-code-visual-studio-2010-beta2-sample-data-project-templates/</link>
<pubDate>Wed, 28 Oct 2009 23:36:48 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/28/updated-code-visual-studio-2010-beta2-sample-data-project-templates/</guid>
<description><![CDATA[I have updated the project templates Visual Studio 2010 Beta2 Sample Data Project Templates.&#160; T]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I have updated the project templates <font color="#333333"><a href="http://karlshifflett.wordpress.com/2009/10/21/visual-studio-2010-beta2-sample-data-project-templates/">Visual Studio 2010 Beta2 Sample Data Project Templates</a>.&#160; </font></p>
<p><font color="#333333">The Silverlight template needed an update to the .proj file.</font></p>
<p>Please download the templates from the above post.</p>
<p>Sorry for the problem.</p>
<h4>Close</h4>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Updated Code: XAML Power Toys for Visual Studio 2010 Beta2 Cider Designer]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/28/updated-code-xaml-power-toys-for-visual-studio-2010-beta2-cider-designer/</link>
<pubDate>Wed, 28 Oct 2009 16:27:18 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/28/updated-code-xaml-power-toys-for-visual-studio-2010-beta2-cider-designer/</guid>
<description><![CDATA[I was working on a post for T4 Preprocessed Text Templates (I’ll post it tonight) and found a bug in]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I was working on a post for T4 Preprocessed Text Templates (I’ll post it tonight) and found a bug in the <a href="http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2010-beta2-cider-designer/">XAML Power Toys for Visual Studio 2010 Beta2 Cider Designer</a> grid parsing code.&#160; </p>
<p>Chances are you won’t hit it, but I did so I’ve corrected the code and posted a new update.&#160; The code didn’t properly handle a null value in the CheckBox.Content property.&#160; I’ve correct it and added additional null checks.</p>
<p>Please visit this page <a href="http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2010-beta2-cider-designer/">XAML Power Toys for Visual Studio 2010 Beta2 Cider Designer</a> and get the latest version v1.0.1.</p>
<p>You can go to the above page, download the install files and install overtop as it will remove the previous version and install the new one.</p>
<p>Sorry for the bug.&#160; </p>
<h4>Close</h4>
<p>Hope you use and enjoy XAML Power Toys for Visual Studio 2010 Beta2 for Cider.</p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[d:DesignInstance, d:DesignData in Visual Studio 2010 Beta2]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/28/ddesigninstance-ddesigndata-in-visual-studio-2010-beta2/</link>
<pubDate>Wed, 28 Oct 2009 05:02:52 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/28/ddesigninstance-ddesigndata-in-visual-studio-2010-beta2/</guid>
<description><![CDATA[The WPF and Silverlight Designer for Visual Studio 2010 shares several new design time (d:) properti]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The WPF and Silverlight Designer for Visual Studio 2010 shares several new design time (d:) properties and design time MarkupExtensions with Expression Blend 3 that provide necessary information for the WPF and Silverlight Designer to deliver a great editing experience.</p>
<p>I have explained the d:DesignData MarkupExtension in detail in this blog post:&#160; <a href="http://karlshifflett.wordpress.com/2009/10/21/visual-studio-2010-beta2-sample-data-project-templates/" target="_blank">Visual Studio 2010 Beta2 Sample Data Project Templates</a>.</p>
<p>In this post I’ll cover the d:DataContext property and the d:DesignInstance MarkupExtension.</p>
<h4>d:DataContext</h4>
<p>d:DataContext gives developers the ability to set a design time d:DataContext that is separate and independent of the run-time DataContext property. </p>
<p>This feature solves the problem of developers wanting to set their DataContext programmatically but also wanting design time data.</p>
<p>All d: properties are ignored during compilation and are not part of any run-time assemblies.</p>
<h4>d:DesignInstance</h4>
<p><strong>Purpose:</strong>&#160; Provides a design time shape to the d:DataContext its applied to.</p>
<p><strong>Example:&#160; </strong>In the below snippet the Person class is the shape provided by d:DesignInstance to the Grid’s d:DataContext.</p>
<div class="code">
<pre><span style="color:blue;">&#60;</span><span style="color:#a31515;">Grid </span><span style="color:red;">d</span><span style="color:blue;">:</span><span style="color:red;">DataContext</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">d</span><span style="color:blue;">:</span><span style="color:#a31515;">DesignInstance </span><span style="color:red;">local</span><span style="color:blue;">:</span><span style="color:red;">Person</span><span style="color:blue;">}&#34;&#62;
</span></pre>
</div>
<p><strong>Note: </strong>In the above example, the Person class is actually a faux type (fake or substitute type).&#160; This faux type enables types that are not creatable to be created and their properties exposed as a shape.&#160; See the below section on creating creatable types.</p>
<p><strong>Usage:</strong>&#160; So, now that the d:DataContext has shape, what can I do with it?</p>
<p>The shape is used by the new Binding Builder to expose the properties of the type in d:DataContext.&#160; You can see in the below image, the four properties exposed by the Person class.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/bindingbuilder.png"><img style="display:inline;border-width:0;" title="BindingBuilder" border="0" alt="BindingBuilder" src="http://karlshifflett.files.wordpress.com/2009/10/bindingbuilder_thumb.png?w=480&#038;h=467" width="480" height="467" /></a> </p>
<p>The Binding Builder is opened by clicking or right clicking on the Property Marker in the Properties Window.&#160; The Property Marker is the icon to the right of the property name.&#160; The Binding Builder is a GUI for editing bindings in WPF and Silverlight.&#160; This is a super feature</p>
<blockquote>
<p>The Cider Team has a great explanation of the new features on <a href="http://windowsclient.net/wpfdesigner/" target="_blank">WindowsClient.net</a> that you can read here: <a href="http://windowsclient.net/wpfdesigner/articles/visual-studio-setup.aspx" target="_blank">Setting Up Visual Studio for WPF and Silverlight Development</a>.&#160; There is an article and video.</p>
<p>You can read additional Cider Team Online material here:&#160; <a href="http://windowsclient.net/wpfdesigner/default.aspx" target="_blank">WPF and Silverlight Designer for Visual Studio 2010</a>.&#160; We are in the process of adding many more articles.&#160; While the material is initially geared for developers coming from other platforms to WPF or Silverlight, it has a lot of great information even for the seasoned XAML Head.&#160; Yea, I said it.&#160; I’m a XAML Head too and proud of it.&#160; (LOL)</p>
</blockquote>
<p>Without d:DesignInstance, d:DesignData or d:Source applied to a CollectionViewSource the Binding Builder would have no way to determine shape and provide a list of properties.</p>
<p><strong>Note:</strong>&#160; If d:DataContext is not set, but DataContext is set and has a created type assigned to it, this will also supply shape that the Binding Builder can use for listing properties.</p>
<h4>Creating Creatable Types</h4>
<div class="code">
<pre> <span style="color:blue;">&#60;</span><span style="color:#a31515;">Grid </span><span style="color:red;">d</span><span style="color:blue;">:</span><span style="color:red;">DataContext</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">d</span><span style="color:blue;">:</span><span style="color:#a31515;">DesignInstance </span><span style="color:red;">local</span><span style="color:blue;">:</span><span style="color:red;">Person</span><span style="color:blue;">, </span><span style="color:red;">IsDesignTimeCreatable</span><span style="color:blue;">=True}&#34;&#62;
</span></pre>
</div>
<p>d:DesignInstance provides a technique for creating a non-faux type.&#160; Setting the property IsDesignTimeCreatable to True on the d:DesignInstance MarkupExtension enables this.</p>
<h4>Links</h4>
<p><a href="http://msdn.microsoft.com/en-us/library/dd490796(VS.100).aspx" target="_blank">MSDN d:DesignInstance Walkthrough</a></p>
<p>Video showing d:DesignData and d:DesignInstance can be viewed from this blog post:&#160; <a title="Permanent Link: Visual Studio 2010 Beta2 Sample Data Project&#160;Templates" href="http://karlshifflett.wordpress.com/2009/10/21/visual-studio-2010-beta2-sample-data-project-templates/">Visual Studio 2010 Beta2 Sample Data Project Templates</a>.</p>
<p><font color="#333333">The above post also has source code for sample data templates.&#160; There four of the templates are tutorial walkthroughs on this topic and sample data.</font></p>
<p>The two .xaml files in the DesignInstance Samples folder are the walkthroughs.&#160; You can create this project in VB.NET or C# by using one of the below templates when creating your project.</p>
<ul>
<li>VB WPF Application DesignData Sample – VB.NET Sample WPF Application that demonstrates consuming sample data. </li>
<li>CS WPF Application DesignData Sample – C# Sample WPF Application that demonstrates consuming sample data.</li>
</ul>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/designinstanceexamples.png"><img style="display:inline;border-width:0;" title="DesignInstanceExamples" border="0" alt="DesignInstanceExamples" src="http://karlshifflett.files.wordpress.com/2009/10/designinstanceexamples_thumb.png?w=266&#038;h=313" width="266" height="313" /></a> </p>
<h4>Close</h4>
<p>Hope you find d:DesignInstance and d:DesignData Sample Data in Visual Studio 2010 Beta2 a productive feature for your application development.</p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[New Options for Visual Studio 2010 Beta2 WPF and Silverlight Projects]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/27/new-options-for-visual-studio-2010-beta2-wpf-and-silverlight-projects/</link>
<pubDate>Tue, 27 Oct 2009 16:26:34 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/27/new-options-for-visual-studio-2010-beta2-wpf-and-silverlight-projects/</guid>
<description><![CDATA[To get to this Options dialog, use the Tools menu, selected Options, select Text Editors, select XAM]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://karlshifflett.files.wordpress.com/2009/10/tooloptions.png"><img style="display:inline;border-width:0;" title="ToolOptions" border="0" alt="ToolOptions" src="http://karlshifflett.files.wordpress.com/2009/10/tooloptions_thumb.png?w=700&#038;h=413" width="700" height="413" /></a> </p>
<p>To get to this Options dialog, use the Tools menu, selected Options, select Text Editors, select XAML, select Miscellaneous.</p>
<h4>MarkupExtension IntelliSense and Editing</h4>
<p>The most requested feature for the WPF &#38; Silverlight XAML Editor was MarkupExtension IntelliSense.&#160; This feature has been added to Visual Studio 2010 Beta2.</p>
<p>In addition to IntelliSense you also get some entry helpers.</p>
<p>1.&#160; When you type a { (left curly brace) Visual Studio will automatically insert the } (right curly brace) for you.&#160; </p>
<blockquote><p>You can disable this feature by un-checking the above option, “Closing braces for MarkupExtensions.”</p>
</blockquote>
<p>2.&#160; When you press the SPACEBAR inside {} (curly braces) Visual Studio will automatically insert a comma for you to the left of the space added by pressing the SPACEBAR.&#160; </p>
<blockquote><p>You can disable this feature by un-checking the above option, “Commas to separate MarkupExtension parameters.”</p>
</blockquote>
<h4>Toolbox Auto-Population</h4>
<p>Visual Studio 2010 Beta2 now adds all Custom Controls and UserControls in the Solution to the Toolbox when you build the solution.&#160; Control’s are added to a separate Toolbox tab for each project.&#160; </p>
<blockquote><p>You can disable this feature by un-checking the above option, “Automatically populate toolbox items.”</p>
</blockquote>
<p><strong>How Auto-Population Works</strong></p>
<p>When you build a project, its corresponding tab in the Toolbox is cleared and then all types that derive from FrameworkElement are added to the Toolbox tab for that project.&#160; (see Fine Print below for more details)</p>
<p>When you build the solution, all projects Toolbox tabs are updated as explained above.</p>
<blockquote><p>If you want to prevent an item from appearing in the Toolbox during the Auto-Population processing decorate the class with the System.ComponentModel.DesignTimeVisible attribute and pass False in the constructor.</p>
</blockquote>
<p>The following code snippet shows the DesignTimeVisible attribute decorating the CustomView UserControl.&#160; The CustomView UserControl will not appear in the Toolbox.</p>
<div class="code">
<pre><span style="color:blue;">Imports </span>System.ComponentModel

&#60;<span style="color:#2b91af;">DesignTimeVisible</span>(<span style="color:blue;">False</span>)&#62;
<span style="color:blue;">Public Class </span><span style="color:#2b91af;">CustomerView
    </span><span style="color:blue;">Inherits </span><span style="color:#2b91af;">UserControl

</span><span style="color:blue;">End Class</span></pre>
</div>
<p><strong>Fine Print</strong></p>
<p>To appear in the Auto-Population Toolbox process a type must derive from FrameworkElement and:</p>
<p>1.&#160; Are public and have a default public or internal constructor or are internal and have either a default public or internal constructor</p>
<p>3.&#160; Types deriving from Window or Page are ignored</p>
<p>4.&#160; FrameworkElements in other .exe projects are ignore</p>
<p>5.&#160; Internal classes will only be displayed when the active designer is for an item in the same project</p>
<p>6.&#160; Friend Assemblies are not taken into account for Toolbox Auto-Population</p>
<h4>Close</h4>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[XAML Power Toys for Visual Studio 2010 Beta2 Cider Designer]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2010-beta2-cider-designer/</link>
<pubDate>Sun, 25 Oct 2009 22:29:35 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2010-beta2-cider-designer/</guid>
<description><![CDATA[Current Version 1.0.1, Last Update 28 October 2009 These last few weeks I’ve been writing control de]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><span style="font-family:calibri;color:#808080;font-size:small;">Current Version 1.0.1, Last Update 28 October 2009</span></p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/v1gridtoo.jpg"><img style="display:inline;" title="v1GridToo" alt="v1GridToo" src="http://karlshifflett.files.wordpress.com/2009/10/v1gridtoo_thumb.jpg?w=556&#038;h=611" width="556" height="611" /></a></p>
<p>These last few weeks I’ve been writing control designers for Visual Studio 2010 Beta2 WPF and Silverlight controls.</p>
<p>Turns out this is much easier than I expected and is a lot of fun too!</p>
<p>This application is an example for writing a globalized WPF &#38; Silverlight platform neutral control designer.&#160; Both WPF &#38; Silverlight applications use the same Design library.&#160; You can check out the source code to see how this is done.&#160; This source code is in VB.NET.&#160; Later this week, I’ll be posting another full featured article and code example in C# and VB.NET for writing a platform neutral control designer for WPF &#38; Silverlight custom controls.&#160; The project also includes two controls you can use in your projects.&#160; (Yes, Karl now speaks C#.&#160; Took about 2 days to pick it up.&#160; Still have to lookup some syntax but pretty fluent now.)</p>
<p>I must give credit where credit is due.&#160; I got a good bit of feedback and suggestions from my teammates on the Cider Team (WPF &#38; Silverlight Designer Team).&#160; Thanks Mark, Zhanbo, Bin, Pav, Marco, Ben&#160; and Ray.&#160; My great friend <a href="http://joshsmithonwpf.wordpress.com/" target="_blank">Josh Smith</a> also came over one day for some pair programming activities.&#160; Thanks Josh!</p>
<p>For those that care, the above designer is an MVVM application that is completely data driven from the ViewModel.</p>
<h4>Grid Layout Tool</h4>
<p>The Grid Layout Tool provides an abstract view of the selected Grid control in the designer that enables editing the Rows and Columns of the selected Grid.</p>
<p>The above image is the Grid Layout Tool that allows you to:</p>
<ul>
<li>Move (reorder) rows and columns </li>
<li>Move (reorder) multiple rows and columns (when multi-selected with CTRL+click) </li>
<li>Insert row or column before or after any row or column </li>
<li>Delete row or column </li>
<li>Set all row or all columns sizes using the TextBoxes at the top.&#160; Enter value and press ENTER. </li>
<li>Set individual row or column size by clicking the text value the Azure row or column headers and then editing them.&#160; Enter value and press ENTER. </li>
<li>To set size to auto type “a” or “auto” and press ENTER. </li>
<li>Designer is updated real time as you make your changes. </li>
<li>Clicking the “Save” button commits the changes into one Undo Transaction. </li>
<li>Clicking the “Cancel” button cancels all changes and puts the designer back in its original state. </li>
</ul>
<h4>Menu Options</h4>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/v1menu.jpg"><img style="display:inline;border-width:0;" title="v1Menu" border="0" alt="v1Menu" src="http://karlshifflett.files.wordpress.com/2009/10/v1menu_thumb.jpg?w=600&#038;h=322" width="600" height="322" /></a></p>
<p>This menu is only available when you have selected a GRID control in the WPF or Silverlight designer.</p>
<p><strong>Chainsaw – Leaves Alignment</strong></p>
<p>The chainsaw will remove all Margins, MinHeights, MinWidths and from CheckBox, RadioButton, Label, TextBlock will remove height and widths and on TextBox will remove height.&#160; Will set all Grid Rows to Auto.&#160; Will remove Name and x:Name if enabled.</p>
<p>Use this command if you do not have styles defined that determine layout for your form.&#160; (see video)</p>
<p><strong>Chainsaw – Clears Alignments</strong></p>
<p>The chainsaw will remove all HorizontalAlignments, VerticalAlignments, Margins, MinHeights, MinWidths and from CheckBox, RadioButton, Label, TextBlock will remove height and widths and on TextBox will remove height.&#160; Will set all Grid Rows to Auto.&#160; Will remove Name and x:Name if enabled.</p>
<p>Use this command is you have a styles defined that determines layout for your form.&#160; (see video)</p>
<p><strong>Modify Control Tags on Create</strong></p>
<p>If this option is checked the following controls will be affected when you create the control using the ToolBox.</p>
<p>StackPanel and Grid – Alignments and Name cleared&#160; (note: when the StackPanel is created inside a GroupBox or Expander, the tag modifications are ignored and overridden by the designer.)</p>
<p>TextBox, TextBlock, Label, CheckBox, RadioButton – smaller sizes than the Visual Studio defaults and Named is cleared.&#160; The smaller sizes widths were 120, now 80, except TextBox which is 100.&#160; You can play around with control creation to see if this makes sense for you.</p>
<p><strong>Modify Control Tags and Chainsaw Clears Name</strong></p>
<p>If you want control names cleared by the Chainsaw or the control Modify Control Tags on Create feature check this menu option.&#160; To turn off name clearing, uncheck this menu option.</p>
<h4>Video</h4>
<p>PLEASE view this short tutorial video.&#160; You will get a full and quick understanding of this great feature.</p>
<p>This video is on my SkyDrive.&#160; Silverlight Streaming is being discontinued and won’t let me upload any more video files.&#160; Like many others, I’m trying to find an alternate location to host all my training videos.&#160; Relocating and re-pointing all my videos will be a huge PIA.&#160; Any suggestions for hosting would be greatly appreciated.</p>
<p>The below video can be downloaded and viewed.&#160; Click the link to be taken to my SkyDrive.</p>
<p><img src="http://karlshifflett.files.wordpress.com/2008/01/movie1.gif" />&#160; <a href="http://cid-51de981e071f222b.skydrive.live.com/browse.aspx/Public/XAML%20Power%20Toys%202010%20for%20Cider" target="_blank">XAML Power Toys 2010 Beta2 for Cider Tutorial Video (13 minutes)</a></p>
<h4>Downloads – Visual Studio 2010 Beta2 ONLY</h4>
<p>This software will not work in the final release of Visual Studio 2010.&#160; That includes RC/RTM releases.&#160; I will release a new version when RC (release candidates) are published.</p>
<p><font color="#800000"><strong>Remember</strong> – Please <strong><u>build your projects</u></strong> before attempting to create forms, ViewModels or using the Field List</font>.</p>
<p>Please set your <strong>Control Defaults</strong> after installing, new options have been added.</p>
<p>Download now comes from my Windows Live Sky Drive.</p>
<blockquote><p><u><strong>Microsoft employees</strong> please read this</u>:</p>
<p>If you are using the final Beta2 release these links and this software will work for you.</p>
<p>If not please&#160; email me and I’ll send you an internal drop location you can get this software from.&#160; (Just look me up in the Global address book.)</p>
</blockquote>
<p><a href="http://cid-51de981e071f222b.skydrive.live.com/self.aspx/Public/XAML%20Power%20Toys%202010%20for%20Cider/XAMLPowerToys2010ForCider-1-0-1Release.zip" target="_blank">XAML Power Toys 2010 for Cider &#8211; for Visual Studio 2010 Beta2 v1.0.1 Release (459 KB)</a></p>
<p><a href="http://cid-51de981e071f222b.skydrive.live.com/self.aspx/Public/XAML%20Power%20Toys%202010%20for%20Cider/XAMLPowerToys2010ForCider-1-0-1Source.zip" target="_blank">XAML Power Toys 2010 for Cider &#8211; for Visual Studio 2010 Beta2 v1.0.1 Source Code not required (85 KB)</a></p>
<p><strong>Alternate Download Site</strong></p>
<p>Some corporate firewalls do not allow access to Windows Live Sky Drive.&#160; You can download the installer here.&#160; Remember to rename the file from .doc to .zip.&#160; This is a requirement of WordPress.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/xamlpowertoys2010forcider-1-0-1release-zip.doc" target="_blank">XAML Power Toys 2010 for Cider &#8211; for Visual Studio 2010 Beta2 v1.0.1 Release (459 KB)</a></p>
<h4>Your Feedback</h4>
<p>I can’t not over emphasize the the importance and the weight of your feedback on this block post.&#160; My team (Cider Team that delivers the WPF &#38; Silverlight Designer) is eager to hear from customers on features you need in the WPF &#38; Silverlight Designer and XAML Editor.</p>
<h4>Close</h4>
<p>Hope you use and enjoy XAML Power Toys for Visual Studio 2010 Beta2 for Cider.</p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[XAML Power Toys for Visual Studio 2010 Beta2]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2010-beta2/</link>
<pubDate>Sun, 25 Oct 2009 19:44:10 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2010-beta2/</guid>
<description><![CDATA[This post is the home page for XAML Power Toys for Visual Studio 2010 Beta2.&#160; Please post all c]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This post is the home page for XAML Power Toys for Visual Studio 2010 Beta2.&#160; Please post all comments and suggestions for this version on this post.</p>
<p>XAML Power Toys for Visual Studio 2010 has all the same features as <a href="http://karlshifflett.wordpress.com/xaml-power-toys/" target="_blank">XAML Power Toys for Visual Studio 2008</a> except as noted below.&#160; Please use the <a href="http://karlshifflett.wordpress.com/xaml-power-toys/" target="_blank">XAML Power Toys for Visual Studio 2008</a> page as a reference for how the the features work.&#160; Please download this version of the software below. </p>
<p>During development of XAML Power Toys for Beta2 I ran into some bugs that are being corrected for the final release of Visual Studio 2010.&#160; As a result I had to cut a few features for this release.</p>
<p>The below image displays the menu for XAML Power Toys for Visual Studio 2010 Beta2.&#160; Users of the 2008 version will notice the “Group Into” submenu is gone; the “Tools” submenu is gone and that “Create ViewModel for Class” is displayed in the this submenu but it shouldn’t.</p>
<p>The bottom line is, submenus are broken in Beta2 and there is no known workaround.</p>
<p>Notice I have moved “Set Control Defaults” and “About” features from the “Tools” submenu to this submenu.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/xpt2010menu.png"><img style="display:inline;border-width:0;" title="XPT2010Menu" border="0" alt="XPT2010Menu" src="http://karlshifflett.files.wordpress.com/2009/10/xpt2010menu_thumb.png?w=686&#038;h=274" width="686" height="274" /></a> </p>
<p>The other grayed out menu options are not enabled because no XAML was selected when the screen shot was taken.&#160; All features on this menu work as advertised.&#160; “Create ViewModel for Class” just displays here in error and will never be enabled.&#160; It does work correctly in the C# and VB.NET Code Windows.</p>
<p>The good news is, the above software has been updated and works great in Visual Studio 2010 Beta2.</p>
<p>When the final release of Visual Studio 2010 is public I will release a new version without these limitations.</p>
<h4>Downloads – Visual Studio 2010 Beta2 ONLY</h4>
<p><font color="#800000"><strong>Remember</strong> – Please <strong><u>build your projects</u></strong> before attempting to create forms, ViewModels or using the Field List</font>.</p>
<p>Please set your <strong>Control Defaults</strong> after installing, new options have been added.</p>
<p>Download now comes from my Windows Live Sky Drive.</p>
<p><a href="http://cid-51de981e071f222b.skydrive.live.com/self.aspx/Public/XAML%20Power%20Toys%202010/XAMLPowerToys2010-5-1-0001Release.zip" target="_blank">Download XAML Power Toys for Visual Studio 2010 Beta2 v5.1.0001 Release Installer (809 KB)</a></p>
<p><a href="http://cid-51de981e071f222b.skydrive.live.com/self.aspx/Public/XAML%20Power%20Toys%202010/XAMLPowerToys2010-5-1-0001Source.zip" target="_blank">Download XAML Power Toys for Visual Studio 2010 Beta2 v5.1.0001 Source Code not required (594 KB)</a></p>
<p><strong>Alternate Download Site</strong></p>
<p>Some corporate firewalls do not allow access to Windows Live Sky Drive.&#160; You can download the installer here.&#160; Remember to rename the file from .doc to .zip.&#160; This is a requirement of WordPress.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/xamlpowertoys2010-5-1-0001release-zip.doc" target="_blank">Download XAML Power Toys for Visual Studio 2010 Beta2 v5.1.0001 Release Installer (809 KB)</a></p>
<h4>Visual Studio 2010 Beta2 Known Issues</h4>
<p>The below issues are known, being worked on and will be fixed for the RC/RTM milestone.</p>
<p><strong>1.&#160; Can’t Add Menu inside an AddIn</strong></p>
<p>This problem was first reported on MS Connect.&#160; </p>
<p><a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=462766&#38;wa=wsignin1.0" target="_blank">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=462766&#38;wa=wsignin1.0</a></p>
<p>&#160; <a href="http://karlshifflett.files.wordpress.com/2009/10/referencesbug1.jpg"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="ReferencesBug" border="0" alt="ReferencesBug" src="http://karlshifflett.files.wordpress.com/2009/10/referencesbug_thumb1.jpg?w=700&#038;h=149" width="700" height="149" /></a> </p>
<p>The workaround for this bug is to set the “Embod Interop Types” property to False for the “Microsoft.VisualStudio.CommandBars 8.0 Reference”</p>
<p><strong>2.&#160; Submenus keep repeating</strong></p>
<p>When adding a submenu to a menu you have added in an AddIn, the submenus will repeat the entire menu tree instead of just showing the submenu items.</p>
<p>This is why I had to remove the “Group Into” submenu and features.&#160; The submenus were simply unusable.</p>
<p><strong>3.&#160; Setup project “Client Framework” problems</strong></p>
<p>When I first compiled the Setup project for this release, upon installation I kept getting a message that I had to install the .NET 4.0 Framework.&#160; Obviously the full .NET framework was installed on the machine.</p>
<p>The only way I could get the message to not show up when running the Setup.exe, was to remove all references to the “Client Framework” within the solution.</p>
<p>Remember, in Visual Studio 2010 Beta2 all WPF and Class Library projects will by default target the “.NET 4.0 Client Framework.”&#160; This is a good thing as it makes application distribution and installation easier for customers of your applications. </p>
<p>However, in this Beta2 release, to get the files to install from the output of the Setup project I had to remove all references to the “Client Framework.”</p>
<h4>Close</h4>
<p>Hope you use and enjoy XAML Power Toys for Visual Studio 2010 Beta2. </p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[XAML Power Toys for Visual Studio 2008 v5.0.0.1 Released]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2008-v5-0-0-1-released/</link>
<pubDate>Sun, 25 Oct 2009 17:50:20 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/25/xaml-power-toys-for-visual-studio-2008-v5-0-0-1-released/</guid>
<description><![CDATA[At the request of a XAML Power Toys user I have updated XAML Power Toys for Visual Studio 2008 to ve]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>At the request of a XAML Power Toys user I have updated XAML Power Toys for Visual Studio 2008 to version v5.0.0.01.</p>
<p>This update adds one new feature and corrects the v5 known issue.</p>
<p>The ViewModel creation window now allows selecting the name of the method that is used to raise the&#160; PropertyChanged event.&#160; You can thank Ted Warring for the suggestion.&#160; Awesome Ted, appreciate the feedback and feature suggestion.</p>
<h4>ViewModel Creator Gets New Feature</h4>
<p>The ViewModel creator tool makes building a ViewModel class a snap.&#160; This feature is sensitive to C# and VB.NET and will create the correct code for you.</p>
<p>The yellow highlight indicates the new feature added in v5.0.0.1.&#160; You can now select or type in the name of the method that will be called when raising a PropertyChanged event.</p>
<p>This name value is also used if you selected the Implement INotifyPropertyChanged option.</p>
<p>This name feature enables you to use any name in your ViewModel base classes and have the generated code us it.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/v5001viewmodel1.jpg"><img style="display:inline;border-width:0;" title="v5001ViewModel" border="0" alt="v5001ViewModel" src="http://karlshifflett.files.wordpress.com/2009/10/v5001viewmodel_thumb1.jpg?w=689&#038;h=744" width="689" height="744" /></a> </p>
<p>As always, you can download XAML Power Toys for Visual Studio 2008 here:</p>
<p><a href="http://karlshifflett.wordpress.com/xaml-power-toys/">http://karlshifflett.wordpress.com/xaml-power-toys/</a></p>
<h4>Close</h4>
<p>Hope you use and enjoy XAML Power Toys for Visual Studio 2008. </p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Much Improved .NET 4.0 WPF Text Rendering]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/22/much-improved-net-4-0-wpf-text-rendering/</link>
<pubDate>Thu, 22 Oct 2009 20:50:04 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/22/much-improved-net-4-0-wpf-text-rendering/</guid>
<description><![CDATA[In .NET 4.0 WPF text rendering has been greatly improved. However this new feature is not enabled by]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In .NET 4.0 WPF text rendering has been greatly improved.</p>
<p>However this new feature is not enabled by default.</p>
<p>You can read the complete feature write up on the <a href="http://blogs.msdn.com/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx" target="_blank">WPF Text Blog</a>.</p>
<p>The scenario where you get the most payback for using this feature is with text that is sized 15pt and below.</p>
<p>Line of Business forms containing TextBlocks, Labels, CheckBoxes, RadioButtons, Buttons and TextBoxes will have FontSizes below 15pt and will receive the most benefit of this new feature.</p>
<p>The feature is enabled by placing the “TextOptions.TextFormattingMode” attached property on the UI Element or on a parent UI Element.</p>
<div class="code">
<pre><span style="color:blue;">&#60;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Text</span><span style="color:blue;">=&#34;.NET 3.5 rendering&#34; /&#62;

&#60;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Text</span><span style="color:blue;">=&#34;.NET 4.0 improved rendering&#34; </span><span style="color:red;">TextOptions.TextFormattingMode</span><span style="color:blue;">=&#34;Display&#34; /&#62;</span></pre>
</div>
<p>The below XAML demonstrates how to have all text rendering use the new text rendering feature by placing the “TextOptions.TextFormattingMode” attached property on the Window.</p>
<p>In the below example, all child controls of the Window will use the new text rendering.</p>
<div class="code">
<pre><span style="color:blue;">&#60;</span><span style="color:#a31515;">Window </span><span style="color:red;">x</span><span style="color:blue;">:</span><span style="color:red;">Class</span><span style="color:blue;">=&#34;MainWindow&#34;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">=&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:red;">x</span><span style="color:blue;">=&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;
    </span><span style="color:red;">Title</span><span style="color:blue;">=&#34;MainWindow&#34; </span><span style="color:red;">Height</span><span style="color:blue;">=&#34;350&#34; </span><span style="color:red;">Width</span><span style="color:blue;">=&#34;525&#34;
    </span><span style="color:red;">TextOptions.TextFormattingMode</span><span style="color:blue;">=&#34;Display&#34;&#62;
    &#60;</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&#62;

        &#60;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Text</span><span style="color:blue;">=&#34;Inherited the .NET 4.0 improved rendering&#34; /&#62;

    &#60;/</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&#62;
&#60;/</span><span style="color:#a31515;">Window</span><span style="color:blue;">&#62;</span></pre>
</div>
<p>Visual Studio 2010 Beta2 and .NET 4.0 have a lot of new goodness, go check it out!</p>
<p>Have a great day,</p>
</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Visual Studio 2010 Beta2 Sample Data Project Templates]]></title>
<link>http://karlshifflett.wordpress.com/2009/10/21/visual-studio-2010-beta2-sample-data-project-templates/</link>
<pubDate>Thu, 22 Oct 2009 01:26:00 +0000</pubDate>
<dc:creator>Karl Shifflett</dc:creator>
<guid>http://karlshifflett.wordpress.com/2009/10/21/visual-studio-2010-beta2-sample-data-project-templates/</guid>
<description><![CDATA[Silverlight 3 application demonstrating Sample Data. Displaying Sample Data in the WPF and Silverlig]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Silverlight 3 application demonstrating Sample Data.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/silverlightsampledata.png"><img style="display:inline;border-width:0;" title="SilverlightSampleData" border="0" alt="SilverlightSampleData" src="http://karlshifflett.files.wordpress.com/2009/10/silverlightsampledata_thumb.png?w=700&#038;h=285" width="700" height="285" /></a></p>
<p>Displaying Sample Data in the WPF and Silverlight Designer for Visual Studio 2010 Beta2 is now very easy with the design time DesignData markup extension.</p>
<p>The below video is a complete tutorial for using Sample Data in your WPF and Silverlight applications.&#160; <u>Please</u> take a view few minutes to view it.</p>
<p>The Sample Application templates have many comments in them, walking you through Sample Data.&#160; <u>Please</u> take a few minutes and review the projects created by the Sample Application Templates.</p>
<h4>Beta2 Template Information</h4>
<p>For Beta2, you need to use these templates to consume sample data in your projects.&#160; The reason is the winfx.targets file for was not updated with the Sample Data Build Actions in time for Beta2.</p>
<p>These project files have been modified to include the DesignData Build Action for the Sample Data files.&#160; All Sample Data files must have their Build Action set to DesignData in the properties window.</p>
<p>These templates will not be required for the final version of Visual Studio 2010.</p>
<p>There are really two templates.</p>
<p>1.&#160; &#60;Language&#62; &#60;Platform&#62; Empty Application – this template consists of an empty project file and the added Build Action DesignData.</p>
<p>2.&#160; &#60;Language&#62; &#60;Platform&#62; Sample Application – this template consists of a sample application that has sample data files and a UserControl that demonstrates how to consume the sample data.&#160; It also includes the added Build Action DesignData.</p>
<h4>WPF Templates</h4>
<p>VB WPF Application DesignData – Empty VB.NET WPF Application template with sample data support.</p>
<p>VB WPF Application DesignData Sample – VB.NET Sample WPF Application that demonstrates consuming sample data.</p>
<p>CS WPF Application DesignData – Empty C# WPF Application template with sample data support.</p>
<p>CS WPF Application DesignData Sample – C# Sample WPF Application that demonstrates consuming sample data.</p>
<h4>Silverlight Templates</h4>
<p>VB SL Application DesignData – Empty VB.NET SL Application template with sample data support.</p>
<p>VB SL Application DesignData Sample – VB.NET Sample SL Application that demonstrates consuming sample data.</p>
<p>CS SL Application DesignData – Empty C# SL Application template with sample data support.</p>
<p>CS SL Application DesignData Sample – C# Sample SL Application that demonstrates consuming sample data.</p>
<h4>Sample Application Template Usage</h4>
<p>The WPF and Silverlight sample application template creates an application complete with sample data files, entity classes, a UserControl consuming the sample data files and</p>
<h4>xmlns:d – How To Easily Add The d: Namespace</h4>
<p>All design time properties live in a design time namespace that is part of this schema: http://schemas.microsoft.com/expression/blend/2008.</p>
<p>Examples of design time properties are, d:DesignWidth, d:DesignHeight, d:DesignInstance, d:DesignData, d:DataContext, d:Source.</p>
<p>In order to use the d: properties you must have a xmlns declaration in your XAML.&#160; In Visual Studio 2010 there is a very easy way to add it to a Window, UserControl or Page .xmal file.</p>
<p>If you select the root control, you’ll see a Root Size Mode button displayed in the lower right hand corner.&#160; Clicking this button changes the size mode of your root container from Auto to Fixed or from Fixed to Auto.</p>
<p>If the d: namespace has not been added to the root control yet, clicking this button will do it for you.&#160; In addition to the d: namespace, mc: is added and the mc:Ignorable is added also.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/autosizedroot.png"><img style="display:inline;border-width:0;" title="AutoSizedRoot" border="0" alt="AutoSizedRoot" src="http://karlshifflett.files.wordpress.com/2009/10/autosizedroot_thumb.png?w=402&#038;h=244" width="402" height="244" /></a></p>
<p>I have modified each of the starter templates below to automatically add this for you.&#160; However, as you add new Windows, Pages or UserControls, those templates may not have the d: namespace declarations, so the above trick comes in handy.</p>
<h4>Adding a New Sample Data File</h4>
<p>Open an existing Sample Data project or Create a new project using one of the Sample Data templates.</p>
<p>Add a resource dictionary to the project naming it &#60;my entity class name&#62;SampleData.xaml.</p>
<p>For example:&#160; Customer sample data file would be named, “CustomerSampleData.xaml”</p>
<p>The the file properties as pictured below:</p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/sampledatasettings.png"><img style="display:inline;border-width:0;" title="SampleDataSettings" border="0" alt="SampleDataSettings" src="http://karlshifflett.files.wordpress.com/2009/10/sampledatasettings_thumb.png?w=403&#038;h=320" width="403" height="320" /></a></p>
<p>Build Action: DesignData</p>
<p>Copy to Output Directory: Do not copy</p>
<p>Custom Too:&#160; &#60;blank&#62;</p>
<h4>Editing a New Sample Data File</h4>
<p>This is an example of a single instance sample data file.</p>
<div class="code">
<pre><span style="color:blue;">&#60;</span><span style="color:#a31515;">local</span><span style="color:blue;">:</span><span style="color:#a31515;">Customer
    </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:red;">local</span><span style="color:blue;">=&#34;clr-namespace:WPFApplication2&#34;
    </span><span style="color:red;">Age</span><span style="color:blue;">=&#34;21&#34; </span><span style="color:red;">Email</span><span style="color:blue;">=&#34;jim@hotmail.com&#34;
    </span><span style="color:red;">FirstName</span><span style="color:blue;">=&#34;Jim&#34; </span><span style="color:red;">LastName</span><span style="color:blue;">=&#34;Smith&#34; /&#62;</span></pre>
</div>
<p>Sample Data files allow you to construct your objects in XAML.&#160; You can set the required properties as illustrated above.</p>
<p>The below code illustrates how to create a collection of items in a sample data file.</p>
<div class="code">
<pre><span style="color:blue;">&#60;</span><span style="color:#a31515;">local</span><span style="color:blue;">:</span><span style="color:#a31515;">Customers </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:red;">local</span><span style="color:blue;">=&#34;clr-namespace:WPFApplication2&#34;&#62;
    &#60;</span><span style="color:#a31515;">local</span><span style="color:blue;">:</span><span style="color:#a31515;">Customer
        </span><span style="color:red;">Age</span><span style="color:blue;">=&#34;21&#34; </span><span style="color:red;">Email</span><span style="color:blue;">=&#34;jim@hotmail.com&#34;
        </span><span style="color:red;">FirstName</span><span style="color:blue;">=&#34;Jim&#34; </span><span style="color:red;">LastName</span><span style="color:blue;">=&#34;Smith&#34; /&#62;
    &#60;</span><span style="color:#a31515;">local</span><span style="color:blue;">:</span><span style="color:#a31515;">Customer
        </span><span style="color:red;">Age</span><span style="color:blue;">=&#34;22&#34; </span><span style="color:red;">Email</span><span style="color:blue;">=&#34;jane@hotmail.com&#34;
        </span><span style="color:red;">FirstName</span><span style="color:blue;">=&#34;Jane&#34; </span><span style="color:red;">LastName</span><span style="color:blue;">=&#34;Smith&#34; /&#62;
&#60;/</span><span style="color:#a31515;">local</span><span style="color:blue;">:</span><span style="color:#a31515;">Customers</span><span style="color:blue;">&#62;
</span></pre>
</div>
<p>The above Customers class derives from the Generic List of Customer.</p>
<h4>Consuming Sample Data in WPF</h4>
<div class="code">
<pre><span style="color:green;">&#60;!-- DataGrid Sample--&#62;
</span><span style="color:blue;">&#60;</span><span style="color:#a31515;">Grid </span><span style="color:red;">d</span><span style="color:blue;">:</span><span style="color:red;">DataContext</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">d</span><span style="color:blue;">:</span><span style="color:#a31515;">DesignData </span><span style="color:red;">Source</span><span style="color:blue;">=</span>/<span style="color:blue;">SampleData</span>/<span style="color:blue;">PeopleSampleData.xaml}&#34;
      </span><span style="color:red;">Grid.Row</span><span style="color:blue;">=&#34;1&#34; </span><span style="color:red;">Margin</span><span style="color:blue;">=&#34;7&#34;&#62;
    &#60;</span><span style="color:#a31515;">DataGrid </span><span style="color:red;">ItemsSource</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding</span><span style="color:blue;">}&#34;/&#62;
&#60;/</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&#62;</span></pre>
</div>
<p>Sample Data is exposed through the d:DataContext design time property.&#160; Design time properties are not compiled into your applications.</p>
<p>In WPF this is how you start at the root, navigate to SampleData folder and get the xaml file.</p>
<h4>Consuming Sample Data in Silverlight</h4>
<div class="code">
<pre><span style="color:green;">&#60;!-- DataGrid Sample--&#62;
</span><span style="color:blue;">&#60;</span><span style="color:#a31515;">Grid </span><span style="color:red;">d</span><span style="color:blue;">:</span><span style="color:red;">DataContext</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">d</span><span style="color:blue;">:</span><span style="color:#a31515;">DesignData </span><span style="color:red;">Source</span><span style="color:blue;">=..</span>/<span style="color:blue;">SampleData</span>/<span style="color:blue;">PeopleCollectionSampleData.xaml}&#34;
      </span><span style="color:red;">Grid.Row</span><span style="color:blue;">=&#34;1&#34; </span><span style="color:red;">Margin</span><span style="color:blue;">=&#34;7&#34;&#62;
    &#60;</span><span style="color:#a31515;">data</span><span style="color:blue;">:</span><span style="color:#a31515;">DataGrid </span><span style="color:red;">ItemsSource</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding</span><span style="color:blue;">}&#34;/&#62;
&#60;/</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&#62;
</span></pre>
</div>
<p>In Silverlight you have to ../ up to the root, then navigate to SampleData folder and get the xaml file.</p>
<p>Slight difference between WPF and Silverlight.</p>
<h4>Video</h4>
<p>PLEASE view this short tutorial video.&#160; You will get a full and quick understanding of this great feature.</p>
<p>This video link supports right click, save as…</p>
<p><img src="http://karlshifflett.files.wordpress.com/2008/01/movie1.gif" />&#160; <a href="http://silverlight.services.live.com/48184/Sample%20Data%20Introduction/video.wmv" target="_blank">Sample Data Tutorial Video (22 minutes)</a></p>
<h4>Installing Templates Using The Download</h4>
<p><strong>For VB.NET</strong> copy the download to:</p>
<p>C:\users\&#60;your user name&#62;\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual Basic</p>
<p>Unzip the download in this folder.&#160; You should have 4 zip files in the folder.&#160; You are ready to go.</p>
<p><strong>For C# </strong>copy the download to:</p>
<p>C:\users\&#60;your user name&#62;\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#</p>
<p>Unzip the download in this folder.&#160; You should have 4 zip files in the folder.&#160; You are ready to go.</p>
<h4>Downloads</h4>
<p>After downloading one or both template downloads, you’ll need to rename the file extension from .doc to .zip.&#160; This is a requirement of WordPress.com.</p>
<p><font color="#ff0000"><strong>Requires</strong></font>:&#160; Visual Studio 2010 <strong>Beta2</strong></p>
<p>Silverlight Templates require:&#160; <strong>Silverlight 3</strong></p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/vbsampledatatemplates-10-28-2009-zip.doc" target="_blank">VB.NET Project Templates (61KB) (updated 10-28-2009)</a></p>
<p><a href="http://karlshifflett.files.wordpress.com/2009/10/cssampledatatemplates-10-28-2009-zip.doc" target="_blank">C# Project Templates (58KB) (updated 10-28-2009)</a></p>
<h4>Installing Templates From Within Visual Studio 2010 Beta2</h4>
<p>The sample data templates are also be individually available on the Visual Studio Code Gallery.</p>
<p>To use a single template open the New Project Dialog and select the Online Templates tab at the bottom left.&#160; You can browse all available templates or search for “design” and all the templates will be listed.</p>
<h4>Close</h4>
<p>Hope you use and enjoy Sample Data in Visual Studio 2010 Beta2.</p>
<p>Gentle reminder, please watch the above video too.</p>
<p>Have a great day,</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Generics Methods]]></title>
<link>http://carlossantos.wordpress.com/2009/10/20/generics-methods/</link>
<pubDate>Wed, 21 Oct 2009 01:17:57 +0000</pubDate>
<dc:creator>Carlos Marcelo Santos</dc:creator>
<guid>http://carlossantos.wordpress.com/2009/10/20/generics-methods/</guid>
<description><![CDATA[En este post voy a escribir sobre métodos genéricos. La idea es presentar un método que acepte dos p]]></description>
<content:encoded><![CDATA[En este post voy a escribir sobre métodos genéricos. La idea es presentar un método que acepte dos p]]></content:encoded>
</item>
<item>
<title><![CDATA[Generics]]></title>
<link>http://carlossantos.wordpress.com/2009/10/20/generics/</link>
<pubDate>Tue, 20 Oct 2009 22:31:39 +0000</pubDate>
<dc:creator>Carlos Marcelo Santos</dc:creator>
<guid>http://carlossantos.wordpress.com/2009/10/20/generics/</guid>
<description><![CDATA[A partir de la versión 2.0 del Framework .NET contamos con el namespace Generics que define una cant]]></description>
<content:encoded><![CDATA[A partir de la versión 2.0 del Framework .NET contamos con el namespace Generics que define una cant]]></content:encoded>
</item>
<item>
<title><![CDATA[Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation]]></title>
<link>http://stevefinding.wordpress.com/2009/10/18/showing-a-modal-dialog-box-or-form-when-the-application-is-not-running-in-userinteractive-mode-is-not-a-valid-operation/</link>
<pubDate>Sun, 18 Oct 2009 17:52:14 +0000</pubDate>
<dc:creator>findingsteve</dc:creator>
<guid>http://stevefinding.wordpress.com/2009/10/18/showing-a-modal-dialog-box-or-form-when-the-application-is-not-running-in-userinteractive-mode-is-not-a-valid-operation/</guid>
<description><![CDATA[The full error message is &#8220;Showing a modal dialog box or form when the application is not runn]]></description>
<content:encoded><![CDATA[The full error message is &#8220;Showing a modal dialog box or form when the application is not runn]]></content:encoded>
</item>
<item>
<title><![CDATA[Hide your source code at the browser when hit error]]></title>
<link>http://stevefinding.wordpress.com/2009/10/18/hide-your-source-code-at-the-browser-when-hit-error/</link>
<pubDate>Sun, 18 Oct 2009 14:37:04 +0000</pubDate>
<dc:creator>findingsteve</dc:creator>
<guid>http://stevefinding.wordpress.com/2009/10/18/hide-your-source-code-at-the-browser-when-hit-error/</guid>
<description><![CDATA[I got a little anxious and embarrassed to see my source code exposed at the browser when I got an er]]></description>
<content:encoded><![CDATA[I got a little anxious and embarrassed to see my source code exposed at the browser when I got an er]]></content:encoded>
</item>
<item>
<title><![CDATA[VB.NET - Catch error messages from Process]]></title>
<link>http://ermsitgirl.wordpress.com/2009/10/17/vb-net-process-errmsg/</link>
<pubDate>Sat, 17 Oct 2009 11:24:14 +0000</pubDate>
<dc:creator>zellis</dc:creator>
<guid>http://ermsitgirl.wordpress.com/2009/10/17/vb-net-process-errmsg/</guid>
<description><![CDATA[In previous posts, how to run MySQL scripts and add local users and groups with net command in VB.NE]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In previous posts, how to <a href="http://ermsitgirl.wordpress.com/2009/10/10/vb-net-run-mysql-script/" target="_tab">run MySQL scripts</a> and <a href="http://ermsitgirl.wordpress.com/2009/09/29/vb-net-local-acc/" target="_tab">add local users and groups with net command</a> in VB.NET, it did not catch any errors from the child processes running.</p>
<p>In this post, you will see how easy it is to catch those error messages.</p>
<p>Download code (PDF) <a href="http://ermsitgirl.wordpress.com/files/2009/10/testprocesses.pdf" target="_tab">here</a>.</p>
<p>In this example, it will display message &#34;Process Completed&#34; or the &#34;Error message&#34; in a label on the GUI.</p>
<p><a href="http://ermsitgirl.wordpress.com/files/2009/10/01demoprocess.jpg" target="_tab"><img src="http://ermsitgirl.wordpress.com/files/2009/10/01demoprocess.jpg" alt="Process" title="Process" width="300" height="126" class="alignnone size-medium wp-image-1020" /></a></p>
<p><a href="http://ermsitgirl.wordpress.com/files/2009/10/02demoprocess.jpg" target="_tab"><img src="http://ermsitgirl.wordpress.com/files/2009/10/02demoprocess.jpg" alt="Process" title="Process" width="300" height="126" class="alignnone size-medium wp-image-1021" /></a></p>
<p>Here is the code snippet:<br />
Private Sub RunTheCommand(ByVal TheCommand As String, ByVal TheArguments As String)<br />
&#160;&#160;&#160;&#160;&#160;Try<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Dim proc As New Process<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Dim err As String = &#34;&#34;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#39;Clear any messages in the GUI.<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;lblError.Text = &#34;&#34;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.StartInfo.FileName = TheCommand<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.StartInfo.Arguments = TheArguments</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>&#39;StartInfo.UseShellExecute must be False when StartInfo.RedirectStandardError = True.</strong><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>&#39;Otherwise when reading the stream from StandardError will throw an exception.</strong><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.StartInfo.UseShellExecute = False<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.StartInfo.RedirectStandardError = True<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#39;Don&#8217;t show command prompt window.<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.StartInfo.CreateNoWindow = True<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#39;Start process<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.Start()<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>&#39;Read the error stream (synchronously) first to the end before</strong><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>&#39;waiting for the child process to exit &#8211; to avoid a deadlock.</strong><br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;err = proc.StandardError.ReadToEnd<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.WaitForExit()<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.Close()</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#39;Display errors on the GUI if any<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;If err = &#34;&#34; Then<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;lblError.Text = &#34;Process Completed&#34;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Else<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;lblError.Text = err<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;End If</p>
<p>&#160;&#160;&#160;&#160;&#160;Catch ex As Exception<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;MessageBox.Show(Err.Description, &#34;Process Error&#34;, _<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;MessageBoxButtons.OK, MessageBoxIcon.Error)<br />
&#160;&#160;&#160;&#160;&#160;End Try<br />
End Sub</p>
<p>Happy Coding <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
