<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>VB &amp; .NET Blogs @ vbCity.com</title><link>http://blogs.vbcity.com/MainFeed.aspx</link><description>VB &amp; .NET Blogs @ vbCity.com</description><generator>.Text Version 0.95.2004.102</generator><item><title>How To Animate a TextBox in Windows Forms</title><link>http://blogs.vbcity.com/xtab/archive/2009/07/03/9348.aspx</link><pubDate>Fri, 03 Jul 2009 14:34:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/07/03/9348.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9348.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9348.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/07/03/9348.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9348.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Calibri&gt;
&lt;P&gt;&lt;U&gt;Starting Point&lt;/U&gt;&lt;BR&gt;In my earlier post, &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/07/01/wpf-and-winforms-interop-a-highlighted-textbox.aspx"&gt;the HiliteTextBox&lt;/A&gt;, I created a simple WPF UserControl which is hosted in an ElementHost in a Windows Form. If the user tries to continue without entering text in the TextBox, a bright colored Border would appear around it and stay there until the user does enter something.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight6.png"&gt;&lt;/P&gt;
&lt;P&gt;If we are going to go to the trouble of harnessing WPF's graphics power, we may as well go a step further and add some animation to the control. One simple thing we can do is to animate the Border Thickness.&lt;/P&gt;
&lt;P&gt;This is the XAML for the UserControl I created previously. The only thing I have changed is the class name. It was originally HiliteTextBox, but for this version it will be named AnimatedTextBox :&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="AnimatedTextBox"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BrightGradient"&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;EndPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.056,0.993"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; StartPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.634,0.342"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; SpreadMethod&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Repeat"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFB50D0D"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFE80C2C"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFF4DF5A"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.17399999499320984"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFCA0C1F"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.357"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFDCD762"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.522"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFB70D36"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.716"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFDDEE49"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.823"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="GradBorder"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;BorderBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="LightGray"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="5"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;CornerRadius&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4,4,4,4"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;TextWrapping&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Wrap"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;TextChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox_TextChanged"&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;And this is the code-behind in the UserControl:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; InputTextBox_TextChanged(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Controls.TextChangedEventArgs)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; InputTextBox.Text.Length &amp;gt; 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderBrush = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; SolidColorBrush(Colors.Black)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(1)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderBrush = FindResource(&lt;SPAN style="COLOR: #a31515"&gt;"BrightGradient"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(4)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; IsTBEmpty() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Boolean&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; InputTextBox.Text.Length = 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Creating the Animation in Code&lt;/U&gt;&lt;BR&gt;&lt;BR&gt;Generally, you will find XAML to be the best tool for creating animations - and if they are quite complex then Expression Blend is your best bet. However, you can create a simple animation in the UserControl using code. The following code-behind in the UserControl will cause the Border to change in size over a short period of time: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; ChangeSize()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; ThickAnim &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; ThicknessAnimation&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;With&lt;/SPAN&gt; ThickAnim&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .To = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(14)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .AutoReverse = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Duration = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Duration(TimeSpan.FromSeconds(0.6))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;With&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.GradBorder.BeginAnimation(Border.BorderThicknessProperty, ThickAnim)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Even if you have no experience of WPF, most of the above code is relatively easy to follow.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;ThicknessAnimation &lt;/B&gt;is a class that 'does what it says on the tin', as we say here in the UK - it does exactly what you would expect. It animates the Thickness Property of a target element. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;To &lt;/B&gt;sets the value of the Thickness that has to be reached by the conclusion of the animation.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;AutoReverse&lt;/B&gt; ensures that the Thickness returns to its starting value by the end of the animation sequence.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Duration&lt;/B&gt; assigns the length of time for which the animation will run. Note that in the case of this AutoReversed animation both the increase (The &lt;B&gt;To&lt;/B&gt; value) and the decrease (&lt;B&gt;AutoReverse&lt;/B&gt; to the start value) in size are completed within the allowed Duration. &lt;/P&gt;
&lt;P&gt;The &lt;B&gt;BeginAnimation Method&lt;/B&gt; takes parameters of a kind that might be unfamiliar. It takes the WPF DependencyProperty for the Border class as the first argument and it takes the ThicknessAnimation instance as the second argument. The correct element is animated, of course, because the BeginAnimation method is applied to GradBorder, the Border instance we are dealing with. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.GradBorder.BeginAnimation(Border.BorderThicknessProperty, ThickAnim)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;To get the animation to run, we can incorporate it into the code we used previously that tests if the TextBox is empty. This code is in the Windows Form on which we placed an ElementHost to house the WPF UserControl :&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Button1_Click(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; Button1.Click&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; AnimatedTextBox1.IsTBEmpty = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; Change to bright gradient border&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AnimatedTextBox1.HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; Animate&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AnimatedTextBox1.ChangeSize()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Return focus&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.ElementHost1.Focus()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(&lt;SPAN style="COLOR: #a31515"&gt;"You are clear to continue"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If you try this code and run the project, click the Continue Button with no text in the TextBox, you will see that the Gradient Border appears and then the Border size is animated.&lt;/P&gt;
&lt;P&gt;One thing you may have noticed is that the target in the Button Click event is an object named AnimatedTextBox1. If you scour through the small amount of code I have written so far, you won't find where I created this object. The reason being that I didn't. When you use the Smart Tag in the ElementHost and select the content, it will automatically create an instance for you and name it. &lt;/P&gt;
&lt;P&gt;In the next part, I will create a different animation using what on the face of it seems to be a very complex block of XAML. When we take a closer look, you will see that it is not as complicated as it first appears.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9348.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF-WinForms Interop: A Highlighted TextBox</title><link>http://blogs.vbcity.com/xtab/archive/2009/07/01/9346.aspx</link><pubDate>Wed, 01 Jul 2009 15:49:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/07/01/9346.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9346.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9346.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/07/01/9346.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9346.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Calibri&gt;
&lt;P&gt;&lt;U&gt;Introduction&lt;/U&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;A recent forum post on VBCity asked for a way to highlight an important TextBox in a Windows Form. Assuming that the plan is to highlight the TextBox if the user is about to leave the Form without entering any text into it, there are of course several ways this can be done using Windows Forms techniques. But I thought it might be interesting to try something different and see how easy it would be to create a &lt;B&gt;WPF&lt;/B&gt; UserControl that incorporated a TextBox, a smack-you-in-the-eye gradient and a border with rounded corners*. I picked those last two features because they are not particularly easy to create in Windows Forms. The WPF UserControl would then have to be integrated seamlessly into the Windows Forms environment. &lt;BR&gt;&lt;BR&gt;(*If this isn't cutting-edge enough for you, I will be looking at adding animation to the control in a follow up blog post). &lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;/U&gt;So here's our demo Windows Form that will contain two TextBoxes. The WinForms TextBox is already in place. We will create the WPF one shortly. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight1.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;The WPF UserControl&lt;/U&gt; &lt;BR&gt;The first step is to add a WPF UserControl to the Windows Forms project. This is as simple as hitting Ctrl+Shift+A and selecting "WPF" from the &lt;B&gt;Add New Item&lt;/B&gt; menu which appears. The only choice you will then see is "User Control (WPF)", so select this and change the default name to 'HiliteTextBox.xaml'. Then click the &lt;B&gt;Add&lt;/B&gt; button.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight2.png"&gt;&lt;/P&gt;
&lt;P&gt;The WPF UserControl will be added to your Windows Forms project and behind the scenes all the required References will be added also. The UserControl will be on display as the selected item in Visual Studio and you will see that all the WPF tools are in the Toolbox, not the WinForms ones. &lt;/P&gt;
&lt;P&gt;Delete the default Grid from the UserControl and then drag a Border element from the Toolbox and drop it on the &lt;I&gt;XAML&lt;/I&gt; pane, on one of the empty lines where the Grid used to be. You might think it strange that you drag a visual element and drop it into the markup area. There's nothing to stop you from dropping it in the Design pane instead. If you do this, you will find that several properties are automatically added for you and, as it happens, we don't want those particular properties set and you would therefore have to delete them.&lt;/P&gt;
&lt;P&gt;Assign the Name 'GradBorder' to the Border. Create an empty line between the opening and closing tags of the Border. Drag a TextBox from the Toolbox and drop it on the empty line. Name the TextBox 'InputTextBox'.&lt;/P&gt;
&lt;P&gt;Here's the Markup as at this point:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="HiliteTextBox"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="GradBorder"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox"&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Don't worry that nothing seems to be happening in the Design pane. We'll soon change that. With the Border selected in the XAML pane, move over to the Properties window and change the BorderBrush to LightGray, the BorderThickness and CornerRadius properties to 4. (Still no change in the Design pane; no worries). &lt;/P&gt;
&lt;P&gt;The plan is to have a plain gray border round the TextBox by default and have this change to a bright gradient if the user tries to continue without entering any text in the TextBox. To set this up, first create a new empty line between the opening tag of the Window and the opening tag of the Border. Copy and paste the following markup, which creates a LinearGradientBrush that will be stored as a Resource. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BrightGradient"&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;EndPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.056,0.993"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; StartPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.634,0.342"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; SpreadMethod&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Repeat"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFB50D0D"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFE80C2C"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFF4DF5A"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.17399999499320984"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFCA0C1F"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.357"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFDCD762"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.522"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFB70D36"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.716"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFDDEE49"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.823"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;There is a very good reason for storing the gradient brush separately and naming it with the 'BrightGradient' Key, as you will see soon. &lt;/P&gt;
&lt;P&gt;We will set a few properties on the TextBox. Select the TextBox in the XAML pane and then move to the Properties Window and set the TextWrapping property to 'Wrap'. &lt;/P&gt;
&lt;P&gt;In the XAML pane, create a new empty line inside the opening tag of the TextBox. Then type in: 'TextChanged='. &amp;nbsp;&amp;nbsp; As soon as you do this, an Intellisense popup will appear, inviting you to create a new event handler for the TextChanged event. &lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight3.png"&gt;&lt;BR&gt;&lt;BR&gt;Press the TAB key and the rest of the line will be completed for you. It will be assigned a default name and this event handler will have been added to the code-behind for you. &lt;/P&gt;
&lt;P&gt;Your markup for the Border and TextBox should now look like this:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="GradBorder"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;BorderBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="LightGray"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;CornerRadius&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4,4,4,4"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;TextWrapping&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Wrap"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;TextChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox_TextChanged"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Open up the vb file for the UserControl - HiliteTextBox.xaml.vb - in the project files in Solution Explorer. The InputTextBox_TextChanged event handler will be there for you. &lt;BR&gt;Before we code the event handler though, first create a Sub that will check if the TextBox contains any Text. If it does, the Border will be set to the non-highlighted LightGray; if it doesn't, the Border will be the bright gradient. Enter the following code: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Imports&lt;/SPAN&gt; System.Windows&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Imports&lt;/SPAN&gt; System.Windows.Media&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; InputTextBox.Text.Length &amp;gt; 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderBrush = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; SolidColorBrush(Colors.Black)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(1)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderBrush = FindResource(&lt;SPAN style="COLOR: #a31515"&gt;"BrightGradient"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(4)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The only code that may be new to you might be the FindResource method. This is a really useful feature in WPF, which allows you to ferret through the project and pull out any specific resource that you want to use. The 'BrightGradient', you will recall, is the Key that I assigned to the LinearGradientBrush that I stored as a UserControl Resource earlier.&lt;BR&gt;&lt;BR&gt;The Imports statements at the top of the file ensure that you are accessing elements in the System.Windows namespace.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Hosting the UserControl&lt;/U&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;Now the UserControl is built, it has to be hosted in the Windows Form. Rebuild the project and then select the Form1.vb file. The control that WinForms uses to host WPF UserControls is the ElementHost. This probably won't be in your Toolbox by default, so if it isn't listed, right-click on the Toolbox and select &lt;B&gt;Choose Items...&lt;/B&gt; &amp;nbsp;&amp;nbsp;Select the ElementHost from the .NET Framework Components Tab. &lt;/P&gt;
&lt;P&gt;Drag an instance of the ElementHost from the Toolbox on to the surface of the Form. It will be too large by default, but before you change its size, click on small down arrow next to 'Select Hosted Content' and select HiliteTextBox from the list: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight5.png"&gt;&lt;/P&gt;
&lt;P&gt;The Smart Tag window will close and you can then adjust the size of the ElementHost. As you can see from the screenshot, an error message appears inside the ElementHost. You can safely ignore this as it is only tells you that the Windows Form can't display the visuals of the UserControl at Design time.&lt;/P&gt;
&lt;P&gt;Next we need to add code to the Continue button. For our demo purposes, this will be sufficient:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Button1_Click(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; Button1.Click&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HiliteTextBox1.HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If you look back at the earlier code, you will know that the HighlightEmpty method checks if the TextBox has Text entered and sets the Border accordingly. Although the Button on the Windows Form can't access the graphical elements of the UserControl directly, the HighlightEmpty procedure allows for this interchange between the two. &lt;/P&gt;
&lt;P&gt;Try running the application now. Don't enter any text into the UserControl, then press the Continue button. You should see the highlight gradient border appear around the TextBox.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight6.png"&gt;&lt;/P&gt;
&lt;P&gt;If you then insert some text and press the Continue button again, the highlight border will be replaced with the gray one.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Adding Some Refinements&lt;/U&gt;&lt;BR&gt;That pretty much fulfills the spec, but there are a couple of things I would definitely add. The first feature is that if the user is warned about not entering text, then I would like to give some positive feedback as soon as they do so. That is, before they press the Continue button for a second time. This is easily achieved by adding a line of code to the TextChanged event handler of the InputTextBox. &lt;/P&gt;
&lt;P&gt;Go back to the WPF UserControl code-behind file and add a call to the HighlightEmpty procedure:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; InputTextBox_TextChanged(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Controls.TextChangedEventArgs)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;When you run the application again and press the Continue button with no text in the TextBox, the highlight border appears as before. Now though, when you enter a character, the highlight Border disappears. As a small bonus, if the user then deletes all the text in the TextBox, the highlight will reappear, just to make certain they know about it.&lt;/P&gt;
&lt;P&gt;The second thing I would like to add is a way of giving the developer a choice of actions on the Continue Button Click event. What I mean by this is that at the moment, the call goes to the HighlightEmpty procedure of the UserControl. This approach makes it difficult to build choices into the Button Click event, along the lines of "Depending whether the TextBox is empty, do something here in the &lt;I&gt;Form's&lt;/I&gt; logic". &lt;/P&gt;
&lt;P&gt;There are several easy ways of doing this, including adding a Boolean Property to the UserControl or creating a simple Function. This tests if the InputTextBox is empty and if it is, it Returns True. Based on the returned value, the Button event handler can follow one course of action or another.&lt;/P&gt;
&lt;P&gt;Here's a Function that can be added to the UserControl: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; IsTBEmpty() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Boolean&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; InputTextBox.Text.Length = 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You can then put whatever code you want in the Button Click event handler. Maybe something like:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Button1_Click(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; Button1.Click&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; HiliteTextBox1.IsTBEmpty = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HiliteTextBox1.HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.ElementHost1.Focus()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(&lt;SPAN style="COLOR: #a31515"&gt;"You are clear to continue"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You can apply this approach of using a WPF UserControl in a Windows Form to get access to lots of those enhanced visual goodies that WPF offers, including Animation. As you have seen, creating a WPF UserControl hosted in an ElementHost is a very easy process. As an alternative to fiddling with individual controls on a Windows Form, you can of course include complete WPF Windows in Windows Forms projects. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9346.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>How To Change WPF ListBox SelectedItem Color</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/29/9344.aspx</link><pubDate>Mon, 29 Jun 2009 14:43:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/06/29/9344.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9344.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9344.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/06/29/9344.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9344.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Calibri&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;In this article, we will look at how to alter the background color that appears when a user selects an item in a WPF ListBox &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I've been using DataTemplates to organize the layout of WPF ListBoxes for quite a while now. Not only in my WPF Applications, but also by using WPF/WinForms Interop (See &lt;A href="http://www.devcity.net/Articles/353/1/article.aspx"&gt;my article on devcity&lt;/A&gt; for info on how to do this).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;If you have used DataTemplates yourself, you will know that they can make a great job of packaging up the data display and allowing you to easily create UIs that would be extremely difficult in Windows Forms.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I was working on a ListBox creation task this week. Nothing very fancy - each item comprised of an Image and two items of text inside a Gradient Border:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListBox/ListBox1.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The DataTemplate makes a fair job of tweaking the presentation of the data, but when I ran it and selected an item I still got the standard solid blue selection color: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListBox/ListBox2.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I thought it would be better if I could replace the standard solid blue with something else, but this wasn't something I could achieve by tweaking the DataTemplate. What is needed is a change to the &lt;B&gt;ItemContainerStyle&lt;/B&gt; . &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; It's important to understand the role of these two styling tools. The DataTemplate allows you to package up the individual items of data for display. In the case of a ListBox, you can think of the DataTemplate as sitting inside the ListBoxItem. The ItemContainerStyle is one level up from this. It is responsible for the overall look of the ListBoxItem. So if it helps you to picture the respective roles, you could think of the DataTemplate being contained in the ItemContainerStyle, although that's not exactly how it works. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; The question is, how do you change the ItemContainerStyle to create a different selection color and, once this is done, how do you then get the ListBox to apply it? &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; The answer to the second question is shorter, so I'll deal with that one first. ItemContainerStyle is a &lt;I&gt;property&lt;/I&gt; of the ListBox.&lt;BR&gt;&lt;BR&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; SimpleListBoxItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;BR&gt;As you would expect, this property takes a Style as its value. And that leads us to the answer to the first question - you create a Style, but (and here's the important bit) you ensure that the Style also contains the ControlTemplate for the ListBox. 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;When you stop and think about it, this has to be right. As soon as you find you want to change the fundamental look of the ListBox element, you know you have to work with its Template. How much trouble you then go to in order to rewrite the ControlTemplate is a matter of choice. &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; I began by looking at the full ListBox template, which is fairly lengthy, but then realized two things: 
&lt;OL&gt;
&lt;LI&gt;I already had my DataTemplate in place to do the fancy stuff, so all I needed to do was find the part of the Template that deals with the change of color when an item is selected and tweak this. Everything else could be left unchanged. 
&lt;LI&gt;I didn't need to make any changes to the &lt;I&gt;ListBox&lt;/I&gt; template. What I was dealing with here was the &lt;I&gt;ListBoxItem&lt;/I&gt; template. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;When the requirement is as simple as this, a useful approach is to use the Simple Styles, which are available from many sources. If you haven't come across these yet, they are a cut-down version of the full Styles that are used to create the standard WPF elements. One easy way to access and download them is to enter "Styling with ControlTemplates Sample" in the "Look For" text box of the &lt;B&gt;Index&lt;/B&gt;, (not the online Search box) on the Visual Studio Help page. This will reveal the sample page, which includes a link to download all the simple styles. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;So I took the simple style version of the ListBoxItem and changed the Setter for the IsSelected Trigger. Here is the finished Style: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="SimpleListBoxItem"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ListBoxItem"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="FocusVisualStyle"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Null&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}" /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Template"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter.Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ListBoxItem"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Border"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Padding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="2"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;SnapsToDevicePixels&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="true"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentPresenter&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate.Triggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Trigger&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="IsSelected"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="true"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; TargetName&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Border"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Background"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; AuthorGradient&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Trigger&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate.Triggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter.Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Compared to the full version, that's fairly brief. You will see that I changed the Background color of the Border that contains the ListBoxItem in the Template* from the default to a gradient brush named AuthorGradient that I created and stored in the App.xaml file as an Application scope Resource. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;* Don't confuse the Border in the Style's Child ControlTemplate with the Border that is used in the DataTemplate. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Now when an item is selected, the user sees this gradient instead of the plain blue:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListBox/ListBox3.png"&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;So the full markup for the ListBox is as follows:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="TemplatedListBox"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Left"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;&amp;nbsp; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="10"&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;ItemTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; GreenDataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; SimpleListBoxItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}" &amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;You can see that the ListBox's ItemTemplate is set to the DataTemplate which controls the layout of the data in each ListBoxItem. The ItemContainerStyle contains the template for the ListBoxItem - the one where I changed the selected item color from plain blue to gradient green.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;In order for this particular example to work, you will of course need to have a DataSource available to the ListBox's ItemsSource, to which it can bind. However, you don't need to have a bound ListBox, as you will see at the end of this item. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The DataTemplate I used to create the Border/Image/TextBlocks combination is:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="GreenDataTemplate" &amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; BorderBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; GreenGradient&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;CornerRadius&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4,2"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Orientation&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Horizontal"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Image&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=ImagePath}"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="2,0,4,0"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="60"&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="70"&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;Stretch&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="UniformToFill"&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="120"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;Padding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="2,17,5,2"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="13"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;&amp;nbsp; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Bold"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="DarkGreen"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;&amp;nbsp; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=Name}"&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="56"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Green"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="12,2,0,2"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=Published}" &amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I placed this in the Window.Resources block. Again, this will only work if you have a DataSource which contains the three fields I have used in the Bindings for the Image and TextBlocks - ImagePath, Name and Published. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;If all this DataBinding and DataTemplates is confusing or more than you need, and you simply want to change the selected item background color, then the following ListBox will be sufficient: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; SimpleListBoxItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBoxItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Padding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="5"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="14"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Item 1&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBoxItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBoxItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Padding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="5"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="14"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Item 2&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBoxItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;When an item is selected, the ItemContainerStyle will kick in and the user will see the gradient: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListBox/ListBox4.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; And finally, if you don't even want the gradient, but just need a different solid color, then simply make the change in the Style:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="SimpleListBoxItem"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ListBoxItem"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="FocusVisualStyle"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Null&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}" /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Template"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter.Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ListBoxItem"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Border"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Padding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="2"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;SnapsToDevicePixels&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="true"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentPresenter&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate.Triggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Trigger&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="IsSelected"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="true"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; TargetName&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Border"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Background"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Yellow"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Trigger&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate.Triggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter.Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;As you can see, in this case, I have changed the highlight color to Yellow by editing the Setter for the Border in the IsSelected trigger. The result will be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListBox/ListBox5.png"&gt;&lt;/P&gt;
&lt;P&gt;So, whether you want to create multicolor effects, tied in with bound DataSources, or even if you simply want to change the selected item solid color, you now know how to do it.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9344.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Comparing Differences Between WPF in Visual Studio and Silverlight 2</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/17/9334.aspx</link><pubDate>Wed, 17 Jun 2009 21:24:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/06/17/9334.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9334.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9334.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/06/17/9334.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9334.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;This will be something of a 'Work in Progress' blog item, as I plan to jot down differences between WPF and Silverlight as I find them, either in my own work or from other sources. It can be difficult to keep up to speed on what the precise differences are at any given time. The SDKs, Toolkits, roll out of new editions of both platforms, etc all cause the sands to keep on shifting. Anyhow, I hope those that I do identify will be of help to those of you who are familiar with WPF, but maybe not so much with Silverlight. &lt;/P&gt;
&lt;P&gt;The topic headings are listed alphabetically.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Button Content&lt;/U&gt; &lt;BR&gt;In WPF, you can create a Button and assign its Content in the following way: &lt;BR&gt;&lt;BR&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="5" &amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Silverlight&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;BR&gt;&lt;BR&gt;In Silverlight, you don't have this facility and have to explicitly identify the Content property: &lt;BR&gt;&lt;BR&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="5"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Silverlight"&amp;gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Button ClickMode&lt;/U&gt; &lt;BR&gt;This is more a matter of user expectation than different properties. The WPF Button has a ClickMode property. This is available in both WPF and Silverlight. The three available values are: 
&lt;UL&gt;
&lt;LI&gt;Hover 
&lt;LI&gt;Press 
&lt;LI&gt;Release &lt;/LI&gt;&lt;/UL&gt;As you would expect, when the Click event of the button will fire depends on this particular setting. &lt;BR&gt;The reason why I include it as a difference is that I think it is unlikely that you will often use the 'Hover' option in a desktop application, because that isn't a reaction your users will expect. In a Silverlight, browser based environment, of course, it may well be that users will be happy with a button click firing when they hover over a button. (Actually, I'm not sure that 'hover' is totally accurate. It really seems to fire on the immediate mouse enter action and I haven't found a setting that allows a built in delay.) 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The default value - both for WPF and Silverlight - is 'Release'.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Chrome and Decorators&lt;/U&gt;&lt;BR&gt;Most of the Chromes and Decorators, which can be used to fine tune control templates to a very detailed level, are not available in Silverlight2.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Commands&lt;/U&gt;&lt;BR&gt;Silverlight 2 does not support the WPF Commands structure. It does however support the ICommand interface.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Controls (Visual Elements)&lt;/U&gt;&lt;BR&gt;It's hard to keep up with the permutations and changes, but I think the following breakdown is accurate:&lt;BR&gt;&lt;BR&gt;&lt;U&gt;&lt;FONT color=#408080&gt;1. Available in WPF (.NET 3.5, Visual Studio SP1), but not in Silverlight 2:&lt;/FONT&gt;&lt;/U&gt; &lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;FlowDocument Readers 
&lt;LI&gt;Frame 
&lt;LI&gt;Glyph 
&lt;LI&gt;GroupBox 
&lt;LI&gt;InkCanvas 
&lt;LI&gt;ListView 
&lt;LI&gt;Menu 
&lt;LI&gt;NavigationWindow * 
&lt;LI&gt;Page * 
&lt;LI&gt;PageFunction * 
&lt;LI&gt;RichTextBox 
&lt;LI&gt;StatusBar 
&lt;LI&gt;UniformGrid 
&lt;LI&gt;VirtualizingStackPanel 
&lt;LI&gt;WebBrowser 
&lt;LI&gt;Window 
&lt;LI&gt;WindowsFormsHost &lt;/LI&gt;&lt;/UL&gt;* These items are not necessary in Silverlight, because it is browser based. &lt;BR&gt;&lt;BR&gt;&lt;U&gt;&lt;FONT color=#408080&gt;2. Available in Silverlight 2 , but not in WPF with Visual Studio 2008:&lt;/FONT&gt;&lt;/U&gt;&lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;DataGrid * 
&lt;LI&gt;DatePicker * 
&lt;LI&gt;HyperlinkButton 
&lt;LI&gt;MultiScaleImage &lt;/LI&gt;&lt;/UL&gt;&lt;BR&gt;* These are not included in WPF in Visual Studio 2008, but are downloadable as part of the WPF Toolkit and will almost certainly ship with VS 2010. You can see info and download the WPF Toolkit from &lt;A href="http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25047"&gt;here&lt;/A&gt;. 
&lt;P&gt;&lt;/P&gt;&lt;BR&gt;&lt;U&gt;&lt;FONT color=#408080&gt;3. Available in the Silverlight 2 Toolkit and in WPF in Visual Studio 2008.&lt;/FONT&gt;&lt;/U&gt; &lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;Calendar 
&lt;LI&gt;Expander 
&lt;LI&gt;GridSplitter 
&lt;LI&gt;TabControl 
&lt;LI&gt;TreeView 
&lt;LI&gt;ViewBox 
&lt;LI&gt;WrapPanel &lt;/LI&gt;&lt;/UL&gt;&lt;BR&gt;&lt;U&gt;&lt;FONT color=#408080&gt;4. Available in the Silverlight 2 Toolkit, but not in WPF. &lt;/FONT&gt;&lt;/U&gt;&lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;Accordion 
&lt;LI&gt;AutoCompleteBox 
&lt;LI&gt;ButtonSpinner 
&lt;LI&gt;Data Visualization/Chart Tools 
&lt;LI&gt;DomainUpDown 
&lt;LI&gt;NumericUpDown 
&lt;LI&gt;TimePicker 
&lt;LI&gt;TransitioningContentControl &lt;/LI&gt;&lt;/UL&gt;&lt;BR&gt;&lt;BR&gt;&lt;U&gt;&lt;FONT color=#408080&gt;5. Available in the WPF SDK, but not in Silverlight 2.&lt;/FONT&gt;&lt;/U&gt; &lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;Ribbon &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;DataBinding &lt;/U&gt;&lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;Silverlight 2 does not support One-Way To Source binding.&lt;BR&gt;
&lt;LI&gt;With WPF, the default binding mode is dependent upon the dependency property, but is usually TwoWay. The default binding mode in Silverlight 2 is OneWay. 
&lt;LI&gt;Silverlight does not support Explicit DataBinding. It does however support the key approaches of LostFocus and PropertyChanged. 
&lt;LI&gt;Silverlight 2 does not support MultiBinding. 
&lt;LI&gt;Silverlight 2 does not support Element Binding (e.g. Binding a Slider value directly to a property on another element). 
&lt;LI&gt;Silverlight 2 does not support the ObjectDataProvider. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;DependencyProperties&lt;/U&gt;&lt;BR&gt;Silverlight 2 does not support Read Only DependencyProperties. &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Deployment Options&lt;/U&gt;&lt;BR&gt;A Silverlight application is deployed to a web server and hosted in a web browser. (The next version of Silverlight should also include the ability to view the application offline). WPF applications may be deployed as a standard installed application or via Click Once. WPF also offers a browser hosted version - the XAML Browser Application (XBAP). In view of the limitations of XBAPs it is likely that most developers would now choose Silverlight over WPF for browser hosted applications. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;DrawingBrush&lt;/U&gt;&lt;BR&gt;The WPF DrawingBrush is not supported in Silverlight 2. However, there is little that this brush does that can't be achieved with other approaches. The key loss would be the ability to tile, but there are workarounds for this.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Effects&lt;/U&gt;&lt;BR&gt;Effects (as opposed to BitmapEffects, which are no longer recommended for use) are only available in WPF. The next version of Silverlight should have the ability to create Pixel Shaders, and therefore Effects. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;File Access&lt;/U&gt;&lt;BR&gt;WPF has full access to local files in the same way as other .NET desktop applications. Silverlight runs in a Low Trust environment, so Users have restricted access to local files. Access to files in Silverlight is only available by means of the OpenFileDialog and even then is effectively only Read Only access. In Silverlight 2, saving data to file can only be achieved by using Isolated Storage. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;Hardware Acceleration&lt;/U&gt;&lt;BR&gt;By default, WPF hands off much of the heavy duty graphics work to the GPU, assuming that the graphics card meets the minimum specification. Silverlight uses software rendering.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Hyperlinks&lt;/U&gt;&lt;BR&gt;In WPF you can create a Hyperlink by using the Hyperlink element. Generally you use these in Page based applications and FlowDocuments. Silverlight uses the HyperlinkButton. &lt;BR&gt;Both elements use the NavigateUri property to assign the address of the link. The Silverlight version seems to be more versatile. Although it is called 'button', it doesn't have the standard rectangular button appearance. In fact, if you drag one from the Toolbox, you will see its markup in the XAML pane, but nothing shows in the Design pane.&lt;BR&gt;The intention is that you use the HyperlinkButton as a canvas (with a small 'c', not a Canvas element). You then add Content to the button and this is what creates the interface that the user sees. The Content can be anything from a simple single element to a more complex interface - such as a StackPanel which contains multiple elements: 
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HyperlinkButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; NavigateUri&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://www.devcity.net"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="60"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="15"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Left"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Top"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HyperlinkButton.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Image&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ShelfUnit_WithCans.png"&amp;gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Image&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; Click Me! &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HyperlinkButton.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HyperlinkButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFandSLDiffs1.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Isolated Storage&lt;/U&gt;&lt;BR&gt;There are significant differences between the implementation of local isolated storage in Silverlight 2 and WPF. Silverlight 2 restricts the availability of disk space. The default setting is 1 MB. This may be increased with explicit user authorization.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Key Enumeration&lt;/U&gt;&lt;BR&gt;WPF contains more precise Keyboard Key definitions in its Key enumeration. For example, it &lt;/P&gt;
&lt;P&gt;&lt;U&gt;KeyEventArgs&lt;/U&gt;&lt;BR&gt;WPF implements several properties in KeyEventArgs; Silverlight implements two - Key and PlatformKeyCode. &lt;BR&gt;WPF does not implement PlatformKeyCode. This is used in Silverlight to identify non-Windows keys. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;Markup Extensions&lt;/U&gt;&lt;BR&gt;Silverlight only supports a small sub-set of markup extensions. They are: 
&lt;UL&gt;
&lt;LI&gt;Binding 
&lt;LI&gt;StaticResource 
&lt;LI&gt;TemplateBinding 
&lt;LI&gt;x:Null &lt;/LI&gt;&lt;/UL&gt;It is not possible to create your own markup extensions in Silverlight. 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Mouse Events&lt;/U&gt;&lt;BR&gt;Silverlight supports a limited set of Mouse events: 
&lt;UL&gt;
&lt;LI&gt;LostMouseCapture 
&lt;LI&gt;MouseEnter 
&lt;LI&gt;MouseLeave 
&lt;LI&gt;MouseLeftButtonDown 
&lt;LI&gt;MouseLeftButtonUp 
&lt;LI&gt;MouseMove &lt;/LI&gt;&lt;/UL&gt;This means that Silverlight doesn't support mouse wheel, left/right mouse button differentiation or any of the PreviewXX mouse events that are available in WPF. 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Network&lt;/U&gt;&lt;BR&gt;Silverlight 2 is limited to asynchronous network calls. &lt;BR&gt;Silverlight 2 can communicate to Network Resources via Sockets. &lt;BR&gt;Silverlight 2 supports only SOAP 1.1 over HTTP, and does not support other web services not compliant with WS-I Basic Profile 1.0. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;Path Based Animations&lt;/U&gt; &lt;BR&gt;This feature is not available in Silverlight 2. Linear interpolated and KeyFrame animations are available.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Printing&lt;/U&gt;&lt;BR&gt;No PrintDialog or Printing facility in Silverlight 2.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Resources&lt;/U&gt;&lt;BR&gt;Silverlight 2 does not support MergedDictionaries.&lt;BR&gt;Silverlight 2 does not include the FindResource method. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;RoutedEvents&lt;/U&gt;&lt;BR&gt;Silverlight 2 only supports Bubbling and Direct Routed Events. WPF also supports Tunneling Events.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Security&lt;/U&gt;&lt;BR&gt;WPF desktop applications require FullTrust permission in order to run. XBAPs run with partial trust. Silverlight 2 applications run in low trust.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Styles &lt;/U&gt;&lt;BR&gt;WPF offers the choice of Named Styles and Typed Styles. Named Styles allow you to set the Style on an element by using its Key. Typed Styles do not have a Key and all elements of the TargetType within scope of the Style will be assigned the Style. &lt;BR&gt;Silverlight doesn't recognize Typed Styles and if they are used, the assignment of the Style will fail silently. &lt;BR&gt;Silverlight doesn't allow the use of the 'BasedOn' feature to inherit from Styles.&lt;BR&gt;When setting the TargetType, Silverlight does not use the markup extension. You simply assign the name of the TargetType in double quotes. If you forget, and force of habit makes you add the curly braces and markup extension in Silverlight, you won't get a design time error, but it will fail at run time.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;3D Graphics&lt;/U&gt;&lt;BR&gt;Silverlight doesn't have the full range of 3D creation tools that are available in WPF.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Tiled Brushes&lt;/U&gt;&lt;BR&gt;Silverlight 2 doesn't support the TileMode in ImageBrush.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Transitions&lt;/U&gt; &lt;BR&gt;Silverlight will not accept Triggers and uses the Visual State Manager (VSM) to organize animations and transitions for user interaction. VSM's capabilities currently are limited to the equivalent of standard Style Triggers and EventTriggers. There are no features equivalent to DataTriggers or MultiTriggers in Silverlight. &lt;BR&gt;VSM for WPF will be available soon. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;Validation&lt;/U&gt;&lt;BR&gt;WPF supports the creation of ValidationRules. This feature is not available in Silverlight 2.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Visual Brush&lt;/U&gt;&lt;BR&gt;Silverlight2 doesn't support WPF's Visual Brush. As this is a brush of very limited use, it's not likely to be much of a problem.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Visual State Manager (VSM)&lt;/U&gt;&lt;BR&gt;Currently this is a Silverlight only feature. It will be introduced into WPF in the future.&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;U&gt;Visual Studio Designer&lt;/U&gt;&lt;BR&gt;Visual Studio 2008 has the facility for you to drag and drop, reposition, resize, etc, elements in the Design pane with WPF. For Silverlight it seems to offer editing tools only in the XAML pane. The Design pane is a kind of 'Read Only' version of what is created in the markup. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;VisualTreeHelper&lt;/U&gt;&lt;BR&gt;This class exists in both WPF and Silverlight 2, but because of differences in the underlying base classes of the two platforms they have different implementations. The key difference is that WPF offers the HitTest method, whereas Silverlight2 uses FindElementsInHostCoordinates.&lt;BR&gt;With the exception of GetChild, GetParent and GetChildrenCount, Silverlight2 doesn't support any of the GetXXX methods found in WPF.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Watermarked TextBox&lt;/U&gt;&lt;BR&gt;This is a Silverlight only control. The name says it all - basically a TextBox that allows you to include light shaded text to help the user. If memory serves, this was in Kevin's famous Bag o'Tricks. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Note:&lt;/B&gt;&amp;nbsp;Most of the differences described above are also included in an excellent White paper comparison document published by Wintellect. You can download a copy from &lt;A href="http://wpfslguidance.codeplex.com/"&gt;here&lt;/A&gt;. &lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9334.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>First Steps in Silverlight 2 and Expression Blend 2</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/14/9329.aspx</link><pubDate>Sun, 14 Jun 2009 08:50:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/06/14/9329.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9329.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9329.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/06/14/9329.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9329.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;As a Developer, Visual Studio is my comfort zone but I thought the time had come to see what the experience of creating a Silverlight 2 project in Expression Blend would be like. Having spent the past six months working almost exclusively on Windows Presentation Foundation, I was particularly interested to find out how different the WPF and Silverlight experience would be. &lt;BR&gt;&lt;BR&gt;The first thing I had to do was update my copy of Expression Blend 2. Out of the box, your only Silverlight option is a Silverlight 1 site. But if you go to &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyId=EB9B5C48-BA2B-4C39-A1C3-135C60BBBE66&amp;amp;displaylang=en"&gt;the download site here&lt;/A&gt; you can download the latest Service Pack. This incorporates the changes that were available in the Blend 2.5 Beta, the main one being that you can build a Silverlight 2 Application.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Probably the biggest difference between the two versions of Silverlight is that Silverlight 2 gives you the option of using C# or Visual Basic as the code-behind. If, like me, you're not a Javascript expert, but have served your time on the .NET learning curve, this is a really welcome option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;If you have used WPF, you will know that by default when you create a new WPF Application you are presented with a Window instance containing a Grid as the root element on which to start creating your UI. In Silverlight 2, the default is a user control, again containing a Grid as the root element. As Silverlight is a browser plug in*, rather than the desktop application of WPF, this approach makes sense. However, I have to doubt the wisdom of this User Control being named "Page.xaml" by default, as this might cause confusion to those of us who have also created Pages in WPF Applications and think of Pages as being, well, er, pages!. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;To add some elements to the User Control, you simply drag them from the Asset Library on to the design surface. I added a TextBlock, an Image and a Button. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/SilverlightBlend1.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;If you are not familiar with Expression Blend, the Asset Library - where you drag your elements from - is the last icon on the left, which I have circled in Red. I added the png file which is used as the Source property of the Image to the project files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;A Button that does nothing when clicked won't impress anyone, so my next task was to fix this. My inclination was to switch straight away to Visual Studio, but I thought I would see what Blend had to offer in the way of event handler creation. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;The Properties Pane in Blend has a button which causes the Properties to be listed (the default choice) and next to that there is a button for events. You can see this in the screenshot below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/SilverlightBlend2.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Expression Blend is essentially a tool for creating visual user interfaces. So, unsurprisingly, all you get when you choose that Events pane button is a list of common events for the particular element or control. What is quite impressive though is that if you type in the proposed name for the event handler (as I have done in the example below) and then hit the Enter key, not only does this cause Visual Studio to fire up, but when you look at the code-behind page you will see that a handler of the name you input will be created and it will have the correct signature. You can then simply insert whatever code for what you want to happen as a result of the button click. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/SilverlightBlend3.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;One thing I was keen to try out was Silverlight's Visual State Manager, about which I had heard much, but understood nothing. As it seems certain that WPF will have VSM soon, I wondered how much easier (or not) VSM would be compared to the current WPF Storyboard and Triggers approach. &lt;BR&gt;&lt;BR&gt;I experimented by adding a simple animation to a button, transforming its size when the mouse entered its area. (I will be writing a full article on Visual State Manager soon, which will include VSM for controls which have CommonStates built in for you in Blend - such as the Button - as well as VSM for those that don't, such as Images.) &lt;/P&gt;
&lt;P&gt;&amp;nbsp;The steps for the Button are as follows: 
&lt;OL&gt;
&lt;LI&gt;Drag a Button from the Asset Library on to the drawing surface (Note to self: Must get used to calling this the 'Artboard'). 
&lt;LI&gt;Right click on the button and choose 'Edit Control Parts (Template)'. 
&lt;LI&gt;Select 'Edit a Copy'. 
&lt;LI&gt;Rename the Key if you want to. 
&lt;LI&gt;Click OK. &lt;/LI&gt;&lt;/OL&gt;If you now look at the States Pane :- &lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/SilverlightBlend4.png"&gt; &lt;BR&gt;&lt;BR&gt;you will see that a standard set of States for a Button object are displayed for you. These are the four main CommonStates 
&lt;UL&gt;
&lt;LI&gt;Normal 
&lt;LI&gt;MouseOver 
&lt;LI&gt;Pressed 
&lt;LI&gt;Disabled &lt;/LI&gt;&lt;/UL&gt;and two FocusStates: 
&lt;UL&gt;
&lt;LI&gt;Focused 
&lt;LI&gt;Unfocused &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;If you want the visual state to change when the Button is pressed, you add a Transition to the Pressed State in that pane. This is done by clicking on the small 'Arrow and plus symbol' icon to the right of the word 'Pressed' in the States Pane. When you left click on this icon you will see a context menu which shows combinations of state changes. Select the first one - '*&amp;gt;Pressed'. The area round the Artboard should now have a red border and the "State recording is on" message appears at the top left corner. (If for any reason it is not on, simply click the mouse over the dot to the left of the "State recording is off" message.) &lt;/P&gt;
&lt;P&gt;&amp;nbsp; As my initial experiment, I wanted to reduce the width and height of the Button by 15% when it is pressed. Here are the steps: 
&lt;OL&gt;
&lt;LI&gt;Select the part of the Button that you want to animate. 
&lt;LI&gt;Go to the Properties pane. 
&lt;LI&gt;Scroll down until you reach the 'Transform' section. 
&lt;LI&gt;Select the Scale transform icon (the arrow coming out of a rectangle). 
&lt;LI&gt;Change the value of X to 0.85. 
&lt;LI&gt;Change the value of Y to 0.85. 
&lt;LI&gt;Press F5 to test the project. 
&lt;LI&gt;Click on the button to ensure that the animation works. 
&lt;LI&gt;Close the Browser. 
&lt;LI&gt;In the Objects and Timeline pane in Blend, click on the 'Return Scope to [UserControl]' icon at the right hand side of the Style name. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I had quite a lot of trouble with this. I found that if I clicked on the button on the Artboard and made the transformations (or any other animations, for that matter), I was not getting the results I expected. I eventually worked out that the trick is to select the exact element you want to animate from the Objects and Timeline pane. In the case of the button transformation, the item to select is the parent grid. In some cases, you may need to expand the dropdown list to get to the exact item you need and you may have to experiment some before you get it right. I think this kind of problem is only likely to occur where you stick with the standard template; clearly, if you build up your own set of elements on the Artboard to make a styled button of your own, you will be more familiar with exactly which part(s) you want to animate. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;Another little thing to watch out for which might confuse at first, is that the States pane seems to 'remember' the last set of States you dealt with. If you then select a different object, (for example, the TextBlock in my initial user Control) and the States haven't been changed or set for &lt;I&gt;this&lt;/I&gt; object, you will still see the States from the preceding object in the pane. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;Because I was familiar with the Triggers and Storyboard approach, I did want to see if this was still available as an option in Blend. It doesn't seem to be, but of course I can always do this in XAML in Visual Studio, using an EventTrigger. However, I can see that the Visual State Manager is going to be an easy beast to tame, so I don't think I'll need to revert to the old way very often. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;So at this stage, my first impression is that I will be content to use Blend for complex graphics and animations, gradients and visual states. For most other things, I think I will still be using Visual Studio whenever possible. &lt;/P&gt;
&lt;HR&gt;
&lt;BR&gt;&lt;BR&gt;
&lt;P&gt;&amp;nbsp;* At least it is a browser plug in for the time being. Silverlight 3, which is coming up fast, is going to offer an out-of-browser experience. That is, you will be able to include code that will let the user access the Silverlight User Control when offline. My first thought was "Isn't that what WPF does?", but then realized that Silverlight is cross-browser, cross-platform whereas WPF is not. It will be interesting to see where this leads in the long term.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9329.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Copying An Item Between ListViews</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/09/9319.aspx</link><pubDate>Tue, 09 Jun 2009 08:44:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/06/09/9319.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9319.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9319.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/06/09/9319.aspx#comment</comments><slash:comments>2</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9319.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: x-small; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I've always found ListViews quite fascinating. Slightly confusing sometimes, but fascinating nevertheless. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; As I have often been heard to say,&amp;nbsp;it's the little Gotchas that'll get ya.&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;Take, for instance, the subject of this blog - copying an item between ListViews. The scenario is that you let the user click on an item in ListView1 and if they want this item copied to ListView2, they hit a button. &lt;BR&gt;&lt;BR&gt;Now, you would probably think that all you need to do is identify the currently selected item and add it straight to the second ListView. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;ListView2.Items.Add(ListView1.SelectedItems(0))&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;But if you do try this, you will get an error. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG height=249 src="http://www.xtabvbcity.plus.com/Blogs/ListViewItemCopy1.jpg" width=453&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The text of the error message pretty much says it all. What you have to do (assuming that you aren't prepared to remove the item from the original ListView) is to clone it. You will then be allowed to add the clone to the second ListView.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Although the cloning isn't difficult, you do have to be aware of the need to cast the selected item to ListViewItem if you have Option Strict On. To be honest, I found this a bit strange at first. If I lift a ListViewItem from a ListView, I didn't expect to have to cast it to what it is - i.e a ListViewItem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I'm not entirely sure why this occurs and wonder if the underlying reason for this is that the ListViewItem is stored in the SelectedItems collection of the ListView as a generic object. Anyway, Casting it back to a ListViewItem at the point where the cloning takes place, fixes this&amp;nbsp;without any problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;This code works well:&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt; ListView1.SelectedItems.Count &amp;gt; 0&lt;SPAN style="COLOR: #0000ff"&gt; Then&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; lvi&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; ListViewItem&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lvi = ListView1.SelectedItems(0)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; lvi2&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; ListViewItem&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lvi2 =&lt;SPAN style="COLOR: #0000ff"&gt; CType&lt;/SPAN&gt;(lvi.Clone, ListViewItem)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ListView2.Items.Add(lvi2)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; If&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;You'll have noticed that I built in a test to ensure that an item is currently selected. It's an easy thing to forget and is sure to bring your app to a grinding halt before long if you don't build this in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;You can see where I have cast the selected item (aka lvi) to ListViewItem in Line 5. Intriguingly, casting to ListViewItem in the third line of code, e.g. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;lvi =&lt;SPAN style="COLOR: #0000ff"&gt; CType&lt;/SPAN&gt;(ListView1.SelectedItems(0), ListViewItem)&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;doesn't cut it. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9319.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Removing Double Quotes from a Text File</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/09/9318.aspx</link><pubDate>Tue, 09 Jun 2009 08:35:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/06/09/9318.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9318.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9318.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/06/09/9318.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9318.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: x-small; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Sometimes you don't have control over how the data is saved to a text file. For instance, some items might be saved with quotation marks around words or phrases. If you want to read the file but not show these marks then you'll need a way to remove them. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Like a lot of things, it's actually very easy when you know how. You can use the built-in Replace function of the String class, replacing the marks as you find them. The trick though (and to my mind, the less than totally intuitive bit) is knowing how many quotation marks to use in the first argument of the Replace method's parameters. This is the 'OldChar' parameter, i.e the one you want to replace. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;You would think, wouldn't you, that you could put a Quotation Mark inside a pair of Quotation Marks like this:-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: #aaaaaa 1px solid; BORDER-TOP: #aaaaaa 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #aaaaaa 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Lucida Console'; BACKGROUND-COLOR: #dbdbdb"&gt;MyString.Replace(&lt;SPAN style="COLOR: #a31515"&gt;"""&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #a31515"&gt; ""&lt;/SPAN&gt;)&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;But if you try that, you will find that it doesn't work. What you actually have to do is include a second Quotation Mark inside the outside ones. In other words, you need four Quotation Marks in a row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: #aaaaaa 1px solid; BORDER-TOP: #aaaaaa 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #aaaaaa 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Lucida Console'; BACKGROUND-COLOR: #dbdbdb"&gt;MyString.Replace(&lt;SPAN style="COLOR: #a31515"&gt;""""&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #a31515"&gt; ""&lt;/SPAN&gt;)&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;It's only a tiny change, but it will move your mental state from annoyed confusion to enlightened contentment. Or something like that, anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;So putting this together with code that reads from a file and displays the result (minus Quotation Marks) in a ListBox, you have:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: #aaaaaa 1px solid; BORDER-TOP: #aaaaaa 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #aaaaaa 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Lucida Console'; BACKGROUND-COLOR: #dbdbdb"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; Sub&lt;/SPAN&gt; RemoveQuotes(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; filename&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #0000ff"&gt; ByVal&lt;/SPAN&gt; target&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt; ListBox)&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;A StreamReader to fetch the data&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; sr&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; IO.StreamReader(filename)&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;A string to hold each line as it is read&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; line&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt; =&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt;.Empty&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Read from the file&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' As long as there is something left to read&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Do&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; While&lt;/SPAN&gt; sr.Peek &amp;lt;&amp;gt; -1&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Replace the Quotation Marks with Nothing&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line = sr.ReadLine.Replace(&lt;SPAN style="COLOR: #a31515"&gt;""""&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #a31515"&gt; ""&lt;/SPAN&gt;)&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Add edited text to a ListBox&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;target.Items.Add(line)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Loop&lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;Tidy up when finished&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr.Close()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr =&lt;SPAN style="COLOR: #0000ff"&gt; Nothing&lt;BR&gt;End&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; Sub&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;If you prefer your code to be broken down into clearer steps, you could do this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: #aaaaaa 1px solid; BORDER-TOP: #aaaaaa 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #aaaaaa 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Lucida Console'; BACKGROUND-COLOR: #dbdbdb"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; Sub&lt;/SPAN&gt; RemoveQuotes(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; filename&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #0000ff"&gt; ByVal&lt;/SPAN&gt; target&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt; ListBox)&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;A StreamReader to fetch the data&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; sr&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; IO.StreamReader(filename)&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;A string to hold each line as it is read&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; line&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt; =&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt;.Empty&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Read from the file&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' As long as there is something left to read&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Do&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; While&lt;/SPAN&gt; sr.Peek &amp;lt;&amp;gt; -1&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;Read the next line&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line = sr.ReadLine&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Replace the Quotation Marks with Nothing&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line = line.Replace(&lt;SPAN style="COLOR: #a31515"&gt;""""&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #a31515"&gt; ""&lt;/SPAN&gt;)&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Add edited text to a ListBox&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;target.Items.Add(line)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Loop&lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;Tidy up when finished&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr.Close()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr =&lt;SPAN style="COLOR: #0000ff"&gt; Nothing&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; Sub&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Either way, your quotation marks will be history.&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9318.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Colors and Brushes in WPF</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/09/9317.aspx</link><pubDate>Tue, 09 Jun 2009 08:33:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/06/09/9317.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9317.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9317.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/06/09/9317.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9317.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: x-small; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;
&lt;P&gt;&amp;nbsp; One of the things that first caught me out in WPF was the simple topic of colors. For example, let's say you want to reset the BackColor of a Form in Windows Forms. &lt;BR&gt;&lt;BR&gt;Easy enough. This will do the job:&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;.BackColor = Color.CadetBlue&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;When it comes to WPF, you'll know that we are dealing with a Window, instead of a Form and have probably already picked up that &lt;B&gt;BackColor&lt;/B&gt; is now &lt;B&gt;Background&lt;/B&gt;. &amp;nbsp;You can however, still use "Me" to reference the Window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;But if you were to try something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;.Background = Color.CadetBlue&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' or even&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;.Background = Colors.CadetBlue&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;you would be disappointed. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;You would however get some help from Intellisense (at least with the second version). The error message tells you that a Color cannot be converted to a Brush. And there's the answer to the problem. &lt;BR&gt;&lt;BR&gt;The Background property doesn't take a Color - it takes a Brush, which of course can, and usually does, have a color assigned to it. Don't forget though that you are not limited to a single solid color; there are many gradient, tile and image based options that you can choose when it comes to brushes in WPF. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;So this code will work fine in WPF:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;Me&lt;/SPAN&gt;.Background =&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; SolidColorBrush((Colors.CadetBlue))&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;Ah yes, I hear you say, but what about the theory that you should use XAML for the look and code-behind for the behaviour? Well, I can't disagree with you there and personally I would use:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Window1"&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;   &lt;SPAN style="COLOR: #ff0000"&gt; xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;   &lt;SPAN style="COLOR: #ff0000"&gt; xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;   &lt;SPAN style="COLOR: #ff0000"&gt; Title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Window1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="300"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="300"&lt;/SPAN&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CadetBlue"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;where the Background property for the Window is set there in the XAML. However, there may well be times when you want the user to have a say in color choices and in those cases it can be easier to take the user's input and deal with it in the code-behind. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; For example, if the user was empowered to enter values for the ARGB components then you might use an approach like the following: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; col&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; System.Windows.Media.Color&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;In reality the values below could be&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' selected by the user and passed in&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;col = Color.FromArgb(214, 122, 52, 24)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; br&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; SolidColorBrush(col)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Me&lt;/SPAN&gt;.Background = br&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; It would also be quite easy to create a display in WPF where you bind, for example, sliders to the Brush that is used for the background. But I won't go any deeper into that just now, as this sub-set of blog items is meant only to help identify those missing WinForms favorites and repatriate them as WPF troops. &lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9317.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Restricting TextBox Input</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/09/9316.aspx</link><pubDate>Tue, 09 Jun 2009 08:28:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/06/09/9316.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9316.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9316.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/06/09/9316.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9316.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;This is a question that seems to come up a lot in the forums:- How can I restrict the TextBox input to numerals, or only a single occurrence of a decimal point, or some other restriction?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;As ever, there are several approaches. If the restriction is something basic, such as numerals only then the easy approach is to use the KeyPress event. What you can do is stop the character from appearing in the TextBox, test to see if it is allowable and, if it is, then allow it to continue. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;B&gt;Letters Only&lt;/B&gt;&lt;/U&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; To take an example which only allows letters of the alphabet, it would look like this:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox1_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox1.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &lt;SPAN style="COLOR: blue"&gt;Like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"[A-z]"&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;In this snippet, it is the e.Handled = True which blocks the input temporarily. The next line assesses whether the key press is a letter of the alphabet*, either lower or upper case, and if it is then the handled setting is reversed. This allows the key press to be passed to the TextBox display. If it fails the test, the block on this key press remains. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; * Depending on your locale and keyboard, some other keys are allowed. These include symbols that are used in combination with characters in some languages, such as accents. In most cases this is the behaviour you will want.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Specific Keys&lt;/U&gt;&lt;/B&gt; &lt;BR&gt;Sometimes you may want to allow certain keys. A common situation is where you will let the user use the Backspace to correct an error when inputting: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox2_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox2.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &lt;SPAN style="COLOR: blue"&gt;Like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"[A-z]"&lt;/SPAN&gt; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; e.KeyChar = Chr(&amp;amp;H8) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;In this case, it is the Chr(&amp;amp;H8) which identifies and allows the Backspace.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Numbers Only&lt;/U&gt;&lt;/B&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;Another common requirement is to restrict input to numerals. Of the several possible approaches, using IsNumeric is one of the most straightforward:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox3_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox3.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; IsNumeric(e.KeyChar) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Sometimes that is too restrictive though. What happens if you want to allow the user to enter decimal points or (depending on their locale) commas to break up large numbers? Allowing these individual characters is simple, but there is another potential catch as we will see in a moment:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox4_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox4.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; IsNumeric(e.KeyChar) _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; e.KeyChar = &lt;SPAN style="COLOR: #a31515"&gt;"."&lt;/SPAN&gt; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; e.KeyChar = &lt;SPAN style="COLOR: #a31515"&gt;","&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Only One Decimal Point&lt;/U&gt;&lt;/B&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;In most cases where users are inputting numeric values you will want to restrict them to a single decimal point. The code above will allow multiple entries. Again, there are several solutions, but the following one will usually do the job:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox5_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox5.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &amp;lt;&amp;gt; &lt;SPAN style="COLOR: #a31515"&gt;"."&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; IsNumeric(e.KeyChar) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt; &lt;SPAN style="COLOR: green"&gt;' &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;ElseIf&lt;/SPAN&gt; TextBox5.Text.Contains(&lt;SPAN style="COLOR: #a31515"&gt;"."&lt;/SPAN&gt;) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(&lt;SPAN style="COLOR: #a31515"&gt;"Only one decimal point allowed"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Command Keys&lt;/U&gt;&lt;/B&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; If you use any of the previous methods, you will be able to control the standard input keys. But there is another group of keys - Command keys - which won't be excluded by the use of the e.Handled approach. These include such keys as Home, End, Tab, and so on. You may risk alienating your users by excluding these, but there may be times when it is reasonable to do so, in which case you'll need to know how.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;A good way is to intercept the message at the window level and you can do this by overriding the ProcessCmdKey function. Here's how:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Create a new class which inherits from the basic TextBox. Override the ProcessCmdKey function and test for the currently pressed key in a similar way to that used in the earlier examples. If the key is one you want to suppress then you return True and the Windows message pump will ignore it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The following code will be all you need:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt; CustomTextBox&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Inherits&lt;/SPAN&gt; System.Windows.Forms.TextBox&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.BackColor = Color.Azure&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Overrides&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; ProcessCmdKey(&lt;SPAN style="COLOR: blue"&gt;ByRef&lt;/SPAN&gt; msg &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.Message, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; keyData &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.Keys) &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Boolean&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Declare a variable of type Keys enumeration &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' named keyPressed. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Cast the msg's WParam as a KeyEnum value &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' and assign it to the keyPressed variable. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; keyPressed &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; Keys = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(msg.WParam.ToInt32(), Keys)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Process the key that is pressed. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; If keyPressed = Keys.Home Or keyPressed = Keys.End Then Return True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; keyPressed = Keys.Tab &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Return the Command key message&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.ProcessCmdKey(msg, keyData)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The light blue back color is simply to make this sub-classed TextBox look slightly different from the default one for demo purposes, but of course is not a key part of the key checking functionality. As you can see, my example blocks the Tab key. You can add or replace other keys, such as Home and End. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Multiple Options&lt;/U&gt;&lt;/B&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;Handling the KeyPress is fine if you only have a few TextBoxes for which you are controlling input. If there are going to be a lot of them throughout your application, or if you have different input rules for several TextBoxes, then again it may be worth your while to create your own inherited version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The following example deals with some of the previous scenarios, but allows the input rule to be selected from an enumeration of choices. The choices used here remain basic, but of course you can expand this idea much further. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Here is the code:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt; RestrictedTextBox&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Inherits&lt;/SPAN&gt; System.Windows.Forms.TextBox&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Enum&lt;/SPAN&gt; RestrictionCategory&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; NoRestriction&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; NumeralsOnly&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; LettersOnly&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AlphanumericOnly&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Enum&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; _allowedKeys &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; RestrictionCategory&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Property&lt;/SPAN&gt; AllowedKeys() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; RestrictionCategory&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Get&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; _allowedKeys&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Get&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; Value &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; RestrictionCategory)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Select&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; Value&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; 1 &lt;SPAN style="COLOR: blue"&gt;To&lt;/SPAN&gt; 3 &lt;SPAN style="COLOR: green"&gt;' One of the enum choices &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _allowedKeys = Value&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt; &lt;SPAN style="COLOR: green"&gt;' No restriction&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _allowedKeys = 0&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Select&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Property&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Overrides&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; OnKeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; KeyPressEventArgs)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.OnKeyPress(e)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; Test whether key is allowed, based on the current choice&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; from the enum&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Select&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; _allowedKeys&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; 1 &lt;SPAN style="COLOR: green"&gt;'Numerals only &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; IsNumeric(e.KeyChar) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Exit&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; 2&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Letters Only&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &lt;SPAN style="COLOR: blue"&gt;Like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"[A-z]"&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Exit&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; 3&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Alphanumeric&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &lt;SPAN style="COLOR: blue"&gt;Like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"[A-z]"&lt;/SPAN&gt; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; IsNumeric(e.KeyChar) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Exit&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Select&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The key areas are the enumeration which is called RestrictionCategory. These are automatically assigned values from 0 to 3. The Property AllowedKeys and its backing Field carry out the standard roles of a Property, the user being able to set the AllowedKeys property in code. (You could improve this by having the property appear in the Properties Window). &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The core of this class is the overridden OnKeyPress method. This checks for the chosen enumeration and then either allows or applies the blocking filter to the currently pressed key. This works in a very similar way to the individual KeyPress approach used in the earlier examples. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;By default, all keys will be allowed and to set the enumeration of your choice, you simply include code similar to the following somewhere appropriate in your form (I've used the Form Load event for my example):&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Form1_Load(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Load&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.RestrictedTextBox1.AllowedKeys = RestrictedTextBox.RestrictionCategory.NumeralsOnly&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Summary&lt;/U&gt;&lt;/B&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;I think that a combination or extension of any of the above approaches will enable you to control exactly what you will allow the user to input into a TextBox. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9316.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Blog moved</title><link>http://blogs.vbcity.com/canoz/archive/2009/04/11/9291.aspx</link><pubDate>Sat, 11 Apr 2009 09:01:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/canoz/archive/2009/04/11/9291.aspx</guid><wfw:comment>http://blogs.vbcity.com/canoz/comments/9291.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/canoz/comments/commentRss/9291.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/canoz/archive/2009/04/11/9291.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/canoz/services/trackbacks/9291.aspx</trackback:ping><source url="http://blogs.vbcity.com/canoz/rss.aspx">CanOz Blog</source><description>&lt;P&gt;My blog has moved to it's new address.&lt;/P&gt;
&lt;P&gt;You can find my new blog &lt;A href="http://cs.vbcity.com/blogs/canoz/default.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/canoz/aggbug/9291.aspx" width = "1" height = "1" /&gt;</description><dc:creator>V. Neil Knobbe</dc:creator></item><item><title>AutoDragger: automatically enable start dragging for your controls</title><link>http://blogs.vbcity.com/hotdog/archive/2009/02/10/9273.aspx</link><pubDate>Wed, 11 Feb 2009 06:12:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/hotdog/archive/2009/02/10/9273.aspx</guid><wfw:comment>http://blogs.vbcity.com/hotdog/comments/9273.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/hotdog/comments/commentRss/9273.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/hotdog/archive/2009/02/10/9273.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/hotdog/services/trackbacks/9273.aspx</trackback:ping><source url="http://blogs.vbcity.com/hotdog/rss.aspx">HotDog's Blog</source><description>&lt;P&gt;Another 'old' bit of code that I'm still using a lot none the less. Whenever I needed drag and drop, it annoyed me that I had to use repetitive code to start it manually by tracing the mousedown etc. So what better place for repetitive code than in a reusable component. It isn't any highly fancy or complicated code, but a raincoat doesn't have to be pretty to keep you dry ;) &lt;BR&gt;Anyway, when&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;I was thinking when&amp;nbsp;extending the AutoDragger today to alter the behaviour when dragging from a datagridview, that it was never posted on this blog. So here it is. (As far as I know it hasn't been outdated in the sense that .net now supports this out of the box)&lt;/P&gt;
&lt;P&gt;Usage in Designer: drop the component on your form, select a control you wish to enable auto dragging for, locate the added 'UseAutoDrag' property on that control (under a 'Drag Drop' header) and set it to true.&lt;BR&gt;(Of course the component can be used as a runtime class too.) The cursor can be set in the drag events or by setting a default drag cursor on the component.&lt;/P&gt;

&lt;!-- --Start of code block
--&gt;&lt;DIV Style=" Border='1px #000080 solid'; Margin-Left=10pt; Margin-Right=2pt;" OnKeyDown="var k =event.keyCode,i=-1,ch=this.firstChild;if(k==32){i=ch.sel;if(++i==ch.selcount)i=0;}else i = k - 49;if(i&gt;=0 &amp;&amp; i&lt;ch.selcount){ch.sel=i;ch.click();}"&gt;&lt;DIV Style=" Font-Size=9pt; Font-Family='Microsoft Sans Serif'; Border-Bottom='1px #000080 solid';" OnClick="var i=this.sel,j,ch,count = this.selcount;if(i==this.selold)return;this.selold=i;for(j=0;j&lt;count;j++){ch=this.childNodes[2+j];ch.childNodes[0].checked=j==i;ch.style.fontWeight = j==i ? 'bolder' : 'normal';}ch=parentNode.childNodes[1];var sh=new Array('none','');j=i==0?0:1;ch.style.display=sh[j];ch.nextSibling.style.display=sh[1-j];var h =ch.offsetHeight;ch.style.height=i==1?'300pt':null;if(i==1&amp;&amp; ch.offsetHeight&gt;h)ch.style.height=h;" sel=1 selold=1 selcount=3&gt;&lt;b&gt;  Code &lt;/b&gt;&lt;a href="javascript:" Style=" Margin-Left=10pt; Margin-Right=10pt;" OnClick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;Copy&lt;/a&gt;&lt;SPAN Style=" Margin-Left=5pt; Margin-Right=5pt; Cursor='hand';" OnClick="parentNode.sel=0"&gt;&lt;Input Type="Radio" Style="" OnClick="this.blur();"&gt;Hide&lt;/SPAN&gt;&lt;SPAN Style=" Font-Weight=bolder; Margin-Left=5pt; Margin-Right=5pt; Cursor='hand';" OnClick="parentNode.sel=1"&gt;&lt;Input Type="Radio" Style="" OnClick="this.blur();" Checked=True&gt;Scroll&lt;/SPAN&gt;&lt;SPAN Style=" Margin-Left=5pt; Margin-Right=5pt; Cursor='hand';" OnClick="parentNode.sel=2"&gt;&lt;Input Type="Radio" Style="" OnClick="this.blur();"&gt;Full&lt;/SPAN&gt;&lt;!-- CodeBlock by R.Verpalen 2005 : http://blogs.vbcity.com/hotdog/archive/2005/12/30/5759.aspx--&gt;&lt;/DIV&gt;&lt;DIV Style=" BackGround-Color=#dcdcdc; overflow='auto'; Height=300pt;"&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;namespace&lt;/FONT&gt; Subro.Controls&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;using&lt;/FONT&gt; System;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.ComponentModel;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.Windows.Forms;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.Collections.Generic;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.Drawing;&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:20pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Generic component that can start dragging for most control by handling&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; its mouse events.&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Set the Controls property to indicate for which controls dragging should be handled&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; automatically. Catch the StartDrag event to alter the data which is to be dragged.&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DefaultEvent&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quotStartDrag&amp;quot&lt;/FONT&gt;)]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;ProvideProperty&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quotUseAutoDrag&amp;quot&lt;/FONT&gt;,&lt;FONT Color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt;))]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AutoDragger&lt;/FONT&gt; : &lt;FONT Color=#2b91af&gt;Component&lt;/FONT&gt;,&lt;FONT Color=#2b91af&gt;IExtenderProvider&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; AutoDragger()&lt;br&gt;{&lt;br&gt;}&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; AutoDragger(&lt;FONT Color=#2b91af&gt;IContainer&lt;/FONT&gt; c)&lt;div style="margin-left:20pt"&gt;: &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;()&lt;/div&gt;{&lt;div style="margin-left:20pt"&gt;c.Add(&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; AutoDragger(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; ctr)&lt;div style="margin-left:20pt"&gt;: &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;(ctr, &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;/div&gt;{&lt;br&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; AutoDragger(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; ctr, &lt;FONT Color=#2b91af&gt;EventHandler&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt;&amp;gt handler)&lt;div style="margin-left:20pt"&gt;: &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;()&lt;/div&gt;{&lt;div style="margin-left:20pt"&gt;Register(ctr);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (handler != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;StartDrag += handler;&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:40pt"&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt;&amp;gt controls = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt;&amp;gt();&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; Register(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; DragSource)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;int&lt;/FONT&gt; i = controls.IndexOf(DragSource);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (i != -1) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; i;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (!DesignMode)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;DragSource.MouseDown += &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;MouseEventHandler&lt;/FONT&gt;(Control_MouseDown);&lt;br&gt;DragSource.MouseMove += &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;MouseEventHandler&lt;/FONT&gt;(Control_MouseMove);&lt;br&gt;DragSource.MouseUp += &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;MouseEventHandler&lt;/FONT&gt;(Control_MouseUp);&lt;br&gt;DragSource.GiveFeedback += &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;GiveFeedbackEventHandler&lt;/FONT&gt;(Control_GiveFeedback);&lt;/div&gt;}&lt;br&gt;controls.Add(DragSource);&lt;br&gt;i = controls.Count - 1;&lt;br&gt;ControlAdded(DragSource);&lt;br&gt;OnControlsChanged();&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; i;&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; ControlAdded(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; c)&lt;br&gt;{&lt;br&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; UnRegister(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; DragSource)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;DragSource.MouseDown -= &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;MouseEventHandler&lt;/FONT&gt;(Control_MouseDown);&lt;br&gt;DragSource.MouseMove -= &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;MouseEventHandler&lt;/FONT&gt;(Control_MouseMove);&lt;br&gt;DragSource.MouseUp -= &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;MouseEventHandler&lt;/FONT&gt;(Control_MouseUp);&lt;br&gt;DragSource.GiveFeedback -= &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;GiveFeedbackEventHandler&lt;/FONT&gt;(Control_GiveFeedback);&lt;br&gt;controls.Remove(DragSource);&lt;br&gt;ControlRemoved(DragSource);&lt;br&gt;OnControlsChanged();&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; ControlRemoved(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; c)&lt;br&gt;{&lt;br&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; UnRegisterAll()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;int&lt;/FONT&gt; c = controls.Count -1;&lt;FONT Color=#0000ff&gt;&lt;br&gt;for&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; i&amp;nbsp&amp;nbsp= c;i&amp;gt=0 ;i--)&lt;div style="margin-left:20pt"&gt;UnRegister(controls[i]);&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;const&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Category = &lt;FONT Color=#a31515&gt;&amp;quotDragDrop&amp;quot&lt;/FONT&gt;;&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;[&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;Category&lt;/FONT&gt;(Category)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt;[] Controls&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; controls.ToArray();&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;suspendcontrolschanged = &lt;FONT Color=#0000ff&gt;true&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;while&lt;/FONT&gt; (controls.Count &amp;gt 0)&lt;div style="margin-left:20pt"&gt;UnRegister(controls[0]);&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt; != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; c &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Register(c);&lt;/div&gt;}&lt;/div&gt;suspendcontrolschanged = &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;br&gt;OnControlsChanged();&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;bool&lt;/FONT&gt; suspendcontrolschanged;&lt;FONT Color=#0000ff&gt;&lt;br&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; OnControlsChanged()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (!suspendcontrolschanged &amp;amp&amp;amp ControlsChanged != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) ControlsChanged(&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;, &lt;FONT Color=#2b91af&gt;EventArgs&lt;/FONT&gt;.Empty);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;event&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;EventHandler&lt;/FONT&gt; ControlsChanged;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; Index]&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; controls[Index];&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:40pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; The amount of registered controls used as a dragsource&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; DragSourceCount&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; controls.Count; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;event&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;EventHandler&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt;&amp;gt StartDrag;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;private&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DragDropEffects&lt;/FONT&gt; effects = &lt;FONT Color=#2b91af&gt;DragDropEffects&lt;/FONT&gt;.All;&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;DragDropEffects&lt;/FONT&gt;.All)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DragDropEffects&lt;/FONT&gt; Effects&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; effects; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt; { effects = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;override&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; Dispose(&lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; disposing)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;UnRegisterAll();&lt;FONT Color=#0000ff&gt;&lt;br&gt;base&lt;/FONT&gt;.Dispose(disposing);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;int&lt;/FONT&gt; diffmin = 2;&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(2)]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;Category&lt;/FONT&gt;(Category)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; DifferenceMinimum&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; diffmin; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;diffmin = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:40pt"&gt;AutoDragEventArgs&lt;/FONT&gt; curdrag;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;void&lt;/FONT&gt; Control_MouseDown(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; sender, &lt;FONT Color=#2b91af&gt;MouseEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (e.Button == &lt;FONT Color=#2b91af&gt;MouseButtons&lt;/FONT&gt;.Left)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;curdrag = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt;(sender &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt;, e.Location, &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;else&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;curdrag = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;void&lt;/FONT&gt; Control_MouseUp(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; sender, &lt;FONT Color=#2b91af&gt;MouseEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (curdrag != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;AutoDragEventArgs&lt;/FONT&gt; de = curdrag;&lt;br&gt;EndCurDrag();&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&lt;br&gt;OnDragEnded(de);&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp &lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; OnDragEnded(&lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;br&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;void&lt;/FONT&gt; Control_MouseMove(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; sender, &lt;FONT Color=#2b91af&gt;MouseEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (e.Button == &lt;FONT Color=#2b91af&gt;MouseButtons&lt;/FONT&gt;.Left &amp;amp&amp;amp curdrag != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;curdrag.CheckStartDrag(e);&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;void&lt;/FONT&gt; Control_GiveFeedback(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; sender, &lt;FONT Color=#2b91af&gt;GiveFeedbackEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;curdrag.SetFeedback(e);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;private&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Cursor&lt;/FONT&gt; cursor;&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Cursor&lt;/FONT&gt; DragCursor&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; cursor; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (cursor == &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt;;&lt;br&gt;cursor = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;br&gt;dragicon = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;bool&lt;/FONT&gt; ShouldSerializeDragCursor()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; cursor != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; &amp;amp&amp;amp dragicon == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;private&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Icon&lt;/FONT&gt; dragicon;&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Icon&lt;/FONT&gt; DragIcon&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; dragicon; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (dragicon == &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt; == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;DragCursor = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;else&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;DragCursor = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Cursor&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;.Handle);&lt;/div&gt;dragicon = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;private&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; alwaysshowcustomcursor;&lt;br&gt;[&lt;FONT Color=#2b91af&gt;Description&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quotOnly applies when the DragCursor property is set. If this value is false, the cursor is only shown when drop is allowed&amp;quot&lt;/FONT&gt;)]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; AlwaysShowCustomCuror&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; alwaysshowcustomcursor; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt; { alwaysshowcustomcursor = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;; }&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;void&lt;/FONT&gt; EndCurDrag()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (curdrag != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;curdrag.Dispose();&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt; : &lt;FONT Color=#2b91af&gt;EventArgs&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; Control;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Point&lt;/FONT&gt; StartPoint;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AutoDragger&lt;/FONT&gt; AutoDragger;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; AutoDragEventArgs(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; Control, &lt;FONT Color=#2b91af&gt;Point&lt;/FONT&gt; StartPoint, &lt;FONT Color=#2b91af&gt;AutoDragger&lt;/FONT&gt; Owner)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.Control = Control;&lt;FONT Color=#0000ff&gt;&lt;br&gt;this&lt;/FONT&gt;.StartPoint = StartPoint;&lt;FONT Color=#0000ff&gt;&lt;br&gt;this&lt;/FONT&gt;.AutoDragger = Owner;&lt;/div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;private&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; dragobj;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; DragObject&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; dragobj; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt; { dragobj = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;; }&lt;/div&gt;}&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;private&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; started;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; DragStarted&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; started; }&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; CheckStartDrag(&lt;FONT Color=#2b91af&gt;MouseEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;int&lt;/FONT&gt; diff = &lt;FONT Color=#2b91af&gt;Math&lt;/FONT&gt;.Abs(e.X - StartPoint.X)&lt;div style="margin-left:20pt"&gt;+ &lt;FONT Color=#2b91af&gt;Math&lt;/FONT&gt;.Abs(e.Y - StartPoint.Y);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (diff &amp;gt= AutoDragger.diffmin)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;started = &lt;FONT Color=#0000ff&gt;true&lt;/FONT&gt;;&lt;br&gt;Cursor = AutoDragger.DragCursor;&lt;br&gt;AutoDragger.OnStartDrag(&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;,e);&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; Dispose()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (AutoDragger.curdrag == &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;AutoDragger.curdrag = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;private&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Cursor&lt;/FONT&gt; cursor;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Cursor&lt;/FONT&gt; Cursor&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; cursor; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;cursor = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; SetFeedback(&lt;FONT Color=#2b91af&gt;GiveFeedbackEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (cursor != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (e.Effect != &lt;FONT Color=#2b91af&gt;DragDropEffects&lt;/FONT&gt;.None || AutoDragger.alwaysshowcustomcursor)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;e.UseDefaultCursors = &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;FONT Color=#2b91af&gt;&lt;br&gt;Cursor&lt;/FONT&gt;.Current = cursor;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; GetDragObject()&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;Control&lt;/FONT&gt; c = Control;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (c &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ListControl&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; (c &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ListControl&lt;/FONT&gt;).SelectedValue;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (c &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;TextBoxBase&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetDragObject(c &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;TextBoxBase&lt;/FONT&gt;);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (c &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Label&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; c.Text;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (c &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;TreeView&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetDragObject(c &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;TreeView&lt;/FONT&gt;);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (c &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DataGridView&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetDragObject(c &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DataGridView&lt;/FONT&gt;);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;object&lt;/FONT&gt; GetDragObject(&lt;FONT Color=#2b91af&gt;TextBoxBase&lt;/FONT&gt; tb)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (!tb.ReadOnly)&lt;br&gt;{&lt;FONT Color=#008000&gt;&lt;div style="margin-left:20pt"&gt;//when in edit mode and selecting text, don't start dragging&lt;/FONT&gt;&lt;FONT Color=#008000&gt;&lt;br&gt;//TODO: make optional&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp &lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (tb.SelectionLength == 0)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; tb.Text;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;return&lt;/FONT&gt; tb.SelectedText;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;object&lt;/FONT&gt; GetDragObject(&lt;FONT Color=#2b91af&gt;TreeView&lt;/FONT&gt; t)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;TreeNode&lt;/FONT&gt; node = t.GetNodeAt(StartPoint);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (node == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;br&gt;t.SelectedNode = node;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; node;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;object&lt;/FONT&gt; GetDragObject(&lt;FONT Color=#2b91af&gt;DataGridView&lt;/FONT&gt; dg)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;DataGridView&lt;/FONT&gt;.&lt;FONT Color=#2b91af&gt;HitTestInfo&lt;/FONT&gt; ht = dg.HitTest(StartPoint.X, StartPoint.Y);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (ht.RowIndex == -1) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (ht.ColumnIndex &amp;gt -1 &amp;amp&amp;amp !dg.Columns[ht.ColumnIndex].ReadOnly &amp;amp&amp;amp dg[ht.ColumnIndex, ht.RowIndex].IsInEditMode)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;; &lt;FONT Color=#008000&gt;//when on a cell in edit mode, don't start drag drop&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (ht.ColumnIndex == -1 || dg.SelectionMode == &lt;FONT Color=#2b91af&gt;DataGridViewSelectionMode&lt;/FONT&gt;.FullRowSelect || AutoDragger.AlwaysDragFullRow)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;DataGridViewRow&lt;/FONT&gt; row = dg.Rows[ht.RowIndex];&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (row.DataBoundItem != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; row.DataBoundItem;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; row;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; dg[ht.ColumnIndex, ht.RowIndex].Value;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;[&lt;FONT Color=#2b91af&gt;Browsable&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt; LastDragInfo&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; curdrag;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; OnStartDrag(&lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt; e,&lt;FONT Color=#2b91af&gt;MouseEventArgs&lt;/FONT&gt; me)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (StartDrag != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;StartDrag(&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;, e);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (e.DragObject == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;e.DragObject = GetDragObject(e);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (e.DragObject != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;e.Control.DoDragDrop(e.DragObject, Effects);&lt;br&gt;OnDragStarted(e);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;else&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#008000&gt;&lt;div style="margin-left:20pt"&gt;//dragging not allowed&lt;/FONT&gt;&lt;br&gt;curdrag = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; OnDragStarted(&lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;br&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; GetDragObject(&lt;FONT Color=#2b91af&gt;AutoDragEventArgs&lt;/FONT&gt; e)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; e.GetDragObject();&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;&amp;nbsp&amp;nbsp&amp;nbsp&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;private&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; fullrow;&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;)]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;Description&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quotOnly applies when dragging on a datagridview.\r\nIf this value is not set, the full row only will be dragged if the selection mode of the grid is FullRowSelect or the rowheader is dragged and the cell value otherwise.&amp;quot&lt;/FONT&gt;)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; AlwaysDragFullRow&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; fullrow; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt; { fullrow = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;; }&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#region&lt;/FONT&gt; IExtenderProvider Members&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;bool&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IExtenderProvider&lt;/FONT&gt;.CanExtend(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; extendee)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; extendee &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;[&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;)]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;Category&lt;/FONT&gt;(Category)]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DesignerSerializationVisibility&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;DesignerSerializationVisibility&lt;/FONT&gt;.Hidden)] &lt;FONT Color=#008000&gt;//serialized in the control property&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; GetUseAutoDrag(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; c)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (controls.Count == 0) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; controls.Contains(c);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; SetUseAutoDrag(&lt;FONT Color=#2b91af&gt;Control&lt;/FONT&gt; c, &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; value)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (GetUseAutoDrag(c) == value) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (!value)&lt;div style="margin-left:20pt"&gt;UnRegister(c);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;else&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;Register(c);&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#endregion&lt;/FONT&gt;&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;}&lt;/DIV&gt;&lt;DIV Style=" Display='none'; BackGround-Color=#dcdcdc;" OnDblClick="var o = parentNode.firstChild;o.sel =1;o.click()"&gt;&lt;b&gt; . . .&lt;/b&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- 
End of code block----&gt;&lt;img src ="http://blogs.vbcity.com/hotdog/aggbug/9273.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Robert Verpalen</dc:creator></item><item><title>Blog moved</title><link>http://blogs.vbcity.com/sergeb/archive/2009/01/28/9268.aspx</link><pubDate>Wed, 28 Jan 2009 18:09:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/sergeb/archive/2009/01/28/9268.aspx</guid><wfw:comment>http://blogs.vbcity.com/sergeb/comments/9268.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/sergeb/comments/commentRss/9268.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/sergeb/archive/2009/01/28/9268.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/sergeb/services/trackbacks/9268.aspx</trackback:ping><source url="http://blogs.vbcity.com/sergeb/rss.aspx">Public Shared SergeB.Blog()</source><description>&lt;P&gt;We moved vbCity Blogs site to new platform and new location is &lt;A href="http://cs.vbcity.com/blogs"&gt;http://cs.vbcity.com/blogs&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;My new blog URL is &lt;A href="http://cs.vbcity.com/blogs/sergeb"&gt;http://cs.vbcity.com/blogs/sergeb&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;New feed is &lt;A href="http://cs.vbcity.com/blogs/sergeb/rss.aspx"&gt;http://cs.vbcity.com/blogs/sergeb/rss.aspx&lt;/A&gt; &amp;nbsp;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/sergeb/aggbug/9268.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Serge Baranovsky</dc:creator></item><item><title>Creating Video Demos With Camtasia Studio</title><link>http://blogs.vbcity.com/xtab/archive/2009/01/23/9262.aspx</link><pubDate>Fri, 23 Jan 2009 09:28:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/01/23/9262.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9262.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9262.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/01/23/9262.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9262.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana&gt;
&lt;P&gt;&amp;nbsp;&lt;FONT size=2&gt;&amp;nbsp;I've been meaning to blog about the tools I use regularly and find useful and I've managed to get a couple written this month. I'm always a bit concerned that blogs like this might end up looking like some kind of infomercial. But I eventually came to the conclusion that I've always thought that personal recommendation was the best kind of recommendation, so if I like a tool I should tell the world. Whether the world sets any store by my opinion is a matter for the world to decide!&lt;/FONT&gt; &lt;FONT face=Wingdings size=3&gt;J&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Camtasia1.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt; I have been using Camtasia Studio on and off for a couple of years now. When I first got hold of a copy, I needed it to create some demo videos. What I really liked about it was that, with no previous experience of screen recording, I was able to make the recording successfully after only a couple of tries. OK, so when I look back at that effort now, maybe "successfully" is an extravagant claim, but it was good enough for what I wanted to do at the time.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp; Although there are still some (many!) features that I haven't yet got round to using, it has still been a really useful tool for me. When I first got it, I was more interested in grabbing the screen action and recording some audio narration. More recently, I needed to improve the narration side and so was looking for a way to record the voice independently and (often) edit parts of it without having to re-record the whole thing for the umpteenth time.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/CamtasiaAudio.jpg"&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp; Camtasia Studio comes with a subset of handy little apps, one of which is their Audio Editor. This has been really useful, as it enabled me to make those voice recordings and edit them easily. I also found myself doing a lot of "Inserting Silence" to replace the intakes of breath and the occasional unwanted clunk when I'm waving my hands around and hit the boom mike.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;A href="http://www.techsmith.com/learn/camtasia/getting-started/"&gt;&lt;FONT size=2&gt;The tutorials&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=2&gt; are excellent and there is a lively set of &lt;/FONT&gt;&lt;A href="http://forums.techsmith.com/"&gt;&lt;FONT size=2&gt;User forums&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=2&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;A href="http://techsmith.custhelp.com/cgi-bin/techsmith.cfg/php/enduser/std_alp.php"&gt;&lt;FONT size=2&gt;FAQs&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=2&gt; are available to help you with those tricky things that should go right but somehow don't. &lt;BR&gt;&lt;BR&gt;The work area is as easy to use as you could reasonably hope for with an application that seems to have so many options. As you can see from the screenshot, the timeline allows for more than one audio track. &lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/CamtasiaWorkArea.jpg"&gt; &lt;BR&gt;&lt;BR&gt;Version 6 of Camtasia comes with even more presets to help you create the best screen size, resolution and (often important for web distribution or viewing) file size. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp; I'm currently working on creating some courses, all of which contain video demos. As I get more used to using it, I am of course finding that I can get from starting idea to finished production much quicker. When I've finished my current project, as a long term plan, I hope to be able to create a set of short videos to be made available for free here on VBCity.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp; All in all, I'm really pleased with it and many a time I've silently thanked the friend who first put me on to it. You can download a free 30 Day trial version from the TechSmith site &lt;/FONT&gt;&lt;A href="http://www.techsmith.com/download/trials.asp"&gt;&lt;FONT size=2&gt;here.&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9262.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>The Best WPF Developer Books </title><link>http://blogs.vbcity.com/xtab/archive/2009/01/18/9243.aspx</link><pubDate>Sun, 18 Jan 2009 12:10:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/01/18/9243.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9243.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9243.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/01/18/9243.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9243.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I now have several WPF books. I've written reviews on some of them and often mentioned them in answers to Forum questions from members who want to start out in WPF.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;When I wrote those articles and answers, my opinion was mostly based on my experience as a general reader who was interested in seeing what WPF had to offer and dabbling with it at a fairly elementary level. For the past three months though, I've been involved with WPF on a daily basis in a training capacity. During this time, it's become clear that I turn to some of the books much more regularly than others - and to some of them only when fairly desperate). &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;With the very clear understanding up front that this is my personal experience, opinion and preference - which may be completely different from anyone else's - here is my view on the various books.&lt;/P&gt;
&lt;P&gt;The book I first turn to is : &lt;BR&gt;Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5 &lt;BR&gt;by Matthew MacDonald. &lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFBooks/WPF_MMc_VB.jpg"&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Comprehensive, detailed, clearly written, understandable code snippets, and downloadable code samples that work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;It's almost impossible to fault this book. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;And of course, as the title says, the code behind samples are all in VB.NET - the only book I know of so far that is aimed specifically at VB developers. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;However, if you are a C# developer then that won't impress you much. For you, Apress and Matthew MacDonald have produced the equivalent C# title - Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.0. The key differences obviously being the absence of "VB.NET" in the title and the slightly earlier Framework. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I do have this version too and find it very useful when I want to try and understand the C# approach to a concept that I understand in VB.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The next book I reach out for is usually&lt;BR&gt;Windows Presentation Foundation Unleashed &lt;BR&gt;by Adam Nathan. &lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFBooks/NathanBook.jpg"&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The key value of this book is that it is packed with little hints, tips, Gotchas and information that will help you fight your way through the minefield that you encounter when first starting with WPF. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;One negative for me is that the code samples are in C#. There are however many useful XAML samples. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The book is in full color. This makes it slightly more attractive, but isn't a key issue for me. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Compared to most other WPF books, it appears to be relatively slim. In spite of this, I have still found it to be a gold mine of really useful WPF nuggets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Third in line is: &lt;BR&gt;Programming WPF &lt;BR&gt;by Chris Sells and Ian Griffiths. &lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFBooks//Sells.jpg"&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Another C# book, but again contains a lot of XAML. Ian Griffiths was one of the first writer/speaker/presenter/trainers on WPF in general and XAML in particular, so there are some useful insights to be had here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;On the negative side, my impression is that the authors prefer to use code behind sometimes where I would have liked to see the XAML alternative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Make sure you get the Second Edition if you decide to go for this book. The First Edition is inevitably way out of date now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Surprisingly (to me anyway, considering I spent a lot of time converting the code in the next book from C# to VB) the Petzold book only comes fourth in my list of most used books. This is:&lt;BR&gt;Applications = Code + Markup: A Guide to the Microsoft Windows Presentation Foundation &lt;BR&gt;by Charles Petzold. &lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFBooks/Petzold.jpg"&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;If you want intricate details and almost philosophical insight into the structure of WPF, then this would be the book for you. As with all Petzold books, it painstakingly works its way through the minutiae of the subject.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;If I have a criticism, it would be that sometimes the sackcloth and ashes approach to developing (such as manually creating everything yourself, even if it is available for free) doesn't always work for me. I understand the purity of the approach, but this means that it can sometimes be difficult to just dip into this book for a quick answer to a particular question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;However, if you really - really - want to get at the nuts and bolts of WPF, then you will probably not find one that has more detail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The fifth book in my WPF stable (for now, anyway!) is: &lt;BR&gt;Professional WPF Programming: .NET Development with the Windows Presentation Foundation &lt;BR&gt;by Chris Andrade and others. &lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFBooks/Wrox.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;When there were very few other books available, this one had some benefits. The authors had each looked at specific areas and came up with some guidance. Some parts were clearly better than others, but overall it was an easier read than MSDN at the time, but basically rather shallow coverage. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;It rarely gets opened these days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I have the greatest respect for anyone who takes the time, trouble and effort to write or co-write a book. Knowing how long it takes me to write a short article or a training package, I wouldn't dream of criticising someone who will have spent many long, hard months writing (and no doubt re-writing) a book. So, as I said at the start, the opinions in this blog item only reflect my personal experience of using this collection of books; other readers with other backgrounds and author style preferences may well have different opinions. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;As WPF picks up speed and interest grows, I'm sure there will be many other WPF books published in the coming months. There are already several that were published at the end of 2008 that I haven't read. &amp;nbsp; No doubt the temptation to pick up another title or two will become irresistible as 2009 progresses and, if so, I will post up my thoughts on those too in the hope that it might help you decide the best way of spending your hard-earned cash. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9243.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF Commands and PerformClick</title><link>http://blogs.vbcity.com/xtab/archive/2009/01/18/9240.aspx</link><pubDate>Sun, 18 Jan 2009 10:04:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/01/18/9240.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9240.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9240.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/01/18/9240.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9240.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Some weeks ago I wrote &lt;A href="http://blogs.vbcity.com/xtab/archive/2008/11/15/9202.aspx"&gt;a blog item&lt;/A&gt; about how to get the functionality of PerformClick in WPF. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I remember thinking at the time that it was a fairly clunky workaround and wondered why PerformClick hadn't been included in WPF. Of course there may be lots of reasons, beginning with 'No-one thought of it' and ending with 'It was just too difficult'. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;But while looking at an apparently unrelated problem this week, it occurred to me that maybe there is a more elegant solution staring me in the face - WPF's &lt;B&gt;Commands&lt;/B&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;In many cases where PerformClick is required, the situation is that whatever action is wired up to the Button's Click event is often also of interest to other controls - perhaps a menu item, a keyboard shortcut or a user instigated selection of some kind or other elsewhere. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;WPF Commands, if this is a new area for you, is a variation on the theme of Events. Whereas events are generally locked in to a specific action, a Command on the other hand is more along the lines of a loosely-coupled task that can be subscribed to from several places.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Of course,you may be sat there thinking that it doesn't take a coding genius to create code for events that can be re-used and accessed from several different points. The point is though that Commands are specifically designed for this purpose and they have a feature that I think makes them almost unique. &lt;FONT color=#408080&gt;(Can you be 'almost' unique, the literary critic part of my brain asks? Never mind, you know what I mean!)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Commands have the ability to turn themselves off in situations where it wouldn't be appropriate for them to be available - and back on again when it is. A common example is the Paste Command, where it doesn't make sense to have it available unless there is some data in the Clipboard.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Similarly, you might build in a test where the Exit command isn't allowed to function unless the user has taken some action, such as saving data. There are lots of similar examples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;WPF comes with a bundle of pre-built Commands for common tasks, including Copy, Cut, Paste, Find, Save, Close, Play, Zoom, Align and many more. Naturally, the designers of WPF don't know the exact actions you will want to link to each of the commands in every circumstance, so there is still some work for you to do. Commands are clever - but they're not magic!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Apart from the built in Commands, and on the basis that there are never enough of these kind of things, you can create Commands of your own relatively easily. You can set the bindings and the rules that decide when it may be able to execute and when not (as per the Paste example earlier).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;All of which brings me back to my original thought. If you can create a Command that both a Button and (in the case of the Forum question that got me thinking about this) a Menu Item can bind to, then that really removes the need to worry about PerformClick. Command would be a neater and more sophisticated way of achieving the same effect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;If you want more info on Commands, here is a useful link to an &lt;A href="http://msdn.microsoft.com/en-us/library/ms752308.aspx"&gt;MSDN&lt;/A&gt; Introduction to Commands article. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9240.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Generic comparer: for comparing/sorting sources of unknown types</title><link>http://blogs.vbcity.com/hotdog/archive/2008/12/29/9232.aspx</link><pubDate>Mon, 29 Dec 2008 11:56:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/hotdog/archive/2008/12/29/9232.aspx</guid><wfw:comment>http://blogs.vbcity.com/hotdog/comments/9232.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/hotdog/comments/commentRss/9232.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/hotdog/archive/2008/12/29/9232.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/hotdog/services/trackbacks/9232.aspx</trackback:ping><source url="http://blogs.vbcity.com/hotdog/rss.aspx">HotDog's Blog</source><description>&lt;P&gt;It's been a long time since making this class and don't believe I posted it yet, but since I'm going to use it in the DataGridViewGrouper (see previous post), thought I'd post it now.&lt;BR&gt;Since it's &amp;#8220;older&amp;#8221; code, it's fully .net 2.0 compatible. It can be uses where ever an IComparer interface is used. (or the Compare function of the GenericComparer&amp;lt;&amp;gt; class for a Comparison&amp;lt;&amp;gt; call)&lt;/P&gt;
&lt;P&gt;Usage example: &lt;BR&gt;&lt;!-- --Start of code block
--&gt;
&lt;DIV style="BORDER-RIGHT: #000080 1px solid; BORDER-TOP: #000080 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #000080 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #000080 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 9pt; BORDER-BOTTOM: #000080 1px solid; FONT-FAMILY: 'Microsoft Sans Serif'"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 10pt" onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy&lt;/A&gt;&lt;!-- CodeBlock by R.Verpalen 2005 : http://blogs.vbcity.com/hotdog/archive/2005/12/30/5759.aspx--&gt;&lt;/DIV&gt;
&lt;DIV style="OVERFLOW: auto; BACKGROUND-COLOR: #dcdcdc"&gt;&lt;FONT color=#2b91af&gt;Array&lt;/FONT&gt;.Sort(YourArray, &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;GenericComparer&lt;/FONT&gt;());&lt;FONT color=#0000ff&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- 
End of code block----&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;There is a generic comparer class already in the framework, but it will fail on certain types. It's been a while, but I believe the .net native class doesn't support the Nullable struct and&amp;nbsp;strong implementers of the generic&amp;nbsp;IComparer&amp;lt;&amp;gt; interface. (The new Linq will fail if the object sorted on is not an IComparable)&lt;/P&gt;&lt;!-- --Start of code block
--&gt;
&lt;DIV onkeydown="var k =event.keyCode,i=-1,ch=this.firstChild;if(k==32){i=ch.sel;if(++i==ch.selcount)i=0;}else i = k - 49;if(i&gt;=0 &amp;amp;&amp;amp; i&lt;ch.selcount){ch.sel=i;ch.click();}" style="BORDER-RIGHT: #000080 1px solid; BORDER-TOP: #000080 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #000080 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #000080 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 9pt; BORDER-BOTTOM: #000080 1px solid; FONT-FAMILY: 'Microsoft Sans Serif'" onclick="var i=this.sel,j,ch,count = this.selcount;if(i==this.selold)return;this.selold=i;for(j=0;j&lt;count;j++){ch=this.childNodes[2+j];ch.childNodes[0].checked=j==i;ch.style.fontWeight = j==i ? 'bolder' : 'normal';}ch=parentNode.childNodes[1];var sh=new Array('none','');j=i==0?0:1;ch.style.display=sh[j];ch.nextSibling.style.display=sh[1-j];var h =ch.offsetHeight;ch.style.height=i==1?'300pt':null;if(i==1&amp;amp;&amp;amp; ch.offsetHeight&gt;h)ch.style.height=h;" sel="1" selold="1" selcount="3"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 10pt" onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy&lt;/A&gt;&lt;SPAN style="MARGIN-LEFT: 5pt; CURSOR: hand; MARGIN-RIGHT: 5pt" onclick=parentNode.sel=0&gt;&lt;INPUT onclick=this.blur(); type=radio&gt;Hide&lt;/SPAN&gt;&lt;SPAN style="FONT-WEIGHT: bolder; MARGIN-LEFT: 5pt; CURSOR: hand; MARGIN-RIGHT: 5pt" onclick=parentNode.sel=1&gt;&lt;INPUT onclick=this.blur(); type=radio CHECKED&gt;Scroll&lt;/SPAN&gt;&lt;SPAN style="MARGIN-LEFT: 5pt; CURSOR: hand; MARGIN-RIGHT: 5pt" onclick=parentNode.sel=2&gt;&lt;INPUT onclick=this.blur(); type=radio&gt;Full&lt;/SPAN&gt;&lt;!-- CodeBlock by R.Verpalen 2005 : http://blogs.vbcity.com/hotdog/archive/2005/12/30/5759.aspx--&gt;&lt;/DIV&gt;
&lt;DIV style="OVERFLOW: auto; HEIGHT: 300pt; BACKGROUND-COLOR: #dcdcdc"&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System;&lt;FONT color=#0000ff&gt;&lt;BR&gt;using&lt;/FONT&gt; System.Collections.Generic;&lt;FONT color=#0000ff&gt;&lt;BR&gt;using&lt;/FONT&gt; System.Linq;&lt;FONT color=#0000ff&gt;&lt;BR&gt;using&lt;/FONT&gt; System.Text;&lt;FONT color=#0000ff&gt;&lt;BR&gt;using&lt;/FONT&gt; System.Collections;&lt;FONT color=#0000ff&gt;&lt;BR&gt;using&lt;/FONT&gt; System.ComponentModel;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;namespace&lt;/FONT&gt; Subro&lt;BR&gt;{&lt;FONT color=#808080&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; &lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Comparer that tries to find the 'strongest' comparer for a type. &lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; if the type implements a generic IComparable, that is used.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; otherwise if it implements a normal IComparable, that is used.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; If neither are implemented, the ToString versions are compared. &lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; INullable structures are also supported.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; This way, the DefaultComparer can compare any object types and can be used for sorting any source.&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; &lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; &lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;example&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;Array.Sort(YourArray,new GenericComparer());&lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/example&amp;gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;GenericComparer&lt;/FONT&gt; : &lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; GenericComparer()&lt;BR&gt;{&lt;/DIV&gt;&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;}&lt;FONT color=#0000ff&gt;&lt;BR&gt;public&lt;/FONT&gt; GenericComparer(&lt;FONT color=#2b91af&gt;Type&lt;/FONT&gt; Type)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;this&lt;/FONT&gt;.Type = Type;&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#2b91af&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;Type&lt;/FONT&gt; type;&lt;FONT color=#0000ff&gt;&lt;BR&gt;public&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;Type&lt;/FONT&gt; Type&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;get&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; type;&lt;/DIV&gt;}&lt;FONT color=#0000ff&gt;&lt;BR&gt;set&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;if&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;value&lt;/FONT&gt; == &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;throw&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ArgumentNullException&lt;/FONT&gt;();&lt;BR&gt;type = &lt;FONT color=#0000ff&gt;value&lt;/FONT&gt;;&lt;BR&gt;comp = &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#2b91af&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;Type&lt;/FONT&gt; targettype;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; &lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; normally the same as the type, but can be set to a different type&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; &lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;public&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;Type&lt;/FONT&gt; TargetType&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;get&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;if&lt;/FONT&gt; (targettype == &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; type;&lt;FONT color=#0000ff&gt;&lt;BR&gt;return&lt;/FONT&gt; targettype;&lt;/DIV&gt;}&lt;FONT color=#0000ff&gt;&lt;BR&gt;set&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;if&lt;/FONT&gt; (TargetType == &lt;FONT color=#0000ff&gt;value&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;return&lt;/FONT&gt;;&lt;BR&gt;targettype = &lt;FONT color=#0000ff&gt;value&lt;/FONT&gt;;&lt;BR&gt;comp = &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;&lt;/DIV&gt;&lt;FONT color=#2b91af&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;IComparer&lt;/FONT&gt; comp;&lt;/DIV&gt;&lt;FONT color=#2b91af&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;IComparer&lt;/FONT&gt; GetGenericComparer(&lt;FONT color=#2b91af&gt;Type&lt;/FONT&gt; From, &lt;FONT color=#2b91af&gt;Type&lt;/FONT&gt; To)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;while&lt;/FONT&gt; (To != &lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt;))&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;if&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT color=#2b91af&gt;IComparable&lt;/FONT&gt;&amp;lt;&amp;gt;).MakeGenericType(To).IsAssignableFrom(From))&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; (&lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;)&lt;FONT color=#2b91af&gt;Activator&lt;/FONT&gt;.CreateInstance(&lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT color=#2b91af&gt;StrongCompare&lt;/FONT&gt;&amp;lt;,&amp;gt;).MakeGenericType(From,To));&lt;/DIV&gt;To = To.BaseType;&lt;/DIV&gt;}&lt;FONT color=#0000ff&gt;&lt;BR&gt;return&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt; GetComparer(&lt;FONT color=#2b91af&gt;Type&lt;/FONT&gt; From, &lt;FONT color=#2b91af&gt;Type&lt;/FONT&gt; To)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;var&lt;/FONT&gt; gen = GetGenericComparer(From,To);&lt;FONT color=#0000ff&gt;&lt;BR&gt;if&lt;/FONT&gt; (gen != &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;)&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; gen;&lt;FONT color=#0000ff&gt;&lt;/DIV&gt;else&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT color=#2b91af&gt;IComparable&lt;/FONT&gt;).IsAssignableFrom(type))&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; (&lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;)&lt;FONT color=#2b91af&gt;Activator&lt;/FONT&gt;.CreateInstance(&lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT color=#2b91af&gt;NonGenericCompare&lt;/FONT&gt;&amp;lt;&amp;gt;).MakeGenericType(type));&lt;/DIV&gt;}&lt;FONT color=#0000ff&gt;&lt;BR&gt;else&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (type.IsGenericType &amp;amp;&amp;amp; &lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT color=#2b91af&gt;Nullable&lt;/FONT&gt;&amp;lt;&amp;gt;) == type.GetGenericTypeDefinition())&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;var&lt;/FONT&gt; basetype = type.GetGenericArguments()[0];&lt;FONT color=#0000ff&gt;&lt;BR&gt;return&lt;/FONT&gt; (&lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;)&lt;FONT color=#2b91af&gt;Activator&lt;/FONT&gt;.CreateInstance(&lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT color=#2b91af&gt;NullableComparer&lt;/FONT&gt;&amp;lt;&amp;gt;).MakeGenericType(basetype),
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;GetComparer(basetype, To == From ? basetype : To));&lt;/DIV&gt;&lt;/DIV&gt;}&lt;FONT color=#0000ff&gt;&lt;BR&gt;return&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;StringComparer&lt;/FONT&gt;();&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;NullableComparer&lt;/FONT&gt;&amp;lt;T&amp;gt;:&lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;where&lt;/FONT&gt; T:&lt;FONT color=#0000ff&gt;struct&lt;/FONT&gt;&lt;/DIV&gt;{&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt; BaseComparer;&lt;FONT color=#0000ff&gt;&lt;BR&gt;public&lt;/FONT&gt; NullableComparer(&lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt; BaseComparer)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;this&lt;/FONT&gt;.BaseComparer = BaseComparer;&lt;BR&gt;&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;object&lt;/FONT&gt; getval(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; o)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; ((&lt;FONT color=#2b91af&gt;Nullable&lt;/FONT&gt;&amp;lt;T&amp;gt;)o).Value;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;int&lt;/FONT&gt; Compare(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; x, &lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; y)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; BaseComparer.Compare(getval(x), getval(y));&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;}&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;StrongCompare&lt;/FONT&gt;&amp;lt;F,T&amp;gt; : &lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;where&lt;/FONT&gt; F : &lt;FONT color=#2b91af&gt;IComparable&lt;/FONT&gt;&amp;lt;T&amp;gt;&lt;/DIV&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;int&lt;/FONT&gt; Compare(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; x, &lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; y)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; ((F)x).CompareTo((T)y);&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;NonGenericCompare&lt;/FONT&gt;&amp;lt;T&amp;gt; : &lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;where&lt;/FONT&gt; T: &lt;FONT color=#2b91af&gt;IComparable&lt;/FONT&gt;&lt;/DIV&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;int&lt;/FONT&gt; Compare(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; x, &lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; y)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; ((T)x).CompareTo(y);&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;StringComparer&lt;/FONT&gt; : &lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;int&lt;/FONT&gt; Compare(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; x, &lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; y)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; x.ToString().CompareTo(y.ToString());&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;bool&lt;/FONT&gt; Descending&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;get&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; factor &amp;lt; 0;&lt;/DIV&gt;}&lt;FONT color=#0000ff&gt;&lt;BR&gt;set&lt;/FONT&gt;&lt;BR&gt;{
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;factor = &lt;FONT color=#0000ff&gt;value&lt;/FONT&gt; ? -1 : 1;&lt;/DIV&gt;}&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;int&lt;/FONT&gt; factor = 1;&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;int&lt;/FONT&gt; compare(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; x, &lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; y)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;if&lt;/FONT&gt; (x == y) &lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff&gt;&lt;BR&gt;if&lt;/FONT&gt; (x == &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; -1;&lt;FONT color=#0000ff&gt;&lt;BR&gt;if&lt;/FONT&gt; (y == &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; 1;&lt;FONT color=#0000ff&gt;&lt;BR&gt;if&lt;/FONT&gt; (type == &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;Type = x.GetType();&lt;FONT color=#0000ff&gt;&lt;/DIV&gt;if&lt;/FONT&gt; (comp == &lt;FONT color=#0000ff&gt;null&lt;/FONT&gt;)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;comp = GetComparer(type, TargetType);&lt;FONT color=#0000ff&gt;&lt;/DIV&gt;return&lt;/FONT&gt; comp.Compare(x, y);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;int&lt;/FONT&gt; Compare(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; x, &lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; y)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; factor * compare(x, y);&lt;/DIV&gt;}&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;}&lt;/DIV&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;GenericComparer&lt;/FONT&gt;&amp;lt;T&amp;gt; : &lt;FONT color=#2b91af&gt;GenericComparer&lt;/FONT&gt;,&lt;FONT color=#2b91af&gt;IComparer&lt;/FONT&gt;&amp;lt;T&amp;gt;&lt;BR&gt;{&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;public&lt;/FONT&gt; GenericComparer()
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;: &lt;FONT color=#0000ff&gt;base&lt;/FONT&gt;(&lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(T))&lt;/DIV&gt;{ }&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;int&lt;/FONT&gt; Compare(T a, T b)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;return&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;base&lt;/FONT&gt;.Compare(a, b);&lt;/DIV&gt;}&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;}&lt;/DIV&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;PropertyDescriptorComparer&lt;/FONT&gt; : &lt;FONT color=#2b91af&gt;GenericComparer&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;PropertyDescriptor&lt;/FONT&gt; Prop;&lt;/DIV&gt;&lt;/DIV&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;public&lt;/FONT&gt; PropertyDescriptorComparer(&lt;FONT color=#2b91af&gt;PropertyDescriptor&lt;/FONT&gt; Prop)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;: &lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;(Prop, &lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;)&lt;/DIV&gt;{&lt;BR&gt;}&lt;FONT color=#0000ff&gt;&lt;BR&gt;public&lt;/FONT&gt; PropertyDescriptorComparer(&lt;FONT color=#2b91af&gt;PropertyDescriptor&lt;/FONT&gt; Prop, &lt;FONT color=#0000ff&gt;bool&lt;/FONT&gt; Descending)
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;: &lt;FONT color=#0000ff&gt;base&lt;/FONT&gt;(Prop.PropertyType)&lt;/DIV&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;this&lt;/FONT&gt;.Prop = Prop;&lt;FONT color=#0000ff&gt;&lt;BR&gt;this&lt;/FONT&gt;.Descending = Descending;&lt;/DIV&gt;}&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;}&lt;/DIV&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;partial&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;Extend&lt;/FONT&gt;&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;void&lt;/FONT&gt; Sort&amp;lt;T&amp;gt;(&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt;T&amp;gt; list, &lt;FONT color=#2b91af&gt;Func&lt;/FONT&gt;&amp;lt;T, T, &lt;FONT color=#0000ff&gt;int&lt;/FONT&gt;&amp;gt; Comparer)&lt;BR&gt;{
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;list.Sort(&lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;Comparison&lt;/FONT&gt;&amp;lt;T&amp;gt;(Comparer));&lt;/DIV&gt;}&lt;/DIV&gt;&lt;/DIV&gt;&lt;FONT color=#808080&gt;
&lt;DIV style="MARGIN-LEFT: 40pt"&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; &lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;summary&amp;gt;&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; Sort on a property or field&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;BR&gt;///&lt;/FONT&gt;&lt;FONT color=#008000&gt; &lt;/FONT&gt;&lt;FONT color=#808080&gt;&amp;lt;/summary&amp;gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;void&lt;/FONT&gt; Sort&amp;lt;T, S&amp;gt;(&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt;T&amp;gt; list, &lt;FONT color=#2b91af&gt;Func&lt;/FONT&gt;&amp;lt;T, S&amp;gt; Property)&lt;BR&gt;{&lt;FONT color=#0000ff&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;var&lt;/FONT&gt; c = &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; Subro.&lt;FONT color=#2b91af&gt;GenericComparer&lt;/FONT&gt;&amp;lt;S&amp;gt;();&lt;BR&gt;Sort(list, (t1, t2) =&amp;gt; c.Compare(Property(t1), Property(t2)));&lt;/DIV&gt;}&lt;/DIV&gt;
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;}&lt;/DIV&gt;&lt;BR&gt;&lt;BR&gt;}&lt;FONT color=#2b91af&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV ondblclick="var o = parentNode.firstChild;o.sel =1;o.click()" style="DISPLAY: none; BACKGROUND-COLOR: #dcdcdc"&gt;&lt;B&gt;. . .&lt;/B&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- 
End of code block----&gt;&lt;/S&gt;&lt;img src ="http://blogs.vbcity.com/hotdog/aggbug/9232.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Robert Verpalen</dc:creator></item><item><title>Grouping a datagridview: the DataGridViewGrouper component</title><link>http://blogs.vbcity.com/hotdog/archive/2008/12/19/9226.aspx</link><pubDate>Fri, 19 Dec 2008 14:56:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/hotdog/archive/2008/12/19/9226.aspx</guid><wfw:comment>http://blogs.vbcity.com/hotdog/comments/9226.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/hotdog/comments/commentRss/9226.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/hotdog/archive/2008/12/19/9226.aspx#comment</comments><slash:comments>5</slash:comments><trackback:ping>http://blogs.vbcity.com/hotdog/services/trackbacks/9226.aspx</trackback:ping><source url="http://blogs.vbcity.com/hotdog/rss.aspx">HotDog's Blog</source><description>&lt;P&gt;&lt;STRONG&gt;&lt;FONT size=4&gt;Complete Source Code: &lt;/FONT&gt;&lt;/STRONG&gt;&lt;A href="http://blogs.vbcity.com/hotdog/archive/2008/12/19/9225.aspx"&gt;&lt;STRONG&gt;&lt;FONT size=4&gt;http://blogs.vbcity.com/hotdog/archive/2008/12/19/9225.aspx&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;
&lt;P&gt;
&lt;HR id=null&gt;
Note: the code is now rewritten to be 2.0 compatible (the project was written in vs2008 with compatibility set on framework 2.0), but older designers may still have trouble compiling because of the use of newer syntax (such as automatic properties). All 'var' keywords should be replaced, but they tend to sneak in because they are so easy to use ;)&lt;BR&gt;If the newer syntax is a problem for many of you, drop me a note and I'll try to remove all of those syntaxes too.
&lt;HR id=null&gt;
&lt;BR&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;:&lt;BR&gt;Assuming you have a form with a datagridview called dataGridView1, add this code (after setting its datasource): &lt;!-- --Start of code block
--&gt;
&lt;DIV onkeydown="var k =event.keyCode,i=-1,ch=this.firstChild;if(k==32){i=ch.sel;if(++i==ch.selcount)i=0;}else i = k - 49;if(i&gt;=0 &amp;amp;&amp;amp; i&lt;ch.selcount){ch.sel=i;ch.click();}" style="BORDER-RIGHT: #000080 1px solid; BORDER-TOP: #000080 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #000080 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #000080 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 9pt; BORDER-BOTTOM: #000080 1px solid; FONT-FAMILY: 'Microsoft Sans Serif'" onclick="var i=this.sel,j,ch,count = this.selcount;if(i==this.selold)return;this.selold=i;for(j=0;j&lt;count;j++){ch=this.childNodes[2+j];ch.childNodes[0].checked=j==i;ch.style.fontWeight = j==i ? 'bolder' : 'normal';}ch=parentNode.childNodes[1];var sh=new Array('none','');j=i==0?0:1;ch.style.display=sh[j];ch.nextSibling.style.display=sh[1-j];var h =ch.offsetHeight;ch.style.height=i==1?'125pt':null;if(i==1&amp;amp;&amp;amp; ch.offsetHeight&gt;h)ch.style.height=h;" selcount="3" selold="2" sel="2"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 10pt" onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy&lt;/A&gt;&lt;SPAN style="MARGIN-LEFT: 5pt; CURSOR: hand; MARGIN-RIGHT: 5pt" onclick=parentNode.sel=0&gt;&lt;INPUT onclick=this.blur(); type=radio&gt;Hide&lt;/SPAN&gt;&lt;SPAN style="MARGIN-LEFT: 5pt; CURSOR: hand; MARGIN-RIGHT: 5pt" onclick=parentNode.sel=1&gt;&lt;INPUT onclick=this.blur(); type=radio&gt;Scroll&lt;/SPAN&gt;&lt;SPAN style="FONT-WEIGHT: bolder; MARGIN-LEFT: 5pt; CURSOR: hand; MARGIN-RIGHT: 5pt" onclick=parentNode.sel=2&gt;&lt;INPUT onclick=this.blur(); type=radio CHECKED&gt;Full&lt;/SPAN&gt;&lt;!-- CodeBlock by R.Verpalen 2005 : http://blogs.vbcity.com/hotdog/archive/2005/12/30/5759.aspx--&gt;&lt;/DIV&gt;
&lt;DIV style="OVERFLOW: auto; BACKGROUND-COLOR: #dcdcdc"&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; grouper = &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; Subro.Controls.&lt;FONT color=#2b91af&gt;DataGridViewGrouper&lt;/FONT&gt;(dataGridView1);&lt;BR&gt;grouper.SetGroupOn(&lt;FONT color=#a31515&gt;"NameOfThePropertyToGroupOn"&lt;/FONT&gt;);&lt;FONT color=#0000ff&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV ondblclick="var o = parentNode.firstChild;o.sel =2;o.click()" style="DISPLAY: none; BACKGROUND-COLOR: #dcdcdc"&gt;&lt;B&gt;. . .&lt;/B&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- 
End of code block----&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Functionality&lt;/STRONG&gt;:&lt;BR&gt;The DataGridViewGrouper is a component that can be added in the forms designer or in runtime to add grouping to any existing (databound) DataGridView. Grouping can be done on existing properties of the underlying data or with a custom value function. The displayed data can be altered through the exposed Display event.&lt;BR&gt;Grouped rows can be quickly selected by double clicking the group header, and the rows can be collapsed and expanded by the user. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Usage&lt;/STRONG&gt;:&lt;BR&gt;3&amp;nbsp;simple steps&lt;BR&gt;- Add the component to the designer or create it in runtime&lt;BR&gt;-&amp;nbsp;Set its DataGridView property to&amp;nbsp;any existing databound DataGridView &lt;BR&gt;-In runtime set the GroupOn property or call any of the SetGroupOn methods to start grouping&lt;/P&gt;
&lt;P&gt;Other settings include &lt;BR&gt;-the sorting of the groups (asc,desc or none, using the lists original sources order as leading)&lt;BR&gt;-if the count of rows has to be shown (the shown information can be altered by catching the Display event)&lt;BR&gt;-if the property name on which is grouped has to be shown (can also be altered by the Display event)&lt;BR&gt;-besides the options above, the shown group value can also be altered in the Display event.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Background&lt;/STRONG&gt;:&lt;BR&gt;For a while now I was facing a request to add grouping to an overview in a DataGridView. And as you may have noticed: there is no grouping functionality in the default System.Windows.Forms.DataGridView.&lt;BR&gt;Now there are ways of course, by adding DataGridViewRows manually and creating the groups by adding rows, but that would screw up the underlying data binding and automatic buffering/formatting/filtering/sorting, etc. Wanted to keep the bound functionality intact, but still create group rows. The solution in itself is simply to create a wrapper source that includes those rows and the grouped rows underneath and asign that to the grid, leaving the original source unaltered, and override the grouping rows painting/editing. A theory simple enough in itself, of course the implementation was a bit more work, but still less difficult than expected. &lt;BR&gt;The grouping source was created easily enough, especially with the great functionality of Linq. The trick was in seperating what the grid saw from the underlying functionality. By inheriting from BindingSource all tools were available for that job.&amp;nbsp;The DataSource and DataMember properties are set&amp;nbsp;by the original values of the same properties in the Grid, therefor exposing the proper 'Columns'.&amp;nbsp;All adding and removing had to be done in the underlying datagrid source, so those values were overridden.&lt;BR&gt;The DataGridViewGrouper component itself is assigned to a grid and the Source of the grid itself is set to the grouped source. When a group row has to be painted, it is handled by the component, the other rows follow the default behaviour. Editing for a grouprow is simply cancelled. If the original source is a BindingSource, the source's positioning is synchronized.&lt;BR&gt;Note that the index of the datagridview row won't be the same as the index in the original source, so you shouldn't be getting an object out of the original source directly with the row index. Then again, you should never do that anyway ;)&amp;nbsp; Use the Grid.Rows[position].DataBoundItem property instead.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.vbcity.com/hotdog/archive/2008/12/19/9225.aspx"&gt;Source Code&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;TODO: &lt;BR&gt;* Now the component synchronizes navigation if the source is another BindingSource. Will look later to synchronize with any CurrencyManager.&lt;BR&gt;* Adding code comments&amp;nbsp;:p&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/hotdog/aggbug/9226.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Robert Verpalen</dc:creator></item><item><title>DataGridViewGrouper SourceCode</title><link>http://blogs.vbcity.com/hotdog/archive/2008/12/19/9225.aspx</link><pubDate>Fri, 19 Dec 2008 14:12:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/hotdog/archive/2008/12/19/9225.aspx</guid><wfw:comment>http://blogs.vbcity.com/hotdog/comments/9225.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/hotdog/comments/commentRss/9225.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/hotdog/archive/2008/12/19/9225.aspx#comment</comments><slash:comments>3</slash:comments><trackback:ping>http://blogs.vbcity.com/hotdog/services/trackbacks/9225.aspx</trackback:ping><source url="http://blogs.vbcity.com/hotdog/rss.aspx">HotDog's Blog</source><description>&lt;img src ="http://blogs.vbcity.com/hotdog/aggbug/9225.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Robert Verpalen</dc:creator></item><item><title>New Blog</title><link>http://blogs.vbcity.com/skullcrusher/archive/2008/12/18/9224.aspx</link><pubDate>Wed, 17 Dec 2008 22:19:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/skullcrusher/archive/2008/12/18/9224.aspx</guid><wfw:comment>http://blogs.vbcity.com/skullcrusher/comments/9224.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/skullcrusher/comments/commentRss/9224.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/skullcrusher/archive/2008/12/18/9224.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/skullcrusher/services/trackbacks/9224.aspx</trackback:ping><source url="http://blogs.vbcity.com/skullcrusher/rss.aspx">Skullcrusher's Blog</source><description>Just to let anyone who might be interested know that my Blog has now moved to &lt;A href="http://cs.vbcity.com/blogs/skullcrusher/default.aspx"&gt;http://cs.vbcity.com/blogs/skullcrusher/default.aspx&lt;/A&gt;&lt;img src ="http://blogs.vbcity.com/skullcrusher/aggbug/9224.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Andy Bonner</dc:creator></item><item><title>WPF Text Tricks - MultiLine Text and Multiple Spaces</title><link>http://blogs.vbcity.com/xtab/archive/2008/12/12/9215.aspx</link><pubDate>Fri, 12 Dec 2008 16:51:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/12/12/9215.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9215.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9215.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/12/12/9215.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9215.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;When it comes to text handling in WPF, you have a massive range of tools available, some of which can offer you a level of granularity that was previously unachievable. I plan to write about some of these text tools, such as Spans, Runs and Glyphs in future blogs, but for today I want to look at something a little less deep. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Recently I needed to insert a carriage return in a block of text. The text was being created in the XAML markup, and I didn't particularly want to resort to code-behind for what is essentially a UI feature. So I had to do a bit of digging to find how I could create, for instance, this result:- &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Text1.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;where, if I don't override it, the two words would be placed one after the other on one line because there is more than enough width for them both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;As you might expect, there are several ways of achieving this, but I think the easiest one is to use a LineBreak element. This snippet shows the key part of the code that creates and formats the Button's Content, which in this example is of course text only. &lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;}??\fs20 \cf1     \cf3 &amp;lt;\cf1 Button\cf4  Margin\cf3 ="12,45" &amp;gt;\par ??\cf1       \cf3 &amp;lt;\cf1 TextBlock\cf3 &amp;gt;\cf1  Click \cf3 &amp;lt;\cf1 LineBreak\cf3 /&amp;gt;\cf1  Me!\cf3 &amp;lt;/\cf1 TextBlock\cf3 &amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Button\cf3 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="12,45" &amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt; Click &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LineBreak&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt; Me!&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; You might think it a bit strange when you see that XML type item stuck into the middle of a block of text, but this is perfectly valid syntax. Because the Content isn't a single block of text, it's necessary to use the TextBlock to house the text and the LineBreak instruction. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Actually, what I really wanted to do wasn't quite as plain as the above screenshot. It was more along these lines:-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Text2.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The markup for this is still not particularly complex. It just requires more properties to be set specifically:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1     \cf3 &amp;lt;\cf1 Button\cf0  \cf5  Margin\cf3 ="12,45"\cf5  Background\cf3 ="LightSkyBlue"&amp;gt;\par ??\cf1       \cf3 &amp;lt;\cf1 Button.Content\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 TextBlock\cf5  TextAlignment\cf3 ="Center"\cf5  FontSize\cf3 ="16"\cf5  FontFamily\cf3 ="Calibra"\par ??\cf0                   \cf5  FontWeight\cf3 ="Bold"\cf5  Foreground\cf3 ="Navy"\cf5  FontStyle\cf3 ="Italic" &amp;gt;\par ??\cf1           Click \cf3 &amp;lt;\cf1 LineBreak\cf3 /&amp;gt;\cf1  Me!\cf3 &amp;lt;/\cf1 TextBlock\cf3 &amp;gt;\par ??\cf1       \cf3 &amp;lt;/\cf1 Button.Content\cf3 &amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Button\cf3 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="12,45"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="LightSkyBlue"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; TextAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="16"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Calibra"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Bold"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Navy"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; FontStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Italic" &amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Click &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LineBreak&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt; Me!&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I did mention that there are several ways and these include using a StackPanel containing multiple TextBlocks or setting the Padding property on a single TextBlock. An alternative you might consider is to preserve the whitespace. This effectively means that however you enter the text layout in your XAML will be faithfully reproduced in the WPF display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The following markup:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1     \cf3 &amp;lt;\cf1 Button\cf0  \cf5  Margin\cf3 ="12,40"&amp;gt;\par ??\cf1       \cf3 &amp;lt;\cf1 TextBlock\cf5  FontSize\cf3 ="14"\cf5  VerticalAlignment\cf3 ="Center"\par ??\cf5 HorizontalAlignment\cf3 ="Center"\cf5  xml\cf3 :\cf5 space\cf3 ="preserve"&amp;gt;\cf1 Click\par ??Me!\cf3 &amp;lt;/\cf1 TextBlock\cf3 &amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Button\cf3 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="12,40"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="14"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: red"&gt;HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; xml&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;space&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="preserve"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Click&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;Me!&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;will achieve a similar result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Text3.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;However, I really don't think the way the Markup sits in the XAML markup window is particularly neat. If you're interested in experimenting, try moving the word "Me!" so that it is more neatly aligned. Or Start the word "Click" on a new line of its own, maybe aligned with the markup above it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The results are unlikely to be what you wanted to achieve and this is because the preservation is absolute. A XAML twist on WYSIWYG! &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;However, I included it here because the space preserve approach will be very useful to you in those cases where you want more than a single space between words or characters. Simply type out the text with the exact spacing that you require, set the XML Space attribute to Preserve and your requirements will be honored.&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1     \cf3 &amp;lt;\cf1 Button\cf0  \cf5  Margin\cf3 ="12,40"&amp;gt;\par ??\cf1       \cf3 &amp;lt;\cf1 TextBlock\cf5  FontSize\cf3 ="14"\cf5  VerticalAlignment\cf3 ="Center"\par ??\cf0          \cf5  HorizontalAlignment\cf3 ="Center"\cf0  \par ??         \cf5  xml\cf3 :\cf5 space\cf3 ="preserve"&amp;gt;\cf1 Name:    Ged\cf3 &amp;lt;/\cf1 TextBlock\cf3 &amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Button\cf3 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="12,40"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="14"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;SPAN style="COLOR: red"&gt; HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center"&lt;/SPAN&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;SPAN style="COLOR: red"&gt; xml&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;space&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="preserve"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Name:&amp;nbsp; &amp;nbsp; Ged&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Text4.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face=Verdana size=2&gt; So there are a couple of tips for dealing with text in WPF.&amp;nbsp; There's more to come!&lt;/FONT&gt;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9215.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Formatting XAML Code Samples for a Blog </title><link>http://blogs.vbcity.com/xtab/archive/2008/12/11/9214.aspx</link><pubDate>Thu, 11 Dec 2008 09:18:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/12/11/9214.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9214.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9214.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/12/11/9214.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9214.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: x-small; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;For several years, whenever I've needed to include code snippets in my blogs and articles, I've used a neat little application that VBCity member HotDog wrote. This has stood me in good stead until the day that XAML arrived on the scene. Unfortunately, XAML kinda confuses HotDog's AutoFormatter tool and I end up with missing angle brackets. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;A bit of searching led me to a tool called CopySourceAsHTML. Although I had seen this used with Visual Studio 2005, there was a minor problem using it with 2008 for a while, but this was easily fixed with a minor tweak. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Now though there is an official Visual Studio 2008 version. The extra good news about this is that it will also copy XAML to HTML.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;One thing to watch out for if you have used the tool before and usually right click on a code snippet to copy is as HTML: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/CSAH1.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; you will expect to see the &lt;I&gt;Copy As HTML&lt;/I&gt; option in the menu. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;However, this doesn't appear in the context menu if you right click on the markup in the XAML Markup Pane. But it is available and all you have to do is go to the IDE main menu, select &lt;I&gt;Edit &lt;/I&gt;and the &lt;I&gt;Copy As HTML&lt;/I&gt; menu item will be available for you there. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;This great little utility is written (and updated) by Colin Coller of J T Leigh and Associates. You can download it &lt;A href="http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/"&gt;from here&lt;/A&gt;.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9214.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF Gotchas: What's the WPF Equivalent of the Text Property?</title><link>http://blogs.vbcity.com/xtab/archive/2008/12/11/9213.aspx</link><pubDate>Thu, 11 Dec 2008 09:13:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/12/11/9213.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9213.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9213.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/12/11/9213.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9213.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: x-small; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;One of the things that often pulls me up in mid flow when I'm putting WPF UIs together in a Window is that some of the core properties seem to have disappeared. Now, some of these are so fundamental that I know they have to be there, but obviously hiding under a different name. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;Just recently, this happened to me twice in a row and I ended up scrolling through the Properties in the Object Browser, getting dizzy with the whizzing list of choices until I finally found them. All I was looking for was a very simple thing in both cases. I just wanted to apply some text to a control. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;The first one was the good old CheckBox. In Windows Forms this has a Text property, of course, and it's whatever textual information you want to place at the side of the little square check area. The WPF CheckBox will allow you to do a zillion clever things to change its look - add Borders, TextBlocks, Images, Panels, whatever you like - and at times I'm really happy about that. But as it happened this time I just wanted to plonk a couple of words of description at the side.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;You'll have gathered that there isn't a Text property for the WPF CheckBox and after a bit of a search, I did find its replacement - the &lt;B&gt;Content&lt;/B&gt; property. If you assign plain text to this property, WPF&amp;nbsp;will honor your choice. So this:&lt;/FONT&gt; &lt;/P&gt;
&lt;P&gt;&lt;!--
{
tf1\ansi\ansicpg\lang1024
oproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??
ed0\green0\blue255;
ed255\green255\blue255;
ed163\green21\blue21;
ed255\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 CheckBox\cf4  x\cf1 :\cf4 Name\cf1 ="CheckBox1"\cf4  Content\cf1 ="Click Here" /&amp;gt;}
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;17&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CheckBox1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Click Here" /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;will do the job nicely.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;Subsequently I discovered that the Content property is in fact the default property of a CheckBox, so this too will work: &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;!--
{
tf1\ansi\ansicpg\lang1024
oproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??
ed163\green21\blue21;
ed255\green255\blue255;
ed0\green0\blue255;
ed255\green0\blue0;}??\fs20 \cf1  \cf3 &amp;lt;\cf1 CheckBox\cf4  x\cf3 :\cf4 Name\cf3 ="CheckBox1"&amp;gt;\cf1 "Click Here"\cf3 &amp;lt;/\cf1 CheckBox\cf3 &amp;gt;\cf1  }
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;17&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CheckBox1"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Click Here"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face=Verdana size=2&gt;Of course if you do want something more exotic, then you still use the Content property - you just add whatever multiple layers of content you desire.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;The other control for which I had to search for the same kind of thing was the Expander. Again I only wanted a property that would just tack some plain text to the side of the Expander's little arrow. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;This time the answer is to use the Expander's &lt;B&gt;Header&lt;/B&gt; property.&lt;/FONT&gt; &lt;/P&gt;
&lt;P&gt;&lt;!--
{
tf1\ansi\ansicpg\lang1024
oproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??
ed0\green0\blue255;
ed255\green255\blue255;
ed163\green21\blue21;
ed255\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 Expander\cf4  Header\cf1 ="See More Choices"&amp;gt;&amp;lt;/\cf3 Expander\cf1 &amp;gt;}
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Expander&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="See More Choices"&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Expander&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;You can assign plain text to this property, but again you have the option to, well, &lt;I&gt;expand&lt;/I&gt; the Expander's Header to make it a little more graphically interesting.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Expander.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face=Verdana size=2&gt;using this XAML:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;!--
{
tf1\ansi\ansicpg\lang1024
oproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??
ed163\green21\blue21;
ed255\green255\blue255;
ed0\green0\blue255;
ed255\green0\blue0;
ed0\green0\blue0;}??\fs20 \cf1        \cf3 &amp;lt;\cf1 Expander.Header\cf3 &amp;gt;\par ??\cf1           \cf3 &amp;lt;\cf1 Border\cf4  BorderBrush\cf3 ="Navy"\cf4  BorderThickness\cf3 ="2"\cf4  CornerRadius\cf3 ="6"&amp;gt;\par ??\cf1             \cf3 &amp;lt;\cf1 TextBlock\cf4  Margin\cf3 ="10,2,10,2"\cf0  \par ??             \cf4  Foreground\cf3 ="Navy"&amp;gt;\cf1 What do you want to do?\cf3 &amp;lt;/\cf1 TextBlock\cf3 &amp;gt;\par ??\cf1           \cf3 &amp;lt;/\cf1 Border\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;/\cf1 Expander.Header\cf3 &amp;gt;}
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Expander.Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; BorderBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Navy"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; CornerRadius&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="6"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="10,2,10,2"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Navy"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;What do you want to do?&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Expander.Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face=Verdana size=2&gt;Although Content is the default property, don't fall into the trap of trying to use it as:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;!--
{
tf1\ansi\ansicpg\lang1024
oproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??
ed163\green21\blue21;
ed255\green255\blue255;
ed0\green0\blue255;}??\fs20 \cf1  \cf3 &amp;lt;\cf1 Expander\cf3 &amp;gt;\cf1  Click to view choices \cf3 &amp;lt;/\cf1 Expander\cf3 &amp;gt;}
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;20&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Expander&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt; Click to view choices &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Expander&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face=Verdana size=2&gt;because that inserts the text as the first (and in this case, only) item in the area that you get to see when the Expander arrow is clicked. It will be the only item because Content isn't a container and you need to use something like a StackPanel if you have more than one child that you want to include in the expanded area. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;Something like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;!--
{
tf1\ansi\ansicpg\lang1024
oproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??
ed163\green21\blue21;
ed255\green255\blue255;
ed0\green0\blue255;
ed255\green0\blue0;
ed0\green0\blue0;}??\fs20 \cf1        \cf3 &amp;lt;\cf1 Expander.Content\cf3 &amp;gt;\par ??\cf1           \cf3 &amp;lt;\cf1 StackPanel\cf3  &amp;gt;\par ??\cf1             \cf3 &amp;lt;\cf1 CheckBox\cf4  Margin\cf3 ="2,4"\cf4  Content\cf3 =" Do This"&amp;gt;&amp;lt;/\cf1 CheckBox\cf3 &amp;gt;\par ??\cf1             \cf3 &amp;lt;\cf1 CheckBox\cf4  Margin\cf3 ="2,4"\cf4  Content\cf3 =" Do That"&amp;gt;&amp;lt;/\cf1 CheckBox\cf3 &amp;gt;\par ??\cf1             \cf3 &amp;lt;\cf1 CheckBox\cf4  Margin\cf3 ="2,4" &amp;gt;\par ??\cf1               \cf3 &amp;lt;\cf1 CheckBox.Content\cf3 &amp;gt;\par ??\cf1                 \cf3 &amp;lt;\cf1 StackPanel\cf4  Orientation\cf3 ="Horizontal"&amp;gt;\par ??\cf1                   \cf3 &amp;lt;\cf1 Image\cf4  Width\cf3 ="16"\cf4  Source\cf3 ="DCP_1997.jpg"&amp;gt;&amp;lt;/\cf1 Image\cf3 &amp;gt;\par ??\cf1                   \cf3 &amp;lt;\cf1 TextBlock\cf4  Text\cf3 =" View Profile"&amp;gt;&amp;lt;/\cf1 TextBlock\cf3 &amp;gt;\par ??\cf1                 \cf3 &amp;lt;/\cf1 StackPanel\cf3 &amp;gt;\par ??\cf1               \cf3 &amp;lt;/\cf1 CheckBox.Content\cf3 &amp;gt;\par ??\cf1             \cf3 &amp;lt;/\cf1 CheckBox\cf3 &amp;gt;\par ??\cf1             \cf3 &amp;lt;\cf1 TextBlock\cf4  TextWrapping\cf3 ="Wrap"\cf4  Margin\cf3 ="3,30,0,0"\cf0  \par ??           \cf4  Text\cf3 ="Select a task from the list above." /&amp;gt;\par ??\cf1           \cf3 &amp;lt;/\cf1 StackPanel\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;/\cf1 Expander.Content\cf3 &amp;gt;}
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Expander.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="2,4"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=" Do This"&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="2,4"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=" Do That"&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="2,4" &amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Orientation&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Horizontal"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Image&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="16"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="DCP_1997.jpg"&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Image&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=" View Profile"&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;CheckBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TextWrapping&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Wrap"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="3,30,0,0"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Select a task from the list above." /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Expander.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face=Verdana size=2&gt;to produce this result:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Expander1.jpg"&gt;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9213.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>My Blogs Are Moving to New Site</title><link>http://blogs.vbcity.com/xtab/archive/2008/12/08/9212.aspx</link><pubDate>Mon, 08 Dec 2008 16:13:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/12/08/9212.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9212.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9212.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/12/08/9212.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9212.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;FONT face=Verdana&gt;&amp;nbsp; VBCity will be looking very different&amp;nbsp;soon, as we change to the new Community Server based model.&amp;nbsp;&amp;nbsp; In advance of that change, our blogs are moving to a new area.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;From now on, you can view my latest blogs both here and&amp;nbsp;at the new site &lt;/FONT&gt;&lt;A href="http://cs.vbcity.com/blogs/xtab/default.aspx"&gt;&lt;FONT face=Verdana&gt;here&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;.&amp;nbsp; Once the new site is fully up and running, all new blog items will be posted on the new area only.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;All previous blogs from VBCity Bloggers will still be available and hopefully will continue to rank highly in search engine results.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9212.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>How To Get the Icon from an Application</title><link>http://blogs.vbcity.com/xtab/archive/2008/11/27/9208.aspx</link><pubDate>Thu, 27 Nov 2008 18:00:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/11/27/9208.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9208.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9208.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/11/27/9208.aspx#comment</comments><slash:comments>1</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9208.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;This question comes up every so often in the forums and it's one of those things that you'd think should be easy, but actually isn't. Well, it isn't until you know how - like most things in developer land. The question is usually something along the lines of &lt;I&gt;"How can I grab the icon from an MS Word file?"&lt;/I&gt; The application may not necessarily be MS Word, but the that's the general thrust of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The only approach I have successfully used in this kind of scenario is the SHGetFileInfo API*. This API will grab the icon from an application. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Here's the way I do it: First, Import Runtime.InteropServices into your Windows Form. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;Imports&lt;/FONT&gt; System.Runtime.InteropServices&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Next, the API code, which goes at the top of the form, outside of any procedures:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Structure&lt;/FONT&gt; SHFILEINFO&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; hIcon&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; IntPtr&lt;FONT color=#008000&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; iIcon&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; dwAttributes&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)&amp;gt; _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; szDisplayName&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)&amp;gt; _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; szTypeName&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Structure&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Declare&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Auto&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Function&lt;/FONT&gt; SHGetFileInfo&lt;FONT color=#0000ff&gt; Lib&lt;/FONT&gt;&lt;FONT color=#a31515&gt; "shell32.dll"&lt;/FONT&gt; _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; pszPath&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;, _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ByVal&lt;/FONT&gt; dwFileAttributes&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;, _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ByRef&lt;/FONT&gt; psfi&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; SHFILEINFO, _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ByVal&lt;/FONT&gt; cbFileInfo&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;, _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ByVal&lt;/FONT&gt; uFlags&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;)&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; IntPtr&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; hImgSmall&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; IntPtr&lt;FONT color=#008000&gt; 'The handle to the system image list.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Const&lt;/FONT&gt; SHGFI_ICON&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Long&lt;/FONT&gt; = &amp;amp;H100&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Const&lt;/FONT&gt; SHGFI_SMALLICON&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Long&lt;/FONT&gt; = &amp;amp;H1&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Note the two Constants at the end there being declared as Long. You'll usually find you have to tweak old API code to fix these kind of lines if you have Option Strict On.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;To demonstrate this API in action, here is how I've structured it: 
&lt;UL&gt;
&lt;LI&gt;I have added a button (btnSelectFile) to the Form.&lt;BR&gt;
&lt;LI&gt;When this button is clicked, an OpenFileDialog is created to allow the user to select a file.&lt;BR&gt;
&lt;LI&gt;Once a file has been selected, the file name is passed to a function that will dig out the icon for that file type and pass it back. &lt;BR&gt;
&lt;LI&gt;For demo purposes, the Form's default icon will be replaced with this selected one. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Here is the code in the function that grabs the icon:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;Function&lt;/FONT&gt; GetIcon(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; filename&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;)&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; Icon&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; shinfo&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; SHFILEINFO&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;shinfo =&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; SHFILEINFO&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'Get the small icon.&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;hImgSmall = SHGetFileInfo(filename, 0, shinfo, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Marshal.SizeOf(shinfo), _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SHGFI_ICON&lt;FONT color=#0000ff&gt; Or&lt;/FONT&gt; SHGFI_SMALLICON)&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return&lt;/FONT&gt; System.Drawing.Icon.FromHandle(shinfo.hIcon)&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Function&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;And here is that function being called from a Button Click, the icon then being shown as the Form's icon:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Sub&lt;/FONT&gt; btnSelectFile_Click(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; sender&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; System.Object,&lt;FONT color=#0000ff&gt; ByVal&lt;/FONT&gt; e&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; System.EventArgs)&lt;FONT color=#0000ff&gt; Handles&lt;/FONT&gt; btnSelectFile.Click&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; ofd&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; OpenFileDialog&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If&lt;/FONT&gt; ofd.ShowDialog = Windows.Forms.DialogResult.OK&lt;FONT color=#0000ff&gt; Then&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Me&lt;/FONT&gt;.Icon = GetIcon(ofd.FileName)&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Sub&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;That's pretty much all there is to it, if you are happy to plonk the icon on the form like that. But in most cases you'll probably want something a bit more reusable. One easy way to store the grabbed icon is to put it in an ImageList.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Assuming that you are only going to deal with one icon at a time, you can do something like this:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; myIcons&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; ImageList&lt;BR&gt;myIcons.Images.Add(System.Drawing.Icon.FromHandle(shinfo.hIcon))&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Now that you have that icon safely stored in the ImageList, you can access the ImageList in the usual way if you want to place the icon image elsewhere. And of course you can change the above code slightly to allow for more than one icon to be added to the ImageList and used as required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Finally, if you need to switch the icon into Bitmap format you can use the handy ToBitmap method:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; bmp&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; Bitmap = System.Drawing.Icon.FromHandle(shinfo.hIcon).ToBitmap&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;It is possible then to save the Bitmap by using the Bitmap's Save method. However, I have found this to be a bit hit-and-miss, with it sometimes throwing a generic GDI+ error when I tried to recall it for use by means of the Image.FromFile method. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I hope that if you need to grab an image from an application that you find this article useful.&lt;/P&gt;---------------------------------------------------------------------- 
&lt;P&gt;&amp;nbsp;&amp;nbsp;* There is the much more hopeful sounding ExtractIcon API which I have used to extract the icon of a currently running VB application, but haven't managed to port the logic over to the kind of file selection scenario described here.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9208.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF Missing In Action - The Button PerformClick Method</title><link>http://blogs.vbcity.com/xtab/archive/2008/11/15/9202.aspx</link><pubDate>Sat, 15 Nov 2008 15:59:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/11/15/9202.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9202.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9202.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/11/15/9202.aspx#comment</comments><slash:comments>5</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9202.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt;PerformClick is one of the many casualties of a move from Windows Forms to WPF. Of course, it's probably not something you would need to use often, but just in case you do then there is a way.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;It's not a very intuitive way and - had it not been that I spotted the C# version of this trick in Adam Nathan's WPF book - I wouldn't be sat here writing this now. I'd still be searching endlessly to try and find the answer.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp; In order to achieve this in VB, you need to do the following: &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;Add a Reference to &lt;FONT color=#000080&gt;UIAutomationProvider&lt;/FONT&gt; in your Project.&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;Add an Imports statement:&lt;/FONT&gt; &lt;BR&gt;&lt;FONT face="Courier New" color=#000080 size=3&gt;Imports System.Windows.Automation.Peers &lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;Add another Imports statement: &lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=#000080 size=3&gt;Imports System.Windows.Automation.Provider &lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;Use the following code snippet: &lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#000080&gt;&lt;FONT size=3&gt;Dim buttonPeer As New ButtonAutomationPeer(Button1) &lt;BR&gt;Dim invokeProv As IInvokeProvider = TryCast(buttonPeer.GetPattern(PatternInterface.Invoke), IInvokeProvider) &lt;BR&gt;invokeProv.Invoke() &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;FONT size=2&gt; The above code to be placed wherever you want to simulate the Button's Click. (Change the Button name as needed). &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;It did occur to me that this task might be a good candidate for a custom Command, using WPF's quite versatile Command abilities. However, I haven't got past the "wonder if that's a good idea?" stage. And to be honest, probably won't any time soon. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;Whether&amp;nbsp;you feel that it's necessary to go to the trouble of the Automation or the Command approach is of course entirely up to you. I have to admit to being tempted simply to move the action code out of the Button Click event and into a separate method that can be called from both the Button Click and other events.&amp;nbsp; But then, I've never been much or a purist about these things.&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9202.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Blog Moving to New vbCity Blog Site at http://cs.vbcity.com/blogs/mike-mcintyre/default.aspx</title><link>http://blogs.vbcity.com/mcintyre/archive/2008/11/07/9198.aspx</link><pubDate>Fri, 07 Nov 2008 14:02:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/mcintyre/archive/2008/11/07/9198.aspx</guid><wfw:comment>http://blogs.vbcity.com/mcintyre/comments/9198.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/mcintyre/comments/commentRss/9198.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/mcintyre/archive/2008/11/07/9198.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/mcintyre/services/trackbacks/9198.aspx</trackback:ping><source url="http://blogs.vbcity.com/mcintyre/rss.aspx">mike mcintyre's</source><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;My .Net Journal blog posts will be made to the new vbCity blog site from now on.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Here's the link to my new blog site:&amp;nbsp;&lt;A href="http://cs.vbcity.com/blogs/mike-mcintyre/default.aspx"&gt;Mike McIntyre's .NET Journal&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;RSS feed is:&amp;nbsp; &lt;A href="http://cs.vbcity.com/blogs/mike-mcintyre/rss.aspx"&gt;http://cs.vbcity.com/blogs/mike-mcintyre/rss.aspx&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/mcintyre/aggbug/9198.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Mike McIntyre [MVP Visual Basic]</dc:creator></item><item><title>WPF project for Background Colours</title><link>http://blogs.vbcity.com/canoz/archive/2008/10/25/9195.aspx</link><pubDate>Sun, 26 Oct 2008 05:49:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/canoz/archive/2008/10/25/9195.aspx</guid><wfw:comment>http://blogs.vbcity.com/canoz/comments/9195.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/canoz/comments/commentRss/9195.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/canoz/archive/2008/10/25/9195.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/canoz/services/trackbacks/9195.aspx</trackback:ping><source url="http://blogs.vbcity.com/canoz/rss.aspx">CanOz Blog</source><description>&lt;P&gt;It is a little longer than I expected to get the the project that goes along with &lt;A href="http://blogs.vbcity.com/canoz/archive/2008/07/16/9136.aspx" target=blank&gt;this post&lt;/A&gt; about background colours in WPF but as they say better late ....&lt;/P&gt;
&lt;P&gt;The project can be downloaded from &lt;A href="http://www.neilknobbe.com/projects/BackgroundColours.zip" target=blank&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/canoz/aggbug/9195.aspx" width = "1" height = "1" /&gt;</description><dc:creator>V. Neil Knobbe</dc:creator></item><item><title>The Ampersand and XAML</title><link>http://blogs.vbcity.com/canoz/archive/2008/10/25/9193.aspx</link><pubDate>Sun, 26 Oct 2008 05:11:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/canoz/archive/2008/10/25/9193.aspx</guid><wfw:comment>http://blogs.vbcity.com/canoz/comments/9193.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/canoz/comments/commentRss/9193.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/canoz/archive/2008/10/25/9193.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/canoz/services/trackbacks/9193.aspx</trackback:ping><source url="http://blogs.vbcity.com/canoz/rss.aspx">CanOz Blog</source><description>&lt;P&gt;I got caught the other day with a "what the heck" moment.&lt;/P&gt;
&lt;P&gt;I was trying to display "Mr &amp;amp; Mrs" as an Item in a ComboBox but it just was not happening.&lt;/P&gt;
&lt;P&gt;I suppose that this would not have come to light if my computer was not slowing down when I opened the ItemCollection window in Visual Studio.&amp;nbsp; It was so slow that I would type something then have to wait for a couple of seconds to show what I had typed.&amp;nbsp; If I made a mistake I had to change it which would take more time, so I decided to just add the five combobox items in the XMAL itself.&lt;/P&gt;
&lt;P&gt;As soon as I typed the item in, I got the squiggly blue line and the following error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/001ampersand.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which really threw me.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Being an old HTML boy from years past it finally hit me.&amp;nbsp; XAML is a markup language and most, if not all, markup languages use the ampersand (&amp;amp;) for defining special characters and XML (which XAML is based on) is no different.&lt;/P&gt;
&lt;P&gt;XAML has the same &lt;A href="http://msdn.microsoft.com/en-us/library/ms748250.aspx" target=_blank&gt;character entities&lt;/A&gt;&amp;nbsp;as XML and one of these is for using the ampersand in markup.&lt;/P&gt;
&lt;P&gt;Having refreshed my memory getting the desired result was an easy fix.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/02ampersand.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which, when run, shows correctly in the ComboBox.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/03ampersand.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/canoz/aggbug/9193.aspx" width = "1" height = "1" /&gt;</description><dc:creator>V. Neil Knobbe</dc:creator></item><item><title>WPF MIA - Anchor, Alignments,Canvas and Margins</title><link>http://blogs.vbcity.com/xtab/archive/2008/10/25/9192.aspx</link><pubDate>Sat, 25 Oct 2008 13:07:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/10/25/9192.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9192.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9192.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/10/25/9192.aspx#comment</comments><slash:comments>1</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9192.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;Continuing my look at features that seem to be Missing in Action (MIA) from Windows Forms, vbCity colleague Matt pointed out to me that the Anchor property seems to have disappeared. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; I'm really pleased that this came up, because it gives me an opportunity to highlight just some of the massive flexibility you have in WPF Windows when it comes to layout. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;So what does WPF have to offer that will work as well as Anchors do? Umm, that should probably read 'better than Anchors do', because let's face it, WinForms Anchoring doesn't always offer you the precise flexibility you want. But the short answer to the original question is: Lots! &lt;/P&gt;
&lt;P&gt;&amp;nbsp;I'm only going to cover a few examples here and then invite you to play with the ideas I have suggested. Using these, you can ensure that every control (or element, as we should properly call them in WPF) sits exactly where you tell it to, and stays anchored or not as the Window resizes, according to your wishes. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;HorizontalAlignment, VerticalAlignment and Margins&lt;/U&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; These two properties are reasonably close to the Anchor properties in WinForms. HorizontalAlignment gives you the choice of aligning (read: Anchoring) to Left or Right. So you can see how they relate to Anchor Left and Anchor Right. However, WPF never does layout by halves, so you also have two more choices - Center and Stretch. I won't insult your intelligence by telling you what those additional settings do. &lt;/P&gt;&amp;nbsp;Here's an example that will anchor a button to the top right hand corner of a Grid. 
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 Button\cf0  \cf5  Margin\cf1 ="0,5,5,0"\cf5  HorizontalAlignment\cf1 ="Right"\par ??\cf0        \cf5  VerticalAlignment\cf1 ="Top"\cf0  \cf1  &amp;gt;\cf3 Button\cf1 &amp;lt;/\cf3 Button\cf1 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0,5,5,0"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Right"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;SPAN style="COLOR: red"&gt; VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Top"&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt; &amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The result you will get is:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFMIA_Anchor/Align%20and%20Margin.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Notice that there is a 5 unit gap to the top and right of the button. I carefully used the word "unit" there because old habits always want me to say 'pixel'. It isn't necessarily 5 pixels gap; WPF thinks in terms of 'device independent units', but in many common scenarios you can still think pixels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The two gaps are set by the Margin property. "0,5,5,0" translated to: 
&lt;UL&gt;
&lt;LI&gt;0 for the Left Margin 
&lt;LI&gt;5 for the Top Margin 
&lt;LI&gt;5 for the Right Margin 
&lt;LI&gt;0 for the Bottom Margin &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Go ahead and tweak those settings to see how changes affect the position. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;If you try this markup, run the project and then resize the Window, that button will stick like glue to its position at the top right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Obviously, if you don't want any gaps then you can dispense with the Margin settings. This version uses the Left and Bottom settings only.&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;}??\fs20 \cf1  \cf3 &amp;lt;\cf1 Button\cf4  HorizontalAlignment\cf3 ="Left"\cf4  VerticalAlignment\cf3 ="Bottom" &amp;gt;\cf1 Button\cf3 &amp;lt;/\cf1 Button\cf3 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Left"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Bottom" &amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFMIA_Anchor/Align%20Only.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Margins Only&lt;/U&gt;&lt;BR&gt;&amp;nbsp; If you want an element to expand (and reduce) as the containing Window or other container resizes then you can achieve this just by setting the Margin properties. &lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 Grid\cf4  Background\cf1 ="Black"&amp;gt;\par ??\cf3      \cf1 &amp;lt;\cf3 Button\cf4  Margin\cf1 ="20,50"\cf0  \cf1  &amp;gt;\cf3 Button\cf1 &amp;lt;/\cf3 Button\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 Grid\cf1 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Black"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp;  &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="20,50"&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt; &amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFMIA_Anchor/Margins%20Only(Before).png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFMIA_Anchor/Margins%20Only(After).png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Alignment and Width&lt;/U&gt;&lt;BR&gt;&amp;nbsp; Another combination you can try is to use one of the alignments, together with hard coding the Width or Height of a control. Usually you won't want or need to fix a height or width, but there may be cases where this works for you. Try something like this:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;}??\fs20 \cf1  \cf3 &amp;lt;\cf1 Grid\cf4  Background\cf3 ="Black"&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 Button\cf4  VerticalAlignment\cf3 ="Bottom"\cf4  Width\cf3 ="90"&amp;gt;\par ??\cf1           Button\cf3 &amp;lt;/\cf1 Button\cf3 &amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Grid\cf3 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Black"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Bottom"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="90"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFMIA_Anchor/Alignment%20and%20Width.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;And in case you were wondering - yes, you can also add settings for the Margins too, so that you can position it, for example, a set distance from the Bottom edge.&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1  \cf3 &amp;lt;\cf1 Grid\cf4  Background\cf3 ="Black"&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 Button\cf4  VerticalAlignment\cf3 ="Bottom"\cf4  Width\cf3 ="90"\par ??\cf0                \cf4  Margin\cf3 ="0,0,0,15"&amp;gt;\par ??\cf1           Button\cf3 &amp;lt;/\cf1 Button\cf3 &amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Grid\cf3 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Black"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Bottom"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="90"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0,0,0,15"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I hope that by now you're starting to get the idea that WPF layout isn't going to miss the Anchor property any day soon! Combine the techniques shown above and you have a wide range of options.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Canvas&lt;/U&gt;&lt;BR&gt;&amp;nbsp;But we're not done here yet. If you want to contain an element inside a panel and be able to fix its relative position, you could use a Canvas. Check out this markup:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;}??\fs20 \cf1  \cf3 &amp;lt;\cf1 Grid\cf4  Background\cf3 ="Black"&amp;gt;\par ??\cf1       \cf3 &amp;lt;\cf1 Canvas\cf4  Margin\cf3 ="50,35"\cf4  Background\cf3 ="Yellow"&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 Button\cf4  Canvas.Left\cf3 ="12"\cf4  Canvas.Top\cf3 ="3"&amp;gt;\cf1 Button\cf3 &amp;lt;/\cf1 Button\cf3 &amp;gt;\par ??\cf1       \cf3 &amp;lt;/\cf1 Canvas\cf3 &amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Grid\cf3 &amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Black"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Canvas&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="50,35"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Yellow"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Canvas.Left&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="12"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Canvas.Top&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="3"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Button&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Canvas&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;This will net you the following, rather garish, result:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFMIA_Anchor/Canvas.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;That button will remain 12 units from the left and 3 units from the top of that Canvas, no matter what else happens by way of resizing the Canvas, the Grid or even the Window. &lt;/P&gt;
&lt;P&gt;I think that even these simple, single examples show a great deal of power and flexibility for positioning elements. Bear in mind that you can build up layers of containers and panels and elements inside each other - and control the placement of each of them individually in relation to its container. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;While the familiar Anchor may be missing, I somehow think that once you become used to using these new techniques you won't actually miss it at all. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9192.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF MIA: BackColor, Background, Colors and Brushes</title><link>http://blogs.vbcity.com/xtab/archive/2008/10/23/9191.aspx</link><pubDate>Thu, 23 Oct 2008 19:56:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/10/23/9191.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9191.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9191.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/10/23/9191.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9191.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp; One of the things that first caught me out in WPF was the simple topic of colors. For example, let's say you want to reset the BackColor of a Form in Windows Forms. &lt;BR&gt;&lt;BR&gt;Easy enough. This will do the job:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;Me&lt;/FONT&gt;.BackColor = Color.CadetBlue&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;When it comes to WPF, you'll know that we are dealing with a Window, instead of a Form and have probably already picked up that &lt;B&gt;BackColor&lt;/B&gt; is now &lt;B&gt;Background&lt;/B&gt;. &amp;nbsp;You can however, still use "Me" to reference the Window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;But if you were to try something like:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;Me&lt;/FONT&gt;.Background = Color.CadetBlue&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' or even&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;Me&lt;/FONT&gt;.Background = Colors.CadetBlue&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;you would be disappointed. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;You would however get some help from Intellisense (at least with the second version). The error message tells you that a Color cannot be converted to a Brush. And there's the answer to the problem. &lt;BR&gt;&lt;BR&gt;The Background property doesn't take a Color - it takes a Brush, which of course can, and usually does, have a color assigned to it. Don't forget though that you are not limited to a single solid color; there are many gradient, tile and image based options that you can choose when it comes to brushes in WPF. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;So this code will work fine in WPF:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;Me&lt;/FONT&gt;.Background =&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; SolidColorBrush((Colors.CadetBlue))&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&amp;nbsp;Ah yes, I hear you say, but what about the theory that you should use XAML for the look and code-behind for the behaviour? Well, I can't disagree with you there and personally I would use:&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 Window\cf4  x\cf1 :\cf4 Class\cf1 ="Window1"\par ??\cf0    \cf4  xmlns\cf1 ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 x\cf1 ="http://schemas.microsoft.com/winfx/2006/xaml"\par ??\cf0    \cf4  Title\cf1 ="Window1"\cf4  Height\cf1 ="300"\cf4  Width\cf1 ="300"\cf0  \par ??\cf4 Background\cf1 ="CadetBlue"&amp;gt;}
--&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Window1"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;  &lt;SPAN style="COLOR: red"&gt; xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;  &lt;SPAN style="COLOR: red"&gt; xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;  &lt;SPAN style="COLOR: red"&gt; Title&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Window1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&lt;/SPAN&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: red"&gt;Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="CadetBlue"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&amp;nbsp;where the Background property for the Window is set there in the XAML. However, there may well be times when you want the user to have a say in color choices and in those cases it can be easier to take the user's input and deal with it in the code-behind. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; For example, if the user was empowered to enter values for the ARGB components then you might use an approach like the following: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; col&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; System.Windows.Media.Color&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;In reality the values below could be&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' selected by the user and passed in&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;col = Color.FromArgb(214, 122, 52, 24)&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; br&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; SolidColorBrush(col)&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Me&lt;/FONT&gt;.Background = br&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; It would also be quite easy to create a display in WPF where you bind, for example, sliders to the Brush that is used for the background. But I won't go any deeper into that just now, as this sub-set of blog items is meant only to help identify those missing WinForms favorites and repatriate them as WPF troops. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9191.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF: How To Hide the Minimize and Maximize Buttons</title><link>http://blogs.vbcity.com/xtab/archive/2008/10/22/9189.aspx</link><pubDate>Wed, 22 Oct 2008 08:17:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2008/10/22/9189.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9189.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9189.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2008/10/22/9189.aspx#comment</comments><slash:comments>3</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9189.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;For some time now, I've been promising myself that one day I will create a&amp;nbsp;&amp;nbsp;list of what I like&amp;nbsp;to&amp;nbsp;think of as "WPF MIA" - those basic elements&amp;nbsp;that I am totally familiar with in WindowsForms, but which somehow seem to have disappeared into thin air in WPF.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;In many cases of course the tools are still there; it's just that the name has changed.&amp;nbsp;&amp;nbsp; Here's an example:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;In Windows Forms, you can hide the Minimize and Maximize buttons by setting the MinimizeBox or MaximizeBox to False&amp;nbsp; I guess that this is most people's favourite way of doing this.&amp;nbsp;If you dig deeper into the Properties Window though, there is also the &amp;nbsp;FormBorderStyle property.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp; I used to think that this property was only good for things like changing&amp;nbsp;the border style, say, from 3D to single line.&amp;nbsp; But actually if you choose FixedToolWindow or SizableToolWindow then you automatically get a Form that only has the close button - no Min or Max.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp; So what about WPF then? Does it have the same properties available?&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;If you've spent any time on WPF, you'll know that that's really a rhetorical question because you can almost guarantee that things will have changed.&amp;nbsp;Now though&amp;nbsp;you have a WindowStyle property which you can use to set the Window's border style, including showing or hiding the Max and Min buttons.&amp;nbsp; To have those buttons hidden, you need to choose the &lt;STRONG&gt;ToolWindow&lt;/STRONG&gt; option.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp; As far as&amp;nbsp;I know, there isn't a property setting that will hide the individual buttons&amp;nbsp;in in WPF.&amp;nbsp; At first I found this a bit surprising.&amp;nbsp;&amp;nbsp; However,&amp;nbsp; as I've become more familiar with WPF and its ability to morph its Windows into almost any conceivable style and shape, I can see that creating your own Window style is so easy that maybe those properties would have been almost redundant anyway.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9189.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Use LINQ and Visual Basic 2008 to Get a List of Buttons from a Windows Forms Form</title><link>http://blogs.vbcity.com/mcintyre/archive/2008/10/19/9188.aspx</link><pubDate>Sun, 19 Oct 2008 20:50:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/mcintyre/archive/2008/10/19/9188.aspx</guid><wfw:comment>http://blogs.vbcity.com/mcintyre/comments/9188.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/mcintyre/comments/commentRss/9188.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/mcintyre/archive/2008/10/19/9188.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/mcintyre/services/trackbacks/9188.aspx</trackback:ping><source url="http://blogs.vbcity.com/mcintyre/rss.aspx">mike mcintyre's</source><description>&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;' Create a LINQ query.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; buttonQuery = &lt;SPAN style="COLOR: blue"&gt;From&lt;/SPAN&gt; control &lt;SPAN style="COLOR: blue"&gt;In&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Controls &lt;SPAN style="COLOR: blue"&gt;Where&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;TypeOf&lt;/SPAN&gt; (control) &lt;SPAN style="COLOR: blue"&gt;Is&lt;/SPAN&gt; Button&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' Create a list of object.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; buttonList = buttonQuery.ToList&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' Iterate through the objects in buttonList.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;For&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Each&lt;/SPAN&gt; btn &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; Button &lt;SPAN style="COLOR: blue"&gt;In&lt;/SPAN&gt; buttonList&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' Show each button's text property.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;MessageBox.Show(btn.Text)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Next&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/mcintyre/aggbug/9188.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Mike McIntyre [MVP Visual Basic]</dc:creator></item><item><title>Rename Files with the Visual Basic My Namespace Computer Object</title><link>http://blogs.vbcity.com/mcintyre/archive/2008/10/19/9187.aspx</link><pubDate>Sun, 19 Oct 2008 20:38:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/mcintyre/archive/2008/10/19/9187.aspx</guid><wfw:comment>http://blogs.vbcity.com/mcintyre/comments/9187.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/mcintyre/comments/commentRss/9187.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/mcintyre/archive/2008/10/19/9187.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/mcintyre/services/trackbacks/9187.aspx</trackback:ping><source url="http://blogs.vbcity.com/mcintyre/rss.aspx">mike mcintyre's</source><description>&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;My makes it easy to use .Net. &lt;/FONT&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;Here's an example that uses My to rename a file:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&lt;STRONG&gt;Syntax:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Shared&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; RenameFile ( _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt;, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newName &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt; _&lt;BR&gt;)&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;file is the file path to the file to be renamed.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;newName is the new name (with file extentsion) to be given to the file.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;My&lt;/FONT&gt;&lt;/FONT&gt;.Computer.FileSystem.RenameFile(&lt;FONT color=#a31515&gt;&lt;FONT color=#a31515&gt;"C:\OldName.txt"&lt;/FONT&gt;&lt;/FONT&gt;, &lt;FONT color=#a31515&gt;&lt;FONT color=#a31515&gt;"NewName.txt"&lt;/FONT&gt;&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;FONT size=2&gt;Mike McIntyre&lt;/FONT&gt;&lt;BR&gt;&lt;FONT size=2&gt;&lt;A href="http://www.getdotnetcode.com/"&gt;Get Dot Net Code&lt;/A&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/mcintyre/aggbug/9187.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Mike McIntyre [MVP Visual Basic]</dc:creator></item><item><title>Printing a Windows Foundation Presentation FlowDocument</title><link>http://blogs.vbcity.com/canoz/archive/2008/10/18/9184.aspx</link><pubDate>Sat, 18 Oct 2008 08:05:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/canoz/archive/2008/10/18/9184.aspx</guid><wfw:comment>http://blogs.vbcity.com/canoz/comments/9184.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/canoz/comments/commentRss/9184.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/canoz/archive/2008/10/18/9184.aspx#comment</comments><slash:comments>2</slash:comments><trackback:ping>http://blogs.vbcity.com/canoz/services/trackbacks/9184.aspx</trackback:ping><source url="http://blogs.vbcity.com/canoz/rss.aspx">CanOz Blog</source><description>&lt;P&gt;I have just discovered the most compelling reason to port over any projects I have to Windows Presentation Foundataion (WPF) as well as only starting new projects as a WPF project.&lt;/P&gt;
&lt;P&gt;The reason you ask?&amp;nbsp; Well the answer is one word.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size=5&gt;Printing&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Being a File I/O guy, printing has almost always needed to be a part of most projects that I have written so this is a really big thing for me.&amp;nbsp; Looking back printing with Visual Basic.NET was painful for me at times especially if the document spanned several pages and I don't even want to get into printing with pre .NET Visual Basic.&lt;BR&gt;That, however, is the past and today we take a look at the present and future.&lt;/P&gt;
&lt;P&gt;After creating a &lt;A href="http://blogs.vbcity.com/canoz/archive/2008/10/08/9182.aspx" target=blank&gt;table in a flowdocument&lt;/A&gt; I got to thinking about being ability to print out the flowdocument.&lt;/P&gt;
&lt;P&gt;The WPF PrintDialog class has two methods for printing.&amp;nbsp; The two methods are PrintVisual and PrintDocument.&lt;BR&gt;&lt;BR&gt;This post will deal with the PrintDocument method.&lt;/P&gt;
&lt;P&gt;When you use PrintDocument you don&amp;#8217;t actually pass the flowdocument that you want to print as a parameter, you use a DocumentPaginator object.&lt;/P&gt;
&lt;P&gt;What the documentpaginator does is take the content of the flowdocument and breaks it up into multiple pages (if required) then passes the page(s) to the printer to be printed out.&lt;/P&gt;
&lt;P&gt;After importing the necessary namespaces and declaring two Form level variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/001wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I started out with the code to create a flowdocument that goes over more than one page I used the following code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: #c8c8c8; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;' Create the parent FlowDocument...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; flowDoc = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; FlowDocument()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; table2 &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Table()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; flowDoc.Blocks.Add(table2)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.Columns.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableColumn)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.Columns.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableColumn)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.Columns.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableColumn)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.Columns.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableColumn)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Create and add an empty TableRowGroup to hold the table's Rows.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.RowGroups.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRowGroup())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Add the first (title) row.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.RowGroups(0).Rows.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRow())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Alias the current working row for easy reference.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; currentRow2 &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRow()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2 = table2.RowGroups(0).Rows(0)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; v &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Image&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; v.Source = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; BitmapImage(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Uri(&lt;SPAN style="COLOR: #a31515"&gt;"dice.jpg"&lt;/SPAN&gt;, UriKind.Relative))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; v.Height = 80&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; v.Width = 80&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Add cells with content to the second row.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Loan Report"&lt;/SPAN&gt;))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells(0).ColumnSpan = 3&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.FontSize = 50&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Foreground = Brushes.RosyBrown&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells(0).TextAlignment = TextAlignment.Center&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; BlockUIContainer(v)))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.RowGroups(0).Rows.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRow())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2 = table2.RowGroups(0).Rows(1)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;" For: Neil Knobbe, "&lt;/SPAN&gt; &amp;amp; Now.Date.ToLongDateString))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells(0).TextAlignment = TextAlignment.Center&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells(0).ColumnSpan = 4&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.RowGroups(0).Rows.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRow())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2 = table2.RowGroups(0).Rows(2)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Ammount Borrowed: Borrowed Variable"&lt;/SPAN&gt; &amp;amp; vbCrLf &amp;amp; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #a31515"&gt;"Monthly Payment: Payment Variable"&lt;/SPAN&gt; &amp;amp; vbCrLf &amp;amp; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #a31515"&gt;"Interest: Interest Variable"&lt;/SPAN&gt; &amp;amp; vbCrLf &amp;amp; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #a31515"&gt;"Duration: Duration Variable"&lt;/SPAN&gt; &amp;amp; vbCrLf &amp;amp; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #a31515"&gt;"Reason For Loan: Reason Varaible"&lt;/SPAN&gt; &amp;amp; vbCrLf &amp;amp; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #a31515"&gt;"Lender: Lender Variable"&lt;/SPAN&gt; &amp;amp; vbCrLf &amp;amp; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #a31515"&gt;"Loan Number: LoanNum Variable"&lt;/SPAN&gt;))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells(0).ColumnSpan = 2&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow2.Cells(0).Padding = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(10)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Create and add an empty TableRowGroup to hold the table's Rows.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.RowGroups.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRowGroup())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Add the first (title) row.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.RowGroups(1).Rows.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRow())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Alias the current working row for easy reference.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; currentRow &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRow()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow = table2.RowGroups(1).Rows(0)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Add the header row with content, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Date"&lt;/SPAN&gt;))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Balance"&lt;/SPAN&gt;))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Payment"&lt;/SPAN&gt;))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Interest"&lt;/SPAN&gt;))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(0).Foreground = Brushes.RosyBrown&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(0).TextAlignment = TextAlignment.Left&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(1).Foreground = Brushes.RosyBrown&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(1).TextAlignment = TextAlignment.Left&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(2).Foreground = Brushes.RosyBrown&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(2).TextAlignment = TextAlignment.Left&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(3).Foreground = Brushes.RosyBrown&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(3).TextAlignment = TextAlignment.Left&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.RowGroups(1).Rows.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRow())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow = table2.RowGroups(1).Rows(1)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(0).ColumnSpan = 4&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(0).BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(0, 5, 0, 0)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells(0).BorderBrush = Brushes.RosyBrown&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; i &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Integer&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;For&lt;/SPAN&gt; i = 2 &lt;SPAN style="COLOR: blue"&gt;To&lt;/SPAN&gt; 25&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; table2.RowGroups(1).Rows.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableRow())&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow = table2.RowGroups(1).Rows(i)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Column "&lt;/SPAN&gt; &amp;amp; i - 1 &amp;amp; &lt;SPAN style="COLOR: #a31515"&gt;" Entry - "&lt;/SPAN&gt; &amp;amp; i.ToString))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Column "&lt;/SPAN&gt; &amp;amp; i - 1 &amp;amp; &lt;SPAN style="COLOR: #a31515"&gt;" Entry - "&lt;/SPAN&gt; &amp;amp; i.ToString))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Column "&lt;/SPAN&gt; &amp;amp; i - 1 &amp;amp; &lt;SPAN style="COLOR: #a31515"&gt;" Entry - "&lt;/SPAN&gt; &amp;amp; i.ToString))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentRow.Cells.Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; TableCell(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Paragraph(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Run(&lt;SPAN style="COLOR: #a31515"&gt;"Column "&lt;/SPAN&gt; &amp;amp; i - 1 &amp;amp; &lt;SPAN style="COLOR: #a31515"&gt;" Entry - "&lt;/SPAN&gt; &amp;amp; i.ToString))))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Next&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ScrollView1.Document = flowDoc&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which, once I applied the table to a flowdocument and set the flowdocument to be the document of my FlowDocumentScrollViewer,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/01wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;gave me a table with 50 entries, shown in three columns, which I wanted to print.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/02wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now that the flowdocument was ready to print all that was left to do was create instance of a WPF PrintDialog and enter the one line of code needed to print the document.&lt;/P&gt;
&lt;P&gt;Yes you heard right, one line of code* to print a WPF flowdocument.&amp;nbsp; How much easier can it get?&amp;nbsp; (And I thought I was happy when the people at MS made reading the entire contents of a file into a single line of code for Visual Studio 2005.&amp;nbsp; I am simple ecstatic about this change to printing!)&lt;/P&gt;
&lt;P&gt;(* &lt;STRONG&gt;Note&lt;/STRONG&gt; &amp;#8211; Although you can accomplish printing with just this one line, there are a few gotchas that you will need to be aware of.&amp;nbsp; I will touch on some of these in a bit.)&lt;/P&gt;
&lt;P&gt;So, the magic line of code is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/03wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ok, I hear all you out there going "Ummm.... Neil that looks like 5 lines of code to me not one like you said."&amp;nbsp; Which would be a valid statement and it is true there is a couple more lines of code.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Basically what I have done is put the print code in an If...End If statement which gives displays the printdialog to the user where they can choose their printer and print the document or cancel the print job all together. &lt;BR&gt;&amp;nbsp;&lt;BR&gt;All in all six lines of code to print out a single or multiple page document is nothing.&lt;/P&gt;
&lt;P&gt;What is the code doing then? &lt;/P&gt;
&lt;P&gt;As I mentioned earlier a new instance of a printdialog is created.&amp;nbsp; The printdialog is the window that is shown where you can select which printer you want to print with and other printing options.&lt;/P&gt;
&lt;P&gt;The printdialog is shown as a dialog window and if the user clicks the "OK" button, the flowdocument is cast as a DocumentPaginator object which is used as the first parameter of the printdialog&amp;#8217;s PrintDocument.&amp;nbsp; The second parameter of the printdocument is the name of the document being printed.&amp;nbsp; This name is what is displayed in the print queue of the printer so you can uniquely identify what documents are lined up to be printed.&lt;/P&gt;
&lt;P&gt;The Else portion of the If...End If statement handles if the user clicks the "Cancel" button.&amp;nbsp; A simple message box is displayed letting the user know that the print job has been cancelled.&lt;/P&gt;
&lt;P&gt;That in a nutshell is all that you need to do to print a flowdocument in a WPF application.&lt;/P&gt;
&lt;P&gt;Now for the gotchas that caught me while I tried to print.&lt;/P&gt;
&lt;P&gt;#1)&amp;nbsp; Multiple columns.&amp;nbsp; Let me tell you I this one really got me.&amp;nbsp; When I first tried to print the flowdocument in the image above, I expected the print out to look like the window.&amp;nbsp; Such was not the case.&amp;nbsp; What I ended up with was the entire table printed out on two columns per page over the three pages* the printed document covered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/04wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This was not quite what I was expecting, but is apparently the default behaviour without having set any properties of the document to match the printer.&amp;nbsp; What I wanted was to have the table fill the entire width of the page.&lt;/P&gt;
&lt;P&gt;(* &lt;STRONG&gt;Note&lt;/STRONG&gt; - As a rather interesting side note here this is not what I got the first time I tried to print this flowdocument.&amp;nbsp; My first results were rather disappointing and I was very disillusioned with what I thought was going to be a much simplified printing process.&amp;nbsp; The image below is my first attempt at printing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/05wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see it ended up quite the mess.&amp;nbsp; What happened was that all three pages of the flowdocument got printed in two columns on one page.&amp;nbsp; (If you look real close at the left column you can see the header of the table in the background then the first 8 lines have been printed twice.)&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I can happily report that the fault with this lies with the printer and not how the WPF printdialog sent the document to the printer.&amp;nbsp; I have since tested several other printers and they all print as the multiple columns image.)&lt;/P&gt;
&lt;P&gt;Getting back on track and printing the document on only one column.&lt;/P&gt;
&lt;P&gt;The way to get around having multiple columns is to set the column width of the document to be printed prior to casting it as a documentpaginator object.&amp;nbsp; This is a simple process and requires only one line of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/06wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What this code does is sets the width of document in the scrollviewer to be the entire printable width of the page.&amp;nbsp; Now when the document is printed the table will span the width of the page.&lt;/P&gt;
&lt;P&gt;#2) Page size.&amp;nbsp; While perhaps not quite as important as multiple columns is getting the proper page size and margins for your printed output.&lt;/P&gt;
&lt;P&gt;You can set the bounds of your document to be printed by setting three properties of the document.&amp;nbsp; The three properties are the PrintableAreaHeight, PrintableAreaWidth and the Thickness.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The PrintableAreaHeight and PrintableAreaWidth properties are pretty self explanatory.&amp;nbsp; The Thickness is what is used for the margin.&amp;nbsp; The thickness can be set with a universal value which will be applied to all sides, or you can set pass different parameters for the margin on each side.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/07wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While it is not essential to set these three properties for printing it does ensure that your document fits the page or pages.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;So, with adding in the few lines of code from the two gotchas, I finally was able to print out the report and have it look as I wanted it to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/08wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The entire print code I used was:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/09wpfprinting.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There you have it a quick overview of printing in a WPF application.&amp;nbsp; As I said it is much easier and I have my doubts if I will ever look at starting another WinForms application.&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/canoz/aggbug/9184.aspx" width = "1" height = "1" /&gt;</description><dc:creator>V. Neil Knobbe</dc:creator></item><item><title>Tables in a Windows Presentation Foundation FlowDocument</title><link>http://blogs.vbcity.com/canoz/archive/2008/10/08/9182.aspx</link><pubDate>Wed, 08 Oct 2008 07:24:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/canoz/archive/2008/10/08/9182.aspx</guid><wfw:comment>http://blogs.vbcity.com/canoz/comments/9182.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/canoz/comments/commentRss/9182.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/canoz/archive/2008/10/08/9182.aspx#comment</comments><slash:comments>2</slash:comments><trackback:ping>http://blogs.vbcity.com/canoz/services/trackbacks/9182.aspx</trackback:ping><source url="http://blogs.vbcity.com/canoz/rss.aspx">CanOz Blog</source><description>&lt;P&gt;vbCity Leader (and Microsoft MVP) &lt;A href="http://blogs.vbcity.com/xtab/" target=blank&gt;Ged Mead&lt;/A&gt; showed how to create a FlowDocument in &lt;A href="http://www.devcity.net/Articles/351/1/article.aspx" target=blank&gt;his article&lt;/A&gt;&amp;nbsp;published on devCity.com.&lt;/P&gt;
&lt;P&gt;I got the challenge recently to display a data inserted in a table in a flowdocument.&amp;nbsp; So I embarked on my quest.&lt;/P&gt;
&lt;P&gt;I knew that what I wanted could be done because some quick testing with XAML I was easily able to add a table to my flowdocument.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/001WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Which gives an output like the following.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/01WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;My challenge, however, was that I needed to be able to do this with Visual Basic.NET code behind as the data that was to be displayed in the table was going to be read from a file.&lt;/P&gt;
&lt;P&gt;I made my first mistake almost immediately.&amp;nbsp; (Now that is probably not the best thing for me to admit when I am trying to convince everyone that I actually know what I am talking about, but hey, I am big enough to admit my mistakes.)&lt;/P&gt;
&lt;P&gt;The mistake I made was trying to use the wrong table.&amp;nbsp; I was able to create and insert the data from the file into the table I created with VB code, but when I tried to add the table to the flowdocument I couldn&amp;#8217;t.&amp;nbsp; No matter what I tried, I was just unable to add the table and after a couple of days, I finally gave up and asked for help.&amp;nbsp; Microsoft MVP Jay Harlow&amp;nbsp;quickly pointed me in the right direction.&lt;/P&gt;
&lt;P&gt;What the problem was is that there are more than one table that is accessible for use in the .NET Framework.&amp;nbsp; I was trying to use the table in the &lt;STRONG&gt;System.Web&lt;/STRONG&gt; Namespace, but in fact I needed to be using the table from the &lt;STRONG&gt;System.Windows.Documents&lt;/STRONG&gt; Namespace.&lt;/P&gt;
&lt;P&gt;Once I was referencing the correct table, the whole project came together quite nicely.&lt;/P&gt;
&lt;P&gt;(While the project I was doing required reading data from a file that will be outside the scope of this blog post.&amp;nbsp; In this post I will just be showing how to hardcode data into a table in a flowdocument.)&lt;/P&gt;
&lt;P&gt;The first thing that is needed is to Import the Namespace to give us access to use a table.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/02WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Next declare two form level variables.&amp;nbsp; One variable is declared as a flowdocument and the other is declared as a table.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/03WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;In the event you want to create the table in, I used the Initialized event of the form for this example, set the two variables to a new instance of a flowdocument and table respectively.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/04WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Now that there is a flowdocument and a table the table needs colums, rows and content for the table.&lt;/P&gt;
&lt;P&gt;The columns are the first things to be added to the table.&amp;nbsp; Columns are added to the collection, or array, of columns of the table.&amp;nbsp; For this example I am going to add four columns to the table.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/05WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;With the columns added, Rows can now be added to the table.&amp;nbsp; Like columns, rows are also held in an array of rows.&amp;nbsp; Where rows differ from columns is rows are actually part of RowGroups.&amp;nbsp; You can have several rows in a rowgroup and more than one rowgroup in a table. 
&lt;P&gt;So to start a new rowgroup must be added to the rowgroups of the table.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/06WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;and into that rowgroup a new row is added.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/07WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Although you still can&amp;#8217;t see it if you were to look at the form itself, the table now has four columns and one row.&amp;nbsp; Into the row Cells need to be added.&lt;/P&gt;
&lt;P&gt;At this point there is a great deal of possibilities to how what the table is going to look like.&amp;nbsp; While you can set some formatting for the table with changing the properties of the table and rows, you have much greater control over the look of the table by manipulating the properties of the cells.&lt;/P&gt;
&lt;P&gt;For this table I want to have a header that stretches across the entire top of the table, so while I can have four cells in the row (I can do this because I added four columns to the table earlier) only one is going to be added to the row.&amp;nbsp; The cell will then be made to stretch over the entire width of the table.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/08WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;There is quite a bit going on in the above line of code.&amp;nbsp; A new TableCell is added to the collection of cells of the row and to add content to the cell a new Paragraph is used as a parameter of the tablecell and a new Run of text is passed as a parameter of the paragraph.&lt;/P&gt;
&lt;P&gt;After adding what is going to be the title of the table, some formatting can be assigned.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/09WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;The first line of code above tells the cell to span the entire width of the four columns of the table.&amp;nbsp; (If you have worked with tables in Microsoft Word think of this process to be like merging cells in a table.) 
&lt;P&gt;The second line sets the size of the font to make the text stand out as a title and the third line centers the text in the cell.&amp;nbsp; (By default the text alignment of a table, row or cell is left.)&lt;/P&gt;The fourth line of code makes the font bold. 
&lt;P&gt;The fifth line of code sets the colour of the text in the cell and the sixth line gives the cell a colour for the background.&lt;/P&gt;If we add two more lines of code the table can be shown in the FlowDocumentReader. 
&lt;P&gt;The table is first added to the Blocks of the flowdocument that was declared at the beginning of our code then the flowdocument is assigned as the document of the FlowDocumentReader of the form.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/10WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;(&lt;STRONG&gt;Note&lt;/STRONG&gt;:&amp;nbsp; Interestingly enough it does not seem to matter where you place the code to add the table into the flowdocument and make the document of the reader to be your flowdocument.&amp;nbsp; The code can be added just after the declaration of the flowdocument and table or anywhere in the middle of the code that formats and populates the table.&amp;nbsp; Personally I put these two lines at the very end prior to displaying the flowdocument.)&lt;/P&gt;
&lt;P&gt;Now when the project is run, you can see the table starting to take shape.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/11WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Putting Headers for each column are next to be added to the table.&lt;/P&gt;
&lt;P&gt;A new row is added to the rowgroup of the table then four cells are added to the row with content also being added to each cell.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/12WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;You can see by the Index number of the rows that the new cells have been added to the second row.&amp;nbsp; Like all .NET arrays the rows array of a rowgroup, as is the rowgroup itself, are zero based so if you need to remember that the actual row number is one higher than the index number. 
&lt;P&gt;Running the project shows that the columns now have headers.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/13WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;The table is really starting to look like a table now.&lt;/P&gt;
&lt;P&gt;A line under the column headers keeps the data in the columns separated from the headers.&amp;nbsp; To accomplish this, a new row is added under the row of headers.&amp;nbsp; One cell is added to the row and it will span the four columns like the title cell does.&amp;nbsp; To make the line, the border property of the cell is going to be used.&amp;nbsp; The top border of the cell will be made larger and given a colour.&lt;/P&gt;
&lt;P&gt;To make the border thicker a New Thickness is applied to the cell.&amp;nbsp; Thickness can either be set by passing a single parameter to the new thickness, which would give the same thickness to all sides of the cell, or you can pass four parameters and assign separate thicknesses to each side.&amp;nbsp; While it does not make any difference to what I am demonstrating here, I have only assigned a thickness to the top border of the cell.&amp;nbsp; I could have just as easily assigned a uniform thickness to the cell.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/14WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Now the contents of the table will be separated from the column headers by a red line.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/15WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;With the formatting of the table set out, it is time to add some content into the table itself.&lt;/P&gt;
&lt;P&gt;For this example I am going to use a For&amp;#8230;Next Loop to populate the table.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/16WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Two Integer variables are declared.&amp;nbsp; The first is used to keep track of the index of the row in the rowgroup.&amp;nbsp; The variable is declared with a value of 3 because the first line that will be added in the loop will be the fourth element of the array of rows.&amp;nbsp; The second variable is just used for adding content to each of the cells as they are added to the row.&lt;/P&gt;
&lt;P&gt;In the loop the first line of code adds a new row to the table then the next four lines add the cells to the row and put some content in the cell.&amp;nbsp; In this example the content of the cells in the row will just have the text "Number: 0" to "Number: 97".&lt;/P&gt;
&lt;P&gt;In the last line the value of the variable j is incremented by 1 so the content number of the next row will be one higher than the last.&lt;/P&gt;
&lt;P&gt;Now when the project is run the table is complete.&amp;nbsp; The table starts with:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/17WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;
&lt;P&gt;and six pages later going to:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.neilknobbe.com/blogimages/18WPFFlowDocumentTable.jpg"&gt;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/canoz/aggbug/9182.aspx" width = "1" height = "1" /&gt;</description><dc:creator>V. Neil Knobbe</dc:creator></item></channel></rss>