<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>WPF: How To Move Controls and Elements At Runtime</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/27/9429.aspx</link><pubDate>Tue, 27 Oct 2009 11:23:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/27/9429.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9429.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9429.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/27/9429.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9429.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;p&gt;&lt;span style="font-family: Calibri;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;XAML is brilliant for creating user interfaces at design time, but if you need to make changes dynamically at runtime, this can sometimes be a problem. To take an example, let's say that you need to allow an Image to move to a different location on screen in response to some user action. &lt;/p&gt;
&lt;p&gt;To demonstrate this, we can use an Image which is housed in a Canvas. So the first step is to create a Canvas in a WPF Window, place the Image inside the Canvas and assign a value to the Source property of the Image:&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&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;="Window2"&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp; &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;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp; &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;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;Title&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="Image In A Canvas"&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"&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: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Canvas&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;="MainCanvas"&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: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Image&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;="MoveableImage"&lt;/span&gt;&lt;span style="color: #ff0000;"&gt; Width&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="55"&lt;/span&gt;&lt;span style="color: #ff0000;"&gt; Source&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="questionmark2.jpg" /&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: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Canvas&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: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Window&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;We can then have the Image move a few units to the right each time it receives a mouse click. The WPF Image doesn't support the Click event, but MouseDown is available for the same purpose. So the next step is to wire up an event handler for this:&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: #a31515;"&gt;&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; 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;="MoveableImage"&lt;/span&gt;&lt;span style="color: #ff0000;"&gt; Width&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="55"&lt;/span&gt;&lt;span style="color: #ff0000;"&gt; Source&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="questionmark2.jpg"&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #ff0000;"&gt;MouseDown&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="Image_MouseDown"&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Here's the first pass at the Image_MouseDown event in the code-behind to move the Image 10 units to the right on each mouse down:&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt; Image_MouseDown(&lt;span style="color: #0000ff;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; System.Object, &lt;span style="color: #0000ff;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; System.Windows.Input.MouseButtonEventArgs)&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: #0000ff;"&gt;Dim&lt;/span&gt; LeftPos &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Double&lt;/span&gt; = MoveableImage.GetValue(Canvas.LeftProperty)&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; MoveableImage.SetValue(Canvas.LeftProperty, LeftPos + 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; &lt;span style="color: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This seems straightforward enough, doesn't it? The variable named LeftPos reads the value that is currently stored as the attached Canvas.Left property of the Image, then it increments that value by 10. If you were to run this project, you would expect that the Image would jump 10 units to the right when the mouse is clicked on it. But if you try this code, you will find that nothing happens when the Image is clicked. &lt;/p&gt;
&lt;p&gt;There's a little WPF Gotcha lurking in the canvas, just waiting to confuse you. When you create this layout, as you can see from the screenshot below, the Image appears in the top left hand corner of the Canvas by default: &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&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/Blog_GetValue01.png" /&gt;&lt;/p&gt;
&lt;p&gt;You would be forgiven for assuming that the attached Canvas.Left and Canvas.Top values of the Image are set to zero. It's a reasonable assumption to make, especially as you can see the Image in exactly that location. However, it doesn't actually work like that. By default the Left and Top attached properties are in fact set to Double.NaN - Not A Number. This is effectively a null value that is assigned in order to allow the Canvas to make use of its own built-in layout intelligence for more complex scenarios. &lt;/p&gt;
&lt;p&gt;The fix is simple - you just have to assign values to the Canvas.Left and Canvas.Top properties in the XAML when you create the Image element, but it's something that isn't obvious. Not only does it mean that the expected movement of the Image doesn't happen, but it will actually cause your application to crash if you try and reset the value in code to move the Image back to the start position (which we will do later).&lt;/p&gt;
&lt;p&gt;So, here's the amended XAML for the Image:&amp;nbsp;&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: #a31515;"&gt;&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; 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;="MoveableImage"&lt;/span&gt;&lt;span style="color: #ff0000;"&gt; Width&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="55"&lt;/span&gt;&lt;span style="color: #ff0000;"&gt; Source&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="questionmark2.jpg"&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #ff0000;"&gt;MouseDown&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="Image_MouseDown"&lt;/span&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #ff0000;"&gt;Canvas.Left&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="0"&lt;/span&gt;&lt;span style="color: #ff0000;"&gt; Canvas.Top&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="0" /&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;With that change in place, the Image will now move when it is clicked. &lt;/p&gt;
&lt;p&gt;In this kind of situation, you probably won't want the Image to either get stuck at the right hand side of the Canvas or, possibly even worse, move out of sight. A simple If/Then statement will fix this:&amp;nbsp;&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;If&lt;/span&gt; LeftPos &amp;lt; (MainCanvas.ActualWidth - MoveableImage.Width) &lt;span style="color: #0000ff;"&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; MoveableImage.SetValue(Canvas.LeftProperty, LeftPos + 10)&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: #0000ff;"&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; MoveableImage.SetValue(Canvas.LeftProperty, &lt;span style="color: #0000ff;"&gt;CDbl&lt;/span&gt;(0))&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;If&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, the first line tests if there is still enough width remaining for the Image to be moved 10 elements to the right and still be visible. If there is, then the 10 unit jump takes place. If not, then the Image is shunted back to far left of the Canvas. Note that this will fail if you haven't set the initial value of the Canvas.Left property as described earlier. &lt;/p&gt;
&lt;p&gt;It will also fail if you don't cast the value (in this example, zero) to a Double. This is because the second parameter of the SetValue method is a generic Object Type and the Canvas.Left property requires a Double.&lt;/p&gt;
&lt;p&gt;Moving the Image downwards follows the same kind of logic. You set an initial value on the Canvas.Top property then increment this when the MouseDown event fires. Perhaps you want to build in a feature where the left mouse button causes the Image to move left and the right mouse button to move it down. &lt;/p&gt;
&lt;p&gt;If you are moving from Windows Forms to WPF, you may expect to find the Button property of the MouseEventArgs. You would then use code along the lines of:&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;If&lt;/span&gt; e.Button = Windows.Forms.MouseButtons.Left &lt;span style="color: #0000ff;"&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: #008000;"&gt;' Do Something&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: #0000ff;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;WPF is (again) slightly different. It uses the System.Windows.Input.MouseButtonEventArgs class in place of the Windows Forms version and it has a ChangedButton property, not a Button property. So the WPF version of the previous snippet will start with:&amp;nbsp;&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;If&lt;/span&gt; e.ChangedButton = MouseButton.Left &lt;span style="color: #0000ff;"&gt;Then&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The following code snippet combines the use of either the left or right mouse button to move the Image left or down respectively:&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt; Image_MouseDown(&lt;span style="color: #0000ff;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; System.Object, &lt;span style="color: #0000ff;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; System.Windows.Input.MouseButtonEventArgs)&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: #0000ff;"&gt;If&lt;/span&gt; e.ChangedButton = MouseButton.Left &lt;span style="color: #0000ff;"&gt;Then&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: #0000ff;"&gt;Dim&lt;/span&gt; LeftPos &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Double&lt;/span&gt; = MoveableImage.GetValue(Canvas.LeftProperty)&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: #0000ff;"&gt;If&lt;/span&gt; LeftPos &amp;lt; (MainCanvas.ActualWidth - MoveableImage.Width) &lt;span style="color: #0000ff;"&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; MoveableImage.SetValue(Canvas.LeftProperty, LeftPos + 10)&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: #0000ff;"&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; MoveableImage.SetValue(Canvas.LeftProperty, &lt;span style="color: #0000ff;"&gt;CDbl&lt;/span&gt;(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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&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;&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: #0000ff;"&gt;ElseIf&lt;/span&gt; e.ChangedButton = MouseButton.Right &lt;span style="color: #0000ff;"&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: #0000ff;"&gt;Dim&lt;/span&gt; TopPos &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Double&lt;/span&gt; = MoveableImage.GetValue(Canvas.TopProperty)&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: #0000ff;"&gt;If&lt;/span&gt; TopPos &amp;lt; (MainCanvas.ActualHeight - MoveableImage.Width) &lt;span style="color: #0000ff;"&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; MoveableImage.SetValue(Canvas.TopProperty, TopPos + 10)&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: #0000ff;"&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; MoveableImage.SetValue(Canvas.TopProperty, &lt;span style="color: #0000ff;"&gt;CDbl&lt;/span&gt;(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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;If&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Finally, of course, you can combine the horizontal and vertical movement of the Image - maybe by using the Middle mouse button:&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;ElseIf&lt;/span&gt; e.ChangedButton = MouseButton.Middle &lt;span style="color: #0000ff;"&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; MoveableImage.SetValue(Canvas.LeftProperty, MoveableImage.GetValue(Canvas.LeftProperty) + 10)&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; MoveableImage.SetValue(Canvas.TopProperty, MoveableImage.GetValue(Canvas.TopProperty) + 10)&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;If&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The above snippet can be expanded to have the tests for reaching the outer edges built in also.&lt;/p&gt;
&lt;p&gt;The main issues I particularly wanted to cover in this blog item were the GetValue and SetValue methods, which are a very useful tool in these kind of situations. I also wanted to flag up the various WPF Gotchas that might trip up the unwary WinForms developer. In a follow-up blog, I plan to take this task a step further and look at ways of giving the user several ways of achieving the Image movement - all of which loop back to a single piece of code &lt;/p&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9429.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Populating a WinForms ListView from a Text File</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/26/9428.aspx</link><pubDate>Mon, 26 Oct 2009 11:41:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/26/9428.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9428.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9428.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/26/9428.aspx#comment</comments><slash:comments>269</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9428.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;p&gt;&lt;span style="font-family: Calibri;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;The Windows Forms ListView is designed to display data. You can use a simple text file as the data source of a Windows Forms ListView. Let's start with a scenario where you have a txt file that contains the data. Each line of the text file represents one row of data to be displayed in the ListView. The content for each column item (or cell) is delimited by the use of a TAB character. &lt;/p&gt;
&lt;p&gt;A simple text file along these lines might contain the following entries: &lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;Ged Mead UK &lt;br /&gt;Serge Baranovsky&amp;nbsp;&amp;nbsp; &amp;nbsp;USA &lt;br /&gt;Larry Blake USA &lt;br /&gt;Scott Waletzko&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USA &lt;br /&gt;Mark Dryden UK &lt;br /&gt;Dave Jeavons UK &lt;br /&gt;Chris Manning USA &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;(The uneven layout is caused by the use of the TAB as the delimiter)&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;Reading data from a file&lt;/span&gt;&lt;br /&gt;An easy way of transferring this data from the file to the ListView is to: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use a StreamReader which accesses the text file and then reads it line by line. &lt;br /&gt;&lt;/li&gt;
&lt;li&gt;As each new line is read, it is split by means of the TAB character and temporarily stored in a String array. &lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Next, the first element is pulled out of the String array and used as the item for the first column of the ListView (the ListViewItem).&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Then the remaining two elements are pulled out of the String array in turn and assigned as the SubItems of the ListViewItem. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here's the code that carries out those steps: &lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp; &lt;span style="color: #008000;"&gt;' Variable for file to hold data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;Dim&lt;/span&gt; TextFile &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;String&lt;/span&gt; = &lt;span style="color: #a31515;"&gt;"F:\MVPs.txt"&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: #0000ff;"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt; btnGet_Click(&lt;span style="color: #0000ff;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; System.Object, &lt;span style="color: #0000ff;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: #0000ff;"&gt;Handles&lt;/span&gt; btnGet.Click&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: #0000ff;"&gt;Try&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: #008000;"&gt;' Declare StreamReader and pass the Path of the text file to be read as a Parameter &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: #0000ff;"&gt;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; StreamReader(TextFile)&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: #008000;"&gt;'&amp;nbsp; Variable to hold data as it is read line by line&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: #0000ff;"&gt;Dim&lt;/span&gt; strTemp() &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;String&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: #0000ff;"&gt;Do&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;While&lt;/span&gt; SR.Peek &amp;lt;&amp;gt; -1 &lt;span style="color: #008000;"&gt;' Use Peek to read the file until there are no more lines &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: #008000;"&gt;'&amp;nbsp; Create a variable for the ListViewItems&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: #0000ff;"&gt;Dim&lt;/span&gt; LVItem &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;New&lt;/span&gt; ListViewItem&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: #008000;"&gt;'&amp;nbsp; Read the next line in file and Split it using the TAB. &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; strTemp = SR.ReadLine.Split(Chr(9))&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: #008000;"&gt;'&amp;nbsp; Pull out the first element in the line and assign it as&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: #008000;"&gt;'&amp;nbsp; the data for the first column.&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; LVItem.Text = strTemp(0).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; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #008000;"&gt;'&amp;nbsp; Add the item to the ListView&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; LVMVPs.Items.Add(LVItem)&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: #008000;"&gt;'&amp;nbsp; Assign elements 2 &amp;amp; 3 as the subitems.&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; LVItem.SubItems.Add(strTemp(1).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; &amp;nbsp;&amp;nbsp;&amp;nbsp; LVItem.SubItems.Add(strTemp(2).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; &lt;span style="color: #0000ff;"&gt;Loop&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; SR.Close() &lt;span style="color: #008000;"&gt;' Close the StreamReader &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: #0000ff;"&gt;Catch&lt;/span&gt; ex &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; Exception&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; MsgBox(&lt;span style="color: #a31515;"&gt;"Error reading file."&lt;/span&gt; &amp;amp; ex.Message)&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Try&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You'll see that I've used a variable to hold the path to the file that contains the data. You will also need to include an Imports statement for System.IO at the top of the Class file.&lt;/p&gt;
&lt;p&gt;Although the above code will successfully access the file, read and split the data and then populate the ListView, the result you will see may not be what you expect or want: &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/Blog_LV_File01.png" /&gt;&lt;/p&gt;
&lt;p&gt;The first problem is that the View Property of the ListView needs to be set to Details. By default it is set to LargeIcon, with the result you see in the screenshot. You can make this change via the Properties Window or in code.&amp;nbsp;&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; LVMVPs.View = View.Details&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Make that change, run the project, hit the 'Get From File' button and you will see:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/Blog_LV_File02.png" /&gt;&lt;/p&gt;
&lt;p&gt;Again, definitely &lt;i&gt;not&lt;/i&gt; what you want! The problem here is that the ListView won't automatically create columns for you, even though you might expect that it would based on the data you are feeding in. As it is traditional to have some header text at the top of each column, you can create this at the same time as you create the column itself .&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; LVMVPs.Columns.Add(&lt;span style="color: #a31515;"&gt;"First Name"&lt;/span&gt;, 76)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; LVMVPs.Columns.Add(&lt;span style="color: #a31515;"&gt;"Surname"&lt;/span&gt;, 96)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; LVMVPs.Columns.Add(&lt;span style="color: #a31515;"&gt;"Location"&lt;/span&gt;, 56)&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now, when you run the project again you will see the data neatly tabulated in the ListView.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/Blog_LV_File03.png" /&gt;&lt;/p&gt;
&lt;p&gt;I have also set the width property of each column in the code above, because the default width would result in some of the longer strings being truncated otherwise.&lt;/p&gt;
&lt;p&gt;If you don't want to hard code those column headers, you can change the text file structure and have the column headers written to the first line of the file. You would then pull these out first and assign them to the columns, before using the Do While loop to read and display the rest of the file. &lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;Writing data to a file&lt;/span&gt;&lt;br /&gt;Although a ListView's key purpose is to display existing data, there may be times when you have edited the content and want to save it back to a text file. The steps involved in doing this are as follows: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use a FileStream to set up the file you are going to write to. &lt;/li&gt;
&lt;li&gt;Use a StreamWriter to access the chosen file. &lt;/li&gt;
&lt;li&gt;Loop through each row of the ListView, pull the text data from each column in turn and write it to the text file, adding a TAB character after each item. &lt;/li&gt;
&lt;li&gt;Add a new line at the end of each loop.&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The code for this process is:&lt;/p&gt;
&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt; btnSave_Click(&lt;span style="color: #0000ff;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; System.Object, &lt;span style="color: #0000ff;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: #0000ff;"&gt;Handles&lt;/span&gt; btnSave.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: #008000;"&gt;'&amp;nbsp; Create FileStream and StreamWriter to access and write to file&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: #0000ff;"&gt;Dim&lt;/span&gt; FS &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;New&lt;/span&gt; FileStream(TextFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)&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: #0000ff;"&gt;Dim&lt;/span&gt; SW &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;New&lt;/span&gt; StreamWriter(FS)&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: #0000ff;"&gt;Try&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: #008000;"&gt;'&amp;nbsp; Loop through all 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; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;For&lt;/span&gt; Index &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Integer&lt;/span&gt; = 0 &lt;span style="color: #0000ff;"&gt;To&lt;/span&gt; LVMVPs.Items.Count - 1&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: #008000;"&gt;'&amp;nbsp; Internally loop through all columns, gathering items&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: #0000ff;"&gt;For&lt;/span&gt; SubIndex &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Integer&lt;/span&gt; = 0 &lt;span style="color: #0000ff;"&gt;To&lt;/span&gt; LVMVPs.Items(Index).SubItems.Count - 1&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; SW.Write(LVMVPs.Items(Index).SubItems(SubIndex).Text &amp;amp; Chr(9))&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: #0000ff;"&gt;Next&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: #008000;"&gt;'&amp;nbsp; Create new line ready for next 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; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SW.Write(Environment.NewLine)&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: #0000ff;"&gt;Next&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: #0000ff;"&gt;Catch&lt;/span&gt; ex &lt;span style="color: #0000ff;"&gt;As&lt;/span&gt; Exception&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; MsgBox(&lt;span style="color: #a31515;"&gt;"Error saving to file."&lt;/span&gt; &amp;amp; ex.Message)&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: #0000ff;"&gt;Finally&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; SW.Close()&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; FS.Close()&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Try&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: #0000ff;"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;Sub&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;For many simple scenarios where you want to display tabulated text in a ListView (and optionally save it back to a file), the above approaches will work just fine. There will of course be times when you need something more sophisticated and I will look at some of those in later blogs.&lt;/p&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9428.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>How To Sort and Group Items in a WPF ListBox: Part 2</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/25/9425.aspx</link><pubDate>Sun, 25 Oct 2009 12:26:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/25/9425.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9425.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9425.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/25/9425.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9425.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: Calibri"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Introduction&lt;/SPAN&gt;&lt;BR&gt;In the &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/09/26/how-to-sort-and-group-listitems-in-a-wpf-listbox.aspx"&gt;first part&lt;/A&gt;, I outlined the sample application and said that it: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;will create a collection of Person objects and databind them to a ListBox. 
&lt;LI&gt;will use very simple DataTemplates to format two properties of the Person class - FullName and Status. 
&lt;LI&gt;will use a GroupStyle HeaderTemplate to display a third property of the Person class - Category. 
&lt;LI&gt;groups the Person objects by their Category property. 
&lt;LI&gt;sorts the Categories and displays them in alphabetical order. 
&lt;LI&gt;sorts the Persons by name inside the Category groups and displays them in alphabetical order.&amp;nbsp;&amp;nbsp; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The first five tasks are all covered in that previous part. You can download the project up to this point from &lt;A href="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/GroupAndSort_Blog.zip"&gt;here&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Sorting the Categories&lt;/SPAN&gt;&lt;BR&gt;In the same way that I used a Group Description to group items together, WPF offers the SortDescription to allow data inside the CollectionView to be sorted. The following code in the Window Loaded event is all that's needed: &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView.SortDescriptions.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; SortDescription(&lt;SPAN style="COLOR: #a31515"&gt;"Category"&lt;/SPAN&gt;, ListSortDirection.Ascending))&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The SortDescription takes two parameters. The first is the name of the property that you want to sort on. The second is one of two choices for the sort direction.&lt;/P&gt;
&lt;P&gt;For completeness, this is the full code so far in the Window Loaded event (which creates the DataContext, the View, the GroupDescription and the SortDescription):&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt; Window1_Loaded(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Windows.RoutedEventArgs) &lt;SPAN style="COLOR: #0000ff"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;.Loaded&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Contacts = Person.GetPersons&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: #0000ff"&gt;Me&lt;/SPAN&gt;.DataContext = Contacts&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: #0000ff"&gt;Dim&lt;/SPAN&gt; currentView &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; ICollectionView&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView = CollectionViewSource.GetDefaultView(Contacts)&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: #008000"&gt;'&amp;nbsp; Group&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView.GroupDescriptions.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; PropertyGroupDescription(&lt;SPAN style="COLOR: #a31515"&gt;"Category"&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: #008000"&gt;'&amp;nbsp;&amp;nbsp; Sort Categories&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView.SortDescriptions.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; SortDescription(&lt;SPAN style="COLOR: #a31515"&gt;"Category"&lt;/SPAN&gt;, ListSortDirection.Ascending))&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The sorted Categories will look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/SortGroup6.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Sorting the ListItems&lt;/SPAN&gt;&lt;BR&gt;As you can see, the Categories are now in alphabetical order. The names of the Person objects however are still shown in the relative order in which they were created. To create this secondary sort, the same kind of code is used: &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView.SortDescriptions.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; SortDescription(&lt;SPAN style="COLOR: #a31515"&gt;"FullName"&lt;/SPAN&gt;, ListSortDirection.Ascending))&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The resulting display is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/SortGroup7.png"&gt;&lt;/P&gt;
&lt;P&gt;The clearest example is where you can see the three items in the 'Work Colleagues' Category. They are now sorted alphabetically. &lt;BR&gt;&lt;BR&gt;Note that the order that you list the sorting tasks is important. If you were to reverse the order:&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #008000"&gt;'&amp;nbsp;&amp;nbsp; Sort individual names&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView.SortDescriptions.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; SortDescription(&lt;SPAN style="COLOR: #a31515"&gt;"FullName"&lt;/SPAN&gt;, ListSortDirection.Ascending))&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: #008000"&gt;'&amp;nbsp;&amp;nbsp; Sort Categories&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView.SortDescriptions.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; SortDescription(&lt;SPAN style="COLOR: #a31515"&gt;"Category"&lt;/SPAN&gt;, ListSortDirection.Ascending))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;You would effectively lose the Category sort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/SortGroup8.png"&gt;&lt;/P&gt;
&lt;P&gt;It is possible to create and apply the grouping and sorting in XAML, but I always try as far as possible to handle these kind of tasks in code-behind. Equally, I try and use XAML for the actual graphical display. There isn't a clear line between the two sometimes, of course, and you have to allow for individual preferences, but I try and keep to this approach as a general rule. &lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9425.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>How To Sort and Group ListItems in a WPF ListBox</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/25/9424.aspx</link><pubDate>Sun, 25 Oct 2009 12:25:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/25/9424.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9424.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9424.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/25/9424.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9424.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: Calibri"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Introduction&lt;/SPAN&gt;&lt;BR&gt;I was going to title this blog "What's in a name?" because William Shakespeare's famous question smacked me on the head recently after what seemed like&amp;nbsp;several hours of frustration. The answer in this particular case is "Quite a lot!". As you'll see when I cover the syntax used to group items, you can very easily fall into a trap when it comes to names. &lt;/P&gt;
&lt;P&gt;But first, I'll need to set the scene. This small application: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;will create a collection of Person objects and databind them to a ListBox. 
&lt;LI&gt;will use very simple DataTemplates to format two properties of the Person class - FullName and Status. 
&lt;LI&gt;will use a GroupStyle HeaderTemplate to display a third property of the Person class - Category. 
&lt;LI&gt;groups the Person objects by their Category property. 
&lt;LI&gt;sorts the Categories and displays them in alphabetical order. 
&lt;LI&gt;sorts the Persons by name inside the Category groups and displays them in alphabetical order. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN style="TEXT-DECORATION: underline"&gt;The Person Class&lt;/SPAN&gt;&lt;BR&gt;First, the Person Class - which I have chosen to implement INotifyPropertyChanged, although I don't actually take advantage of the change notification in this simple example: &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Imports&lt;/SPAN&gt; System.ComponentModel&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Imports&lt;/SPAN&gt; System.Collections.ObjectModel&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt; Person&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; INotifyPropertyChanged&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: #0000ff"&gt;Sub&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; personname &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; personstatus &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; personsgroup &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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: #0000ff"&gt;Me&lt;/SPAN&gt;.FullName = personname&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: #0000ff"&gt;Me&lt;/SPAN&gt;.Status = personstatus&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: #0000ff"&gt;Me&lt;/SPAN&gt;.Category = personsgroup&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;Private&lt;/SPAN&gt; _name &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; FullName() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _name&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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; _name = 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; OnPropertyChanged(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; PropertyChangedEventArgs(&lt;SPAN style="COLOR: #a31515"&gt;"FullName"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; _status &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; Status() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _status&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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; _status = 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; OnPropertyChanged(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; PropertyChangedEventArgs(&lt;SPAN style="COLOR: #a31515"&gt;"Status"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; _Category &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; Category() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _Category&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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; _Category = 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; OnPropertyChanged(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; PropertyChangedEventArgs(&lt;SPAN style="COLOR: #a31515"&gt;"Category"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt; OnPropertyChanged(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; PropertyChangedEventArgs)&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: #0000ff"&gt;If&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Not&lt;/SPAN&gt; PropertyChangedEvent &lt;SPAN style="COLOR: #0000ff"&gt;Is&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Nothing&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;RaiseEvent&lt;/SPAN&gt; PropertyChanged(&lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;, e)&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&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: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Event&lt;/SPAN&gt; PropertyChanged(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.ComponentModel.PropertyChangedEventArgs) &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; System.ComponentModel.INotifyPropertyChanged.PropertyChanged&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: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Shared&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; GetPersons() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; Person)&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: #0000ff"&gt;Dim&lt;/SPAN&gt; GP &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; Person)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Neil Birch"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Available"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"My Friends"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Joe Brown"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"On Site"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Work Colleagues"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Larry Blake"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Available"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"VB City"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Fran Mead"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"At Work"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Family"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Elaine Javan"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"On Vacation"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Work Colleagues"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Matt Higginbotham"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"On Line"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"VB City"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Zoe Flint"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"On Site"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Work Colleagues"&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: #0000ff"&gt;Return&lt;/SPAN&gt; GP&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Essentially, all you need to note for the purpose of this article is that the GetPersons function creates a List (of Person) and each Person instance has values assigned to all three of the properties of the class - FullName, Status, and Category. &lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;The WPF Window&lt;/SPAN&gt;&lt;BR&gt;The WPF Application contains just one Window. A List of Persons is created by using the GetPersons function and this List is used as the DataContext for the Window. This will allow the ListBox to access that List. The initial code-behind is as follows: &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt; Window1&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Dim&lt;/SPAN&gt; Contacts &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; Person)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt; Window1_Loaded(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Windows.RoutedEventArgs) &lt;SPAN style="COLOR: #0000ff"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;.Loaded&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Contacts = Person.GetPersons&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: #0000ff"&gt;Me&lt;/SPAN&gt;.DataContext = Contacts&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;The ListBox&lt;/SPAN&gt;&lt;BR&gt;In the XAML for Window1, there is a ListBox. To begin with, this ListBox simply shows the Person's FullName, followed by their Status. There is a minimal amount of formatting in the two TextBlocks that are used for this. &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="lstContacts"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;}"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="6,6,3,3" &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;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox.ItemTemplate&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;DataTemplate&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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=FullName}"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,2,0,0"/&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; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Status}"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="6,0,0,0"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="11"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Navy"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox.ItemTemplate&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The result so far is this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/SortGroup5.png"&gt;&lt;/P&gt;
&lt;P&gt;Obviously, there is no sorting or grouping going on there yet.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;CollectionView &lt;/SPAN&gt;&lt;BR&gt;When you set up the Binding between the data source (the List of Persons) and the target control (the ListBox), a CollectionView is created automatically. This is a wrapper for the binding and allows you to sort, filter, group or navigate through the collection without affecting the underlying collection itself. Think of it as an editable snapshot of the data and you won't be far off the mark &lt;/P&gt;
&lt;P&gt;You can access the current view by using the GetDefaultView method and passing in the name of the data source - in this case, the Contacts List created in the code-behind of Window1. In our example, we will access the CollectionView and then group and sort the items as they are displayed in the ListBox. To try and keep things as straightforward as possible I'll tackle each of these one at a time. &lt;/P&gt;
&lt;P&gt;Creation of an instance of the view by means of the GetDefaultView method is simple.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Imports&lt;/SPAN&gt; System.ComponentModel&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt; Window1_Loaded(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Windows.RoutedEventArgs) &lt;SPAN style="COLOR: #0000ff"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;.Loaded&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Contacts = Person.GetPersons&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: #0000ff"&gt;Me&lt;/SPAN&gt;.DataContext = Contacts&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: #0000ff"&gt;Dim&lt;/SPAN&gt; currentView &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; ICollectionView&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView = CollectionViewSource.GetDefaultView(Contacts)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Note the inclusion of the Imports statement for System.ComponentModel, the class which houses ICollectionView. &amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;It's the final two lines of the Window_Loaded event that create the View: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/SortGroup2.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Grouping&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;The following line of code, placed in the Window_Loaded event, will group the individual items based on the Category property:&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentView.GroupDescriptions.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; PropertyGroupDescription(&lt;SPAN style="COLOR: #a31515"&gt;"Category"&lt;/SPAN&gt;))&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The result is shown below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/SortGroup3.png"&gt;&lt;/P&gt;
&lt;P&gt;So I don't have to be much of a mind reader to know that you're not too impressed at this point. In fact, you probably don't even believe that the items &lt;I&gt;are&lt;/I&gt; now grouped. And even if they are, it's not very obvious to the user.&lt;/P&gt;
&lt;P&gt;Let's start with the question of whether they are really grouped. &amp;nbsp;&amp;nbsp;If you look carefully at the order of the names you will see that they have changed from the way they were originally listed - as seen in the earlier screenshot. And if you take a peek at the code which created the Person instances you will be able to see the value of the Category property for each instance.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Shared&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; GetPersons() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; Person)&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: #0000ff"&gt;Dim&lt;/SPAN&gt; GP &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; Person)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Neil Birch"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Available"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"My Friends"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Joe Brown"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"On Site"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Work Colleagues"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Larry Blake"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Available"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"VB City"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Fran Mead"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"At Work"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Family"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Elaine Javan"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"On Vacation"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Work Colleagues"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Matt Higginbotham"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"On Line"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"VB City"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GP.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; Person(&lt;SPAN style="COLOR: #a31515"&gt;"Zoe Flint"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"On Site"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Work Colleagues"&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: #0000ff"&gt;Return&lt;/SPAN&gt; GP&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Now, you can see that the first Category is "My Friends" and Neil Birch is the sole member of that Category. More usefully, the next three instances - Joe Brown, Elaine Javan and Zoe Flint all have "Work Colleagues" as their Category. They are now all listed consecutively - and both Elaine Javan and Zoe Flint have been moved from their original positions.&lt;/P&gt;
&lt;P&gt;The next two names - Larry Blake and Matt Higginbotham are both in the "VB City" Category. Fran Mead is the sole member of the "Family" Category.&lt;/P&gt;
&lt;P&gt;So, the grouping has actually taken place. The order of the Categories is based on the order in which they first appear in the GetPersons function.&lt;/P&gt;
&lt;P&gt;Clearly, we need something to make the grouping of Categories more obvious. And that 'something' is a GroupStyle. GroupStyle has a HeaderTemplate property which can be used to format the text and/or graphics that are displayed at the start of each group - in this case at the start of each Category. &lt;/P&gt;
&lt;P&gt;The XAML is a little bit verbose, but - apart from one potential Gotcha - is straightforward.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;ListBox.GroupStyle&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;GroupStyle&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;GroupStyle.HeaderTemplate&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;DataTemplate&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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Name}"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"/&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GroupStyle.HeaderTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GroupStyle&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox.GroupStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The GroupStyle has a HeaderTemplate. The HeaderTemplate contains a DataTemplate. In this case I have chosen to include only a basic TextBlock in the DataTemplate. The Text property of the TextBlock needs to show the Category name. &lt;/P&gt;
&lt;P&gt;This is where I managed to get myself quite confused. &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Name}"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;I initially had a property in the Person class called Name. (I've since changed it to FullName for clarity.) I couldn't understand why the Path of a TextBlock that showed the Category value would be pointing to the Name property of Person class. And of course it doesn't. But, while I was getting to grips with this I set the path to what I thought was the most logical item - the Category property. In other words, I had it like this:&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Category}"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Now, WPF is so forgiving when it comes to this kind of data binding that it doesn't throw an exception (quite rightly, because it is a valid path to an existing field). Sadly it doesn't show the Categories either. The result at this point is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/SortGroup4.png"&gt;&lt;/P&gt;
&lt;P&gt;You can see that they are grouped, but there's no header. &amp;nbsp;&amp;nbsp;The key lesson to take away from this is that the Path in that particular binding points to the name that is assigned to the PropertyGroupDescription in the code-behind: &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; currentView.GroupDescriptions.Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; PropertyGroupDescription(&lt;SPAN style="COLOR: #a31515"&gt;"Category"&lt;/SPAN&gt;))&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Confused yet? Put simply, you always use the syntax of: &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Name}"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;regardless of what the actual &lt;I&gt;name&lt;/I&gt; of the grouping property is. You're probably thinking that we're well into the "Too much information" stage now, but - apart from wanting to share my pain - I really think that this is Gotcha that is just waiting to bite the unwary and so it was worth spending a couple of extra minutes looking at it.&lt;/P&gt;
&lt;P&gt;OK, so getting back on track, the correct version of the GroupStyle markup will bring you the result you want. I have included all the ListBox XAML so you can see the finished product: &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="lstContacts"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;}"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="6,6,3,3" &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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox.GroupStyle&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;GroupStyle&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;GroupStyle.HeaderTemplate&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;DataTemplate&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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Name}"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"/&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GroupStyle.HeaderTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GroupStyle&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox.GroupStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox.ItemTemplate&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;DataTemplate&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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=FullName}"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,2,0,0"/&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; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Status}"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="6,0,0,0"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="11"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Navy"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox.ItemTemplate&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Here it is: &lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/SortGroup5.png"&gt;&lt;/P&gt;
&lt;P&gt;The grouping is clear, has a useful header and - more to the point - is accurate. The Categories are not yet in alphabetical order. The individual Person instances are also not sorted within their Categories, as you can see from the order in the Work Colleagues group. &lt;/P&gt;
&lt;P&gt;As this blog has become a bit longer than I expected, I will continue with a &lt;A class=null href="http://cs.vbcity.com/blogs/xtab/archive/2009/09/27/sorting-and-grouping-items-in-a-wpf-listbox-part-2.aspx"&gt;Part 2&lt;/A&gt;, which will cover the Sorting methods.&lt;/P&gt;
&lt;P&gt;I have posted a copy of this project which you can download from &lt;A href="http://www.xtabvbcity.plus.com/Blogs/WPFSortGroup/GroupAndSort_Blog.zip"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&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/9424.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF ValueConverter Using Enumeration and Image Paths</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/25/9423.aspx</link><pubDate>Sun, 25 Oct 2009 12:22:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/25/9423.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9423.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9423.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/25/9423.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9423.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the previous blogs on ValueConverters - &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/09/20/using-a-valueconverter-in-wpf.aspx"&gt;here&lt;/A&gt; and &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/09/20/more-complex-conversions-with-the-wpf-multibinding-converter.aspx"&gt;here&lt;/A&gt; - the conversion was from Integer type to Brush. In this blog I will cover the situation where you want to include a small image or icon in the ListView. &lt;BR&gt;&lt;BR&gt;There are various alternatives here. You could hard code the image path into the collection, but the problem may be that you don't know the exact image paths at the time the collection is created. The approach I want to use is where you parse the data as it feeds through the binding and you select a stored image from the hard drive, the selection being based on the value of a specific field. This decouples the details of the image from the collection itself, which may be useful in many situations.&lt;/P&gt;
&lt;P&gt;The DrinkProduct class looks like this:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt; DrinkProduct&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Enum&lt;/SPAN&gt; MaterialType&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Granules&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Leaf&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Liquid&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Paste&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Powder&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Other&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Enum&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; ID &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; Name &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; PackType &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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: #0000ff"&gt;ByVal&lt;/SPAN&gt; BaseMaterial &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; MaterialType, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; Sales &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; Qty &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&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: #0000ff"&gt;Me&lt;/SPAN&gt;.ProductID = ID&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: #0000ff"&gt;Me&lt;/SPAN&gt;.ProductName = Name&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: #0000ff"&gt;Me&lt;/SPAN&gt;.PackageType = PackType&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: #0000ff"&gt;Me&lt;/SPAN&gt;.Material = BaseMaterial&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: #0000ff"&gt;Me&lt;/SPAN&gt;.AnnualSales = Sales&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: #0000ff"&gt;Me&lt;/SPAN&gt;.Quantity = Qty&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;Private&lt;/SPAN&gt; _ProductID &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; ProductID() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _ProductID&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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; _ProductID = value&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; _ProductName &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; ProductName() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _ProductName&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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; _ProductName = value&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; _PackageType &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; PackageType() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _PackageType&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;String&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; _PackageType = value&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;Private&lt;/SPAN&gt; _Material &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; MaterialType&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; Material() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; MaterialType&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _Material&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; MaterialType)&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; _Material = value&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; _quantity &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; Quantity() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _quantity&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&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; _quantity = value&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;Private&lt;/SPAN&gt; _annualsales &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Property&lt;/SPAN&gt; AnnualSales() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&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: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; _annualsales&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&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; _annualsales = value&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Shared&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; StockCheck() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; DrinkProduct)&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: #0000ff"&gt;Dim&lt;/SPAN&gt; CurrentProducts &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; DrinkProduct)&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: #0000ff"&gt;With&lt;/SPAN&gt; CurrentProducts&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"CF1kg"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Coffee Powder"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"1 Kg"&lt;/SPAN&gt;, MaterialType.Powder, 15684, 1276))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"CFB500"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Ground Coffee"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&lt;/SPAN&gt;, MaterialType.Powder, 22785, 12856))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"CFG500"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Coffee Granules"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&lt;/SPAN&gt;, MaterialType.Granules, 19233, 5907))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Te500"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Tea"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&lt;/SPAN&gt;, MaterialType.Leaf, 8544, 235))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"TeInst500"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Instant Tea"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&lt;/SPAN&gt;, MaterialType.Powder, 1009, 22))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"SMlk1lt"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Skimmed Milk"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"1 Litre"&lt;/SPAN&gt;, MaterialType.Liquid, 28012, 2650))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"HiJ300"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"HiJuice Drink Mix"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"300 g"&lt;/SPAN&gt;, MaterialType.Other, 578, 179))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Sm400"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Smoothie"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"400ml"&lt;/SPAN&gt;, MaterialType.Paste, 9346, 3284))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Beef300"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Beef Drink"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"300 g"&lt;/SPAN&gt;, MaterialType.Granules, 8316, 1965))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Beef750"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Beef Drink"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"750 g"&lt;/SPAN&gt;, MaterialType.Granules, 7612, 359))&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; CurrentProducts&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The Enumeration named 'MaterialType' identifies whether the product is powder, liquid, granule, etc and this is what I will use as the key for selecting the appropriate image. &lt;/P&gt;
&lt;P&gt;The ValueConverter class is similar to those used in the previous blogs - IValueConverter requires the two methods named Convert and ConvertBack. ConvertBack serves no purpose is this scenario, so only throws a not implemented exception.&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt; MaterialToImagePathConverter&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; IValueConverter&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: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; Convert(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; targetType &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Type, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; parameter &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; culture &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Globalization.CultureInfo) &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; System.Windows.Data.IValueConverter.Convert&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: #0000ff"&gt;Select&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Case&lt;/SPAN&gt; value.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; &lt;SPAN style="COLOR: #0000ff"&gt;Case&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Powder"&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: #0000ff"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Images/powderbrown.jpg"&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: #0000ff"&gt;Case&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Liquid"&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: #0000ff"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Images/liquiddrop4.jpg"&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: #0000ff"&gt;Case&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Leaf"&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: #0000ff"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Images/leaf.jpg"&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: #0000ff"&gt;Case&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Granules"&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: #0000ff"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Images/granules.jpg"&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: #0000ff"&gt;Case&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Paste"&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: #0000ff"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Images/Paste2.jpg"&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: #0000ff"&gt;Case&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;SPAN style="COLOR: #0000ff"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"Images/questionmark.jpg"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; ConvertBack(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; targetType &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Type, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; parameter &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; culture &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Globalization.CultureInfo) &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; System.Windows.Data.IValueConverter.ConvertBack&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: #0000ff"&gt;Throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; NotImplementedException()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;As before, the parameter named 'value' is an Object type which is the key element in the conversion process. It contains the value that is to be converted. The conversion is simple in this case because all we need is to find the string value of the enumeration that is being passed in. So the basic ToString method will work fine. &lt;/P&gt;
&lt;P&gt;Once we have a String value, this is compared against the various possibilities. A string which represents the file path to an appropriate image is returned by the converter. I've chosen to include the image files in the project, but of course they could be stored externally and still be accessed in the same way. &lt;/P&gt;
&lt;P&gt;The next steps are the same as for the previous examples in the earlier blogs. First, map the current assembly to an XML namespace in Application.xaml:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &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;local&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="clr-namespace:WPFListView2"&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Then create an instance of the converter class in Application.xaml and give it a key:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;local&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;MaterialToImagePathConverter&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IconConverter" /&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Next, create a DataTemplate for the new column of the ListView:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IconCellTemplate"&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;Image&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,0,1,3"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="18"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="25"&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;Stretch&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Fill"&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Material,&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Converter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;={&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IconConverter&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;In the above markup, the Binding Path is the Material field, the converter is the MaterialToImagePathConverter instance created above.&lt;/P&gt;
&lt;P&gt;Finally, the ListView in the Window needs to have a new column added in which the images can be displayed:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;GridViewColumn&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;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IconCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;And now you are all set. The finished Window displays as shown below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/ValueConverter/ValCon_005.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For completeness, the full markup for the Window which contains the ListView is shown here:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&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;="Window2"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &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;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &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;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;Title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Image Path Converter Demo"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="360"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="450"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductsListView"&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;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="5" &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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&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;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ListViewItem"&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;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="HorizontalContentAlignment"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Stretch" /&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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;GridView&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: #008000"&gt;&lt;!-- Icon column --&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;GridViewColumn&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;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IconCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Product ID --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;}"&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;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Product Name --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Pack Size --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackageColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&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: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Of course you are not forced to use the ValueConverter approach for this task. You could rewrite the class and give it an ImagePath property. Then in the code-behind run a function with a similar Select Case block to the one used above, passing back the appropriate path to the ImagePath property. The collection would be amended on the fly to include this data and finally the amended collection would be used as the DataContext. The Binding Path for the Image Source property would be that field. Personally, I think the ValueConverter is neater. And if the data comes from an external source, perhaps in the form of an XML file, then using the ValueConverter is almost certainly a better way.&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&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/9423.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>How To Insert Row Divider Lines in a WPF ListView</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/25/9422.aspx</link><pubDate>Sun, 25 Oct 2009 12:21:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/25/9422.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9422.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9422.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/25/9422.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9422.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: Calibri"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;If you have read any of my previous ListView blogs, you will know that formatting the ListView is mostly a matter of creating templates and styles for the various sub-elements. The same applies if you want to do something to differentiate one row from another. For instance, you might to have horizontal divider lines between each row. &lt;/P&gt;
&lt;P&gt;This is the look we are going for in this blog:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV5-001.png"&gt;&lt;/P&gt;
&lt;P&gt;The column headers were described in &lt;A href="http://blogs.vbcity.com/blogs/xtab/archive/2009/09/03/wpf-listview-column-and-cell-formatting.aspx"&gt;this blog&lt;/A&gt;, so I won't repeat the markup for those here.&lt;/P&gt;
&lt;P&gt;In my &lt;A href="http://blogs.vbcity.com/blogs/xtab/archive/2009/09/08/wpf-listview-formatting-rows.aspx"&gt;last ListView blog&lt;/A&gt;, the ItemContainerStyle was used and we looked at the HorizontalContentAlignment property of the ListViewItem. By setting it to Stretch, the width of the items in each column was stretched so that their start and finish points all lined up vertically. &lt;/P&gt;
&lt;P&gt;Here is the markup:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;ListView.ItemContainerStyle&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;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ListViewItem"&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;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="HorizontalContentAlignment"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Stretch" /&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;And the result was this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV4-003.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;The problem with this obviously is those little gaps between the columns. The ListView inserts a margin of 6 units to the left and right of each column by default. So that is the cause of the gaps you can see there.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;Each cell used a DataTemplate. Here is the DataTemplate for the cells in the first column shown above:&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IDCellTemplate2"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="LightGreen" &amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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: #ff0000"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&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;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductID}" /&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: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;What we need to do is to continue to make use the Border element in the DataTemplate for the cell, but remove the Light Green Background color. Then we can set a BorderBrush of Black and give it a Thickness of 1 unit.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;Here's a first pass at it. This is the DataTemplate for the cells in the first column:&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IDBorderedCellTemplate"&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: #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;="Black"&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: #ff0000"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &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; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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: #ff0000"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&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;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductID}" /&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: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;The other two templates are very similar so I won't clog up the screen with them just yet. Here's the result so far:&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;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV5-002.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;We ended up with boxes when we really wanted lines, but it's a good start. The first trick is to set the individual values on the BorderThickness - that is left, top, right and bottom. By setting a value of 0 on the left and right we will remove the vertical lines. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;We also want to remove the top border, otherwise there will be a double line between the rows (the bottom border of one row, followed by the top border of the next). So, here's an improved version:&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IDBorderedCellTemplate"&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: #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;="Black"&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: #ff0000"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,0,0,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; &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; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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: #ff0000"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&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;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductID}" /&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: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV5-003.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;Getting closer. If we offset the start positions of the Borders in the DataTemplates and shunt them to the left to span the default gap of 6 units either side, we should be able to create a continuous line.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;The following code snippet is the DataTemplate for the &lt;B&gt;second&lt;/B&gt; column's cells. I'll explain why in a moment:&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="NameBorderedCellTemplate"&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: #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;="Black"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="-12,5,0,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;&amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,0,0,1"&lt;/SPAN&gt;&amp;nbsp; &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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"&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;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductName}" /&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: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;The result:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV5-004.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;What has happened here is that the Border in the second cell's template has been moved 12 units to the left. This has the effect of joining the end of first cell's bottom border to the start of the second cell's bottom border. This is achieved by setting the value of -12 for the left margin in the second line of markup above. So, to come back to why I have shown you the second cell's template, the reason is of course that the first cell doesn't need to be shunted to the left. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;It's almost perfect, but there is just one minor adjustment still needed which I'll deal with next.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;Moving the Border to the left means that its child TextBlock is also moved. It would look much better if the text content was displayed more in line with the column headers. You can see this in the second two columns in the screenshot above. This can be fixed by setting Margins on the TextBlocks. This time, I will shunt the TextBlocks back to the right. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;Here is the markup for the second cell again:&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="NameBorderedCellTemplate"&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: #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;="Black"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="-12,5,0,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;&amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,0,0,1"&lt;/SPAN&gt;&amp;nbsp; &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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"&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;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="14,0,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; &lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductName}" /&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: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;This time it is the Margin property on Line 6 that's of interest. As you can see, it pushes the start of the text back to where we want it.&lt;/FONT&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV5-005.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;For completeness, here is the markup for all three DataTemplates:&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IDBorderedCellTemplate"&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: #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;="Black"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,5,0,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: #ff0000"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,0,0,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; &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; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&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;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="3,0,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; &lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductID}" /&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: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="NameBorderedCellTemplate"&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;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; BorderBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Black"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="-12,5,0,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: #ff0000"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,0,0,1"&lt;/SPAN&gt;&amp;nbsp; &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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"&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;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="14,0,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; &lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductName}" /&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;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="PackBorderedCellTemplate"&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: #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;="Black"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="-12,5,0,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;&amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0,0,0,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; &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; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&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;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="15,0,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; &lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=PackageType}" /&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: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;As it has been&amp;nbsp;a couple of blogs since you saw the markup for the actual ListView, I'll list that too:&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductsListView"&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;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="5,25" &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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&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;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ListViewItem"&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;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="HorizontalContentAlignment"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Stretch" /&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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;GridView&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: #008000"&gt;&lt;!-- Product ID --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;}"&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;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDBorderedCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Product Name --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameBorderedCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Pack Size --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackageColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackBorderedCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT color=#000000 size=2 face=Verdana&gt;The DataBinding to the very basic data source was covered in &lt;/FONT&gt;&lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/08/22/how-to-use-the-wpf-listview.aspx"&gt;&lt;FONT color=#000000 size=2 face=Verdana&gt;this blog&lt;/FONT&gt;&lt;/A&gt;&lt;FONT color=#000000 size=2 face=Verdana&gt;. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000 size=2 face=Verdana&gt;So I know I've plodded through this in minute detail and you might think that it would have been better to have shown you the final versions of those DataTemplates and cut out all the intermediate steps. The reason I haven't is that you might want to take the basic idea and tweak it further - change colors, alter the vertical space between lines, change the distance that the text is shunted and so on. Now that you fully understand what each of those individual tweaks does, you can go ahead and make those kind of changes without having to pull my XAML apart to work out how its done.&lt;/FONT&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&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/9422.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Using a ValueConverter in WPF</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/25/9421.aspx</link><pubDate>Sun, 25 Oct 2009 12:20:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/25/9421.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9421.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9421.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/25/9421.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9421.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: calibri"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN style="TEXT-DECORATION: underline"&gt;The Story So Far&lt;/SPAN&gt;&lt;BR&gt;Each of my previous blog items on WPF ListViews has mostly used a collection of DrinkProduct objects as the data source. This collection is bound to the Window via a DataContext and the individual columns are bound to fields in the collection. (As an alternative, &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/08/22/how-to-use-the-wpf-listview.aspx"&gt;this blog&lt;/A&gt; looked at the XML data source alternative.)&lt;/P&gt;
&lt;P&gt;As the route from that &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/08/22/how-to-use-the-wpf-listview.aspx"&gt;first ListView blog&lt;/A&gt; to this one has become a bit murky, I'm going to start off by recreating the DrinkProduct class and creating the collection. I've taken the opportunity to add a few new properties which will be used in this and the upcoming ListView blogs. &lt;/P&gt;
&lt;P&gt;You can view the revised DrinkProducts class code &lt;A href="http://www.xtabvbcity.plus.com/Blogs/DrinkProductCode.txt"&gt;here.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The XAML markup for the start state of the ListView is in two locations. The ListView itself is in a WPF Window:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&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;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &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;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &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;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #ff0000"&gt;Title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="WPF ListView"&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;="450"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductsListView"&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;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="5"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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;GridView&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: #008000"&gt;&lt;!-- Product ID --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;}"&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;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Product Name --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Pack Size --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackageColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&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: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Window&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;All the Resources - GradientBrush, Styles, DataTemplates for ColumnHeaders and Cells - are in the Application.xaml file. You can see the markup for these &lt;A href="http://www.xtabvbcity.plus.com/Blogs/StylesAndResources.txt"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;If the Resources looks like a lot of markup, it breaks down into much less if you analyze it. There's a GradientBrush, a couple of Styles, then the DataTemplates, which are really only slightly tweaked versions of two simple templates.&lt;/P&gt;
&lt;P&gt;At this stage the ListView looks like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/ValueConverter/LV6-001.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;ValueConverters&lt;/SPAN&gt;&lt;BR&gt;In this blog I want to demonstrate a simple example of the creation and use of a ValueConverter in WPF. ValueConverters are particularly useful in situations where you are using data binding to directly populate elements in the UI. By definition, this means that the data from the fields of the data source are passed untested from the source to the display. &lt;/P&gt;
&lt;P&gt;This data will often be in a raw state, e.g. primitive types such as integer, double, boolean, etc. &amp;nbsp; In the first example I will use integer values that represent the quantity of stock remaining of the various drink products. These will be displayed in a new column of the ListView. &lt;BR&gt;&lt;BR&gt;Although the DataTemplates created earlier can alter the core properties of &lt;I&gt;all&lt;/I&gt; the values in the column - Foreground, Bold font, etc,- they don't offer any mechanism for analyzing these values and changing the look of the display of an &lt;I&gt;individual&lt;/I&gt; value based on some criteria. For instance, changing the color of the text if the value is negative. &lt;/P&gt;
&lt;P&gt;The way to achieve this kind of fine tuning is to use a ValueConverter. This automatically intercepts the data as it is being fed in from the DataContext, analyzes the value and makes any appropriate settings or changes to the display of this piece of data.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;A Simple ValueConverter&lt;/SPAN&gt;&lt;BR&gt;Let's start with something simple, a ValueConverter that analyzes the quantity held in stock and if that value is less than a particular threshold, the figure is displayed in red in the ListView. This will give an easy introduction to the steps involved. &lt;/P&gt;
&lt;P&gt;Before getting round to the ValueConverter I need to add a new column to the ListView, the column that will display the quantities held in stock. First a couple of DataTemplates - one for the column header and for the cell:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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: #008000"&gt;&lt;!-- Quantity In Stock column Header --&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="QtyColHeader"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; BlueBorder&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;TextBlock&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Quantity "&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ColHeaderText&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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: #008000"&gt;&lt;!-- Template for new column : Quantity in Stock --&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="QtyCellTemplate"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Quantity}"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Followed by the additional column in the ListView itself:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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: #008000"&gt;&lt;!-- Quantity --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; QtyColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; QtyCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;With just the raw quantity values showing in the new column, the ListView now looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/ValueConverter/ValCon_002.png"&gt;&lt;/P&gt;
&lt;P&gt;For the sake of example, let's say that we want to highlight in red all values that are less than 200. First we create a class that implements IValueConverter. This implementation requires two methods - Convert and ConvertBack - each with a standard signature. Here is the code, which can be placed in a file of its own or - as I have chosen to do - appended to the end of (but not inside!) the Application.xaml.vb file:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt; IntegerToBrushConverter&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; IValueConverter&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: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; Convert(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; targetType &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; Type, _&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: #0000ff"&gt;ByVal&lt;/SPAN&gt; parameter &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; culture &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Globalization.CultureInfo) _&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: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; IValueConverter.Convert&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: #008000"&gt;' Only allow conversion if the correct TargetType is passed in.&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: #008000"&gt;'&amp;nbsp; (This is optional)&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: #0000ff"&gt;If&lt;/SPAN&gt; targetType &lt;SPAN style="COLOR: #0000ff"&gt;IsNot&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;GetType&lt;/SPAN&gt;(Brush) &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Nothing&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #008000"&gt;'&amp;nbsp; If less than 200 in stock, display in Red, otherwise use &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: #008000"&gt;'&amp;nbsp; the default of MediumBlue&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: #0000ff"&gt;Dim&lt;/SPAN&gt; Result &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&lt;/SPAN&gt; = &lt;SPAN style="COLOR: #0000ff"&gt;Integer&lt;/SPAN&gt;.Parse(value.ToString())&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: #0000ff"&gt;Return&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt;(Result &amp;lt; 200, Brushes.Red, Brushes.MediumBlue))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; ConvertBack(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; targetType &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; Type, _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; parameter &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; culture &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Globalization.CultureInfo) _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; IValueConverter.ConvertBack&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: #008000"&gt;' Not used, so throw exception if this method is called.&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: #0000ff"&gt;Throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; NotImplementedException()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;As you can see from the comments, I have chosen to test that a Brush object is passed in to the method. This isn't mandatory but is often worth including. &amp;nbsp;&amp;nbsp;The second test in the Convert method checks the value of the current field and if it finds the value to be less than 200, Returns a Red Brush, otherwise it Returns a MediumBlue Brush. &lt;/P&gt;
&lt;P&gt;Clearly, what is needed next is some mechanism that is watching for those returned values and making use of the particular brush that is returned. This is handled in the markup in the Application.xaml file. &amp;nbsp;If you are wondering why the markup is in Application.xaml and not the Window that contains the ListView, the reason is that we need to set the conversion on the DataTemplate that formats the Quantity column. And that DataTemplate is in Application.xaml. &lt;/P&gt;
&lt;P&gt;As things stand, the XAML markup is unable to access the code above directly. So the first requirement is to map the current project into an XML namespace, making it possible to create a direct link between the two. The syntax for this is as follows:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &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;local&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="clr-namespace:WPFListview"&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;which is placed in the Application.xaml file, just below the default XML namespaces which are placed there automatically. This now gives the ability to refer to the IntegerToBrushConverter in the XAML markup. (You may find that you have to Rebuild the solution to remove the wavy blue error mark after you first enter this. )&lt;/P&gt;
&lt;P&gt;Now that the mapping is in place, I can create an instance of the IntegerToBrushConverter class and assign it a key so that it can be referred to in the XAML.&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&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;local&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;IntegerToBrushConverter&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="QtyConverter" /&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The final step is to use this instance of the converter inside the DataTemplate for the Quantity column. This markup is in the Application.xaml file:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;&lt;!-- Template for new column : Quantity in Stock --&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="QtyCellTemplate"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&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;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Quantity}"&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;Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Quantity,&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Converter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;={&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; QtyConverter&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The only change is to the Foreground property in the markup,which I have changed from the original hard-coded value of MediumBlue to the Binding you can see there. The syntax is reasonably straightforward:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The Path has to be an Integer type because that is what the IntegerToBrushConverter expects.&lt;BR&gt;
&lt;LI&gt;The relevant Path points to the field that the column is being databound to - Quantity. &lt;BR&gt;
&lt;LI&gt;The Converter in the Binding refers to that instance of the IntegerToBrushConverter created a few moments ago and given the key of 'QtyConverter'. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;The resulting display when the project runs is now:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/ValueConverter/ValCon_003.png"&gt;&lt;/P&gt;
&lt;P&gt;Just to briefly cover the ConvertBack method, you can see from the commenting that this method isn't of use to us in this scenario. However, IValueConverter requires that it is included, so we simply throw an Exception if this method should be accessed at any point. &lt;/P&gt;
&lt;P&gt;This has been a very simple example of using a ValueConverter, but it includes all the key steps. I plan to cover some more complex scenarios in later blogs.&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&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/9421.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>More Complex Conversions with the WPF MultiBinding Converter</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/25/9420.aspx</link><pubDate>Sun, 25 Oct 2009 12:18:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/25/9420.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9420.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9420.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/25/9420.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9420.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: calibri"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;In the &lt;A class=null href="http://cs.vbcity.com/blogs/xtab/archive/2009/09/20/using-a-valueconverter-in-wpf.aspx"&gt;previous blog&lt;/A&gt;, I created a simple ValueConverter that analyzed the data bound values and set the Foreground color of a TextBlock based on whether the value was less or more than a cut off value of 200 units. In reality, these preset values (such as the 200 in that demonstration) are rarely that rigid and you often need some flexibility in the analysis. To continue the example of a collection of drink products, it might be more realistic to compute a cut off value on the fly. For instance, if you know your annual sales for an individual item and you know the quantity you have in stock, you might want to highlight those items that need to be re-ordered. If it's a big selling item, the value of 200 may be far too low as a cut off; conversely an item with low annual sales might only need to be re-ordered when the stock is down to a handful. &lt;/P&gt;
&lt;P&gt;So, how do we include this kind of calculation in a process where the value is data bound, but we need to apply some arithmetic to more than one field? The answer is to use MultiBinding and a MultiValueConverter.&lt;/P&gt;
&lt;P&gt;You create a class that implements IMultiValueConverter. The core difference between this class and the one created in the previous blog is that the 'value' parameter of the Convert method is renamed to 'values' and is an array, not a single object. Armed with that array, you can pass in the values of two or more of the fields of your data source, run the calculations and Return a result.&lt;/P&gt;
&lt;P&gt;Take a look at this class:&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt; StockLevelConverter&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; IMultiValueConverter&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: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; Convert(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; values() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; targetType &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Type, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; parameter &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; culture &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Globalization.CultureInfo) &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; System.Windows.Data.IMultiValueConverter.Convert&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: #0000ff"&gt;If&lt;/SPAN&gt; targetType &lt;SPAN style="COLOR: #0000ff"&gt;IsNot&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;GetType&lt;/SPAN&gt;(Brush) &lt;SPAN style="COLOR: #0000ff"&gt;Then&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Nothing&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: #008000"&gt;'&amp;nbsp; Variables for the arithmetic operations&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: #0000ff"&gt;Dim&lt;/SPAN&gt; QtyHeld &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&lt;/SPAN&gt; = &lt;SPAN style="COLOR: #0000ff"&gt;CInt&lt;/SPAN&gt;(values(0))&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: #0000ff"&gt;Dim&lt;/SPAN&gt; AnnualSales &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&lt;/SPAN&gt; = &lt;SPAN style="COLOR: #0000ff"&gt;CInt&lt;/SPAN&gt;(values(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; &lt;SPAN style="COLOR: #008000"&gt;'&amp;nbsp; Avoid divide by zero errors by not proceeding to the calculation&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: #008000"&gt;'&amp;nbsp; and returning a different brush &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: #0000ff"&gt;If&lt;/SPAN&gt; QtyHeld = 0 &lt;SPAN style="COLOR: #0000ff"&gt;Or&lt;/SPAN&gt; AnnualSales = 0 &lt;SPAN style="COLOR: #0000ff"&gt;Then&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Return&lt;/SPAN&gt; Brushes.DarkGray&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: #0000ff"&gt;Dim&lt;/SPAN&gt; RestockLevel &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Integer&lt;/SPAN&gt; = AnnualSales / 12&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: #0000ff"&gt;Return&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt;(QtyHeld &amp;lt; RestockLevel, Brushes.Red, Brushes.MediumBlue))&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; ConvertBack(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; targetTypes() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Type, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; parameter &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; culture &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Globalization.CultureInfo) &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;() &lt;SPAN style="COLOR: #0000ff"&gt;Implements&lt;/SPAN&gt; System.Windows.Data.IMultiValueConverter.ConvertBack&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: #0000ff"&gt;Throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; NotImplementedException()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;It is similar to the converter class created in the previous blog, having the same two methods, Convert and ConvertBack. &amp;nbsp;&amp;nbsp; Note that this class implements IMultiValueConverter and the first parameter being an array as mentioned earlier. &lt;/P&gt;
&lt;P&gt;In the Convert method, I have included the test that confirms that the correct Target Type has been passed in. Two variables, QtyHeld and AnnualSales are created and you will see that their respective values are taken from the two elements of the array named 'values' passed in as a parameter. We will need to look at how those array elements are notified to the converter in a moment. &lt;/P&gt;
&lt;P&gt;Continuing with the Convert method, a test is included to avoid any divide by zero errors. I have chosen to Return a different colored Brush, but it could have been left to the default of MediumBlue if preferred.&lt;/P&gt;
&lt;P&gt;The 'RestockLevel' variable could have been left out and the calculation that it uses could have been placed inside the If statement in the final line. But I felt that it is easier to read in the more verbose approach. The gist of these two lines is to divide the annual sales figure by 12 in order to find the average monthly sales. If the Stock held is less than one month's worth, then a Red Brush is returned, otherwise a MediumBlue one.&lt;/P&gt;
&lt;P&gt;So, how do the values in the array get passed in to the Convert method? The answer is that a MultiBinding is used in the XAML. This is a similar approach to the single ValueConverter example seen previously, except that this time two Paths are required - one for the Quantity field and one for the AnnualSales field of the data source.&lt;/P&gt;
&lt;P&gt;Assuming you are using the same project as in the previous blog, there is already a namespace mapping named 'local'. You then need to create an instance of this new converter class:&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;local&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StockLevelConverter&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="StockChecker" /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The DataTemplate for the Quantity column cells will contain the MultiBinding. Here is the markup for this:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="QtyCellTemplate"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&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;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Quantity}" &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;TextBlock.Foreground&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;MultiBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Converter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; StockChecker&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;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Quantity" /&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;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="AnnualSales" /&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;MultiBinding&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock.Foreground&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The Element.Property syntax is used to allow for the multiple sub elements. The MultiBinding is created and set to point to that instance of the StockLevelConverter class, which has been keyed as 'StockChecker'. The two paths which are passed in to the StockLevelConverter are listed next. Note that the array is filled in the order in which these paths are listed - that is values(0) will take the Quantity field values and values(1) will take the AnnualSales field values.&lt;/P&gt;
&lt;P&gt;That's all there is to it. If I create some arbitrary dummy data for all the properties of the DrinkProduct class collection (i.e. including the Quantity and AnnualSales figures) and run the project, the resulting ListView will look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/ValueConverter/ValCon_004.png"&gt;&lt;/P&gt;
&lt;P&gt;If you're interested in trying this out, using the class code from the previous blog but can't be bothered to create your own dummy data, here is the collection I created:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Shared&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt; StockCheck() &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; DrinkProduct)&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: #0000ff"&gt;Dim&lt;/SPAN&gt; CurrentProducts &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; DrinkProduct)&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: #0000ff"&gt;With&lt;/SPAN&gt; CurrentProducts&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"CF1kg"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Coffee Powder"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"1 Kg"&lt;/SPAN&gt;, MaterialType.Powder, 15684, 1276))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"CFB500"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Ground Coffee"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&lt;/SPAN&gt;, MaterialType.Powder, 22785, 12856))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"CFG500"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Coffee Granules"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&lt;/SPAN&gt;, MaterialType.Granules, 19233, 5907))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Te500"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Tea"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&lt;/SPAN&gt;, MaterialType.Leaf, 8544, 235))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"TeInst500"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Instant Tea"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&lt;/SPAN&gt;, MaterialType.Powder, 1009, 22))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"SMlk1lt"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Skimmed Milk"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"1 Litre"&lt;/SPAN&gt;, MaterialType.Liquid, 28012, 2650))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"HiJ300"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"HiJuice Drink Mix"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"300 g"&lt;/SPAN&gt;, MaterialType.Other, 578, 179))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Sm400"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Smoothie"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"400ml"&lt;/SPAN&gt;, MaterialType.Paste, 9346, 3284))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Beef300"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Beef Drink"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"300 g"&lt;/SPAN&gt;, MaterialType.Granules, 8316, 1965))&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; .Add(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Beef750"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Beef Drink"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"750 g"&lt;/SPAN&gt;, MaterialType.Granules, 7612, 359))&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: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;Return&lt;/SPAN&gt; CurrentProducts&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't forget to include the DataContext in the code-behind of Window1, the Window that holds the actual ListView:&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt; Window1 &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Dim&lt;/SPAN&gt; CurrentProducts &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: #0000ff"&gt;Of&lt;/SPAN&gt; DrinkProduct)&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: #0000ff"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt; Me_Loaded(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Windows.RoutedEventArgs) &lt;SPAN style="COLOR: #0000ff"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;.Loaded&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentProducts = DrinkProduct.StockCheck()&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: #0000ff"&gt;Me&lt;/SPAN&gt;.DataContext = CurrentProducts&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9420.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF ListView - How To Format the Appearance of Rows</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/25/9419.aspx</link><pubDate>Sun, 25 Oct 2009 12:17:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/25/9419.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9419.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9419.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/25/9419.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9419.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: Calibri"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;By the end of &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/09/03/wpf-listview-column-and-cell-formatting.aspx"&gt;the previous blog item&lt;/A&gt;&amp;nbsp;on the topic of&amp;nbsp;the WPF ListView, the ListView looked like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV4-001.png"&gt;&lt;/P&gt;
&lt;P&gt;In this blog I want to look at ways of changing the look of the rows. You may, for example, want to assign a background color to the rows. And based on what we have done so far, you might be tempted to edit the DataTemplates used for the cells. Maybe you would think about adding a Border with a Background fill and placing this around the TextBlock for each cell:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&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;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IDCellTemplate2"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="LightGreen"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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: #ff0000"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&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;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductID}" /&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: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;I won't waste the space showing the markup for all three templates here, but if you did try this you will get a disappointing result:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV4-002.png"&gt;&lt;/P&gt;
&lt;P&gt;Pretty ugly, I think you'll agree. Playing around with the Margin or Padding won't get you any further either.&lt;/P&gt;
&lt;P&gt;The answer is to use the ItemContainerStyle property of the ListView. This opens up a number of choices for you. Firstly, if you would like to still have a gap between each of the columns - but an even gap - then you can take the following approach:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;ListView.ItemContainerStyle&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;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ListViewItem"&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;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="HorizontalContentAlignment"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Stretch" /&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;This will produce the following output, which is an improvement:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV4-003.png"&gt;&lt;/P&gt;
&lt;P&gt;If you want the light green to spread across the whole row, then you still use the ItemContainerStyle, but this time you set the Background property of the ListViewItem:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;ListView.ItemContainerStyle&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;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ListViewItem"&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;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Background"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="LightGreen" /&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Now you get the result you are probably looking for.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV4-004.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all that whiteness in the background is a bit too much for you, then of course you can blend another shade of green into the mix by setting the ListView's Background property. Using SeaGreen, for example, will produce this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/LV4-006.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The final markup for the ListView looks like this:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductsListView"&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;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="5,25"&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: #ff0000"&gt;Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SeaGreen"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&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;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ListViewItem"&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;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Background"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="LightGreen" /&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.ItemContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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;GridView&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: #008000"&gt;&lt;!-- Product ID --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;}"&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;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Product Name --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Pack Size --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackageColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackCellTemplate&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; span&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The markup for the DataTemplates and Styles is the same as that shown in the previous blog, all of which I placed in the Application.xaml file (App.xaml for C# projects).&lt;/P&gt;
&lt;P&gt;There are some other row formatting options I want to cover, but I will leave those for another day.&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&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/9419.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Visual Studio 2010 XAML Intellisense and Other Improvements</title><link>http://blogs.vbcity.com/xtab/archive/2009/10/25/9418.aspx</link><pubDate>Sun, 25 Oct 2009 12:12:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/10/25/9418.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9418.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9418.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/10/25/9418.aspx#comment</comments><slash:comments>1</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9418.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;p&gt;&lt;span style="font-family: Calibri;"&gt;&lt;/span&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/p&gt;
&lt;p&gt;Sometimes it's the tiniest little changes that make you happy out of all proportion to the size of the change. While testing the WPF features in VS2010 I was totally thrilled to discover that at last when you type in the opening curly brace in the XAML Pane, you get an Intellisense list of useful choices. The top one, of course, is &lt;b&gt;StaticResource&lt;/b&gt;. If I had a penny for every time I've laboriously typed out that name, I'd be a rich man! &lt;/p&gt;
&lt;p&gt;The same feature also offers other commonly used properties such as &lt;b&gt;Binding&lt;/b&gt;. And once you have entered 'Binding' and a space, you also get &lt;b&gt;Path&lt;/b&gt;, again courtesy of Intellisense. &lt;/p&gt;
&lt;p&gt;On the subject of DataBinding, which is a key feature in WPF of course, the Properties Pane has been improved. Now if you select a control such as a ListView, the ItemsSource property is available in the Properties Pane and you can select the Binding from the available choices: &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/VS2010Binding.png" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Maybe I've missed a trick, though, because when I tried to drill deeper into the ListView components and looked at the binding for a GridViewColumn, there didn't seem to be a way to select a value for the DisplayMemberBinding. If in the XAML Pane I manually typed in a valid Path, i.e. a field from the data source behind the DataContext, then that would be shown in the Properties Pane. But I couldn't find an option to switch the Path to a different field within that dialog. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/VS2010ProductID.png" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I quite liked the way you can now view and choose from all the Resources in scope. This example shows where I am building a ListView and using a CellTemplate, for instance:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/VS2010Resources.png" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I noticed that when using the Properties Pane in this way, it can have an annoying habit. You close the dialog window by clicking anywhere outside it (i.e. it doesn't have a close/x button). If you are careless about where you click, you will deselect the current element in the XAML Pane. Often, if you click in the Design Pane to deselect, you will be taken back to the root element. It would be nice if a close button is added to the dialog windows at some point. &lt;/p&gt;
&lt;p&gt;You can also pick and assign a saved Style for the Style property of any element. In this example I am offered all the previously created styles which can be assigned to a TextBlock element: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/VS2010Styles.png" /&gt;&lt;/p&gt;
&lt;p&gt;Another super improvement in the Properties pane is the color picker feature. If you select a property which can be assigned a color (well, to be more accurate, a brush), then you can click on the little down arrow at the right hand side of the property in the Properties pane and a color picker dialog will appear: &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/VS2010Colors.png" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This example shows the Background property of a TextBlock. You can play with the color picker until you have the exact look you want. if you've used Expression Blend you'll recognize this layout. &lt;/p&gt;
&lt;p&gt;You can still select a named color if you want. The drop down list is at the bottom left of the color picker:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.xtabvbcity.plus.com/Blogs/VS2010Colors2.png" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Overall, I like the new look of the VS2010 editor and the new features I've found so far. &lt;/p&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9418.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Date and Time: How To Create a 'Time' element</title><link>http://blogs.vbcity.com/xtab/archive/2009/09/05/9390.aspx</link><pubDate>Sat, 05 Sep 2009 10:18:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/09/05/9390.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9390.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9390.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/09/05/9390.aspx#comment</comments><slash:comments>157</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9390.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;I've often thought that dealing with dates and times can sometimes be much more difficult than it should be. There is a bewildering range of choices, many of which seem to do pretty much the same thing and you can sometimes wonder which is the 'right' way. One good example of the multiple choices is identifying a time. I don't mean a TimeSpan - which is a period of time - but a single specific moment in time, such as 8 o'clock, that you want to isolate and maybe compare, manipulate or filter in some way. &lt;/P&gt;
&lt;P&gt;You can of course take any DateTime instance and display only the time element by using ToShortTimeString or ToLongTimeString. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TimeCheck = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; DateTime&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TimeCheck = Now&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"TimeCheck =&amp;nbsp; "&lt;/SPAN&gt; &amp;amp; TimeCheck.ToShortTimeString)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You can also drill down and pull out the hour, minute, second or any combination of those.&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TimeCheck = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; DateTime&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TimeCheck = Now&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"TimeCheck Hour and Minute = {0}:{1}&amp;nbsp; "&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; TimeCheck.Hour, TimeCheck.Minute)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Also available is the TimeOfDay property of the DateTime class, which - as you would expect - will return the time element. However this is a TimeSpan which in some cases can make it very fiddly to manipulate. It is also a ReadOnly property, so you can't use it to set a new time. &lt;/P&gt;
&lt;P&gt;And by coincidence, only today I learned of yet another one - the TimeString property, which returns the current time in HH:mm:ss format.&amp;nbsp; But that is fixed to the current time, not some time point of your choice.&lt;/P&gt;
&lt;P&gt;The TimeValue function offers a different approach. Although it gives the appearance of being just a time - e.g. 14:22:30 or 3:15 PM and so on - it is basically a full standard DateTime, but the date is always constrained to be 1st January in the year 0001. For most purposes when you use TimeValue it conveniently ignores that date, anyway. &lt;/P&gt;
&lt;P&gt;You can extract the time value of any particular date and time by passing in a DateTime instance to the TimeValue function: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; DT &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; DateTime = TimeValue(Now)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;TimeValue returns a String, so there is no need to cast to any of the String formats to read it as text:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;Console.WriteLine(DT)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If you run those last two lines of code, you may be surprised/disappointed to see that it still includes a date. However, remember that the original DateTime we passed in was the DateTime value &lt;B&gt;Now&lt;/B&gt;. As you will see in the Console printout, the real value of today's date has been dropped and is replaced by the 01/01/0001 date.&lt;/P&gt;
&lt;P&gt;TimeValue also allows you to manufacture a time. In the next example, a time of 1400 hours or 2pm is created:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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; TVTime &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; DateTime&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TVTime = TimeValue(&lt;SPAN style="COLOR: #a31515"&gt;"14:00"&lt;/SPAN&gt;)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Note that unlike the overloaded constructors of the DateTime class, you don't have to include year, month and day - for the obvious reason that they would be ignored anyway. &lt;/P&gt;
&lt;P&gt;Although I haven't done so, you can also include a value for Seconds to the time you create. &lt;BR&gt;&lt;BR&gt;You can add or subtract elements of time from the currently stored time by using AddHours, AddMinutes, AddSeconds, etc&lt;/P&gt;
&lt;P&gt;Finally, you can compare times. If you wanted, for example, to check if a particular deadline had passed you can compare the times extracted with TimeValue:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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; TVTime &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; DateTime&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TVTime = TimeValue(&lt;SPAN style="COLOR: #a31515"&gt;"14:00"&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; TimeValue(Now) &amp;gt; TVTime &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; Console.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Passed deadline"&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; Console.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Not yet reached"&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;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;There is really nothing in TimeValue that can't be achieved by manipulating other properties and methods of the DateTime class, but in many situations it's a neat function that will make for easier, cleaner code.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9390.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>WPF ListView Column and Cell Formatting</title><link>http://blogs.vbcity.com/xtab/archive/2009/09/05/9389.aspx</link><pubDate>Sat, 05 Sep 2009 10:03:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/09/05/9389.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9389.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9389.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/09/05/9389.aspx#comment</comments><slash:comments>381</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9389.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: Calibri"&gt;
&lt;P&gt;In the &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/08/22/how-to-use-the-wpf-listview.aspx"&gt;first WPF ListView blog&lt;/A&gt;&amp;nbsp;of this set,&amp;nbsp;I used XML data binding and added some basic formatting to the Column Headers of the ListView. In the &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/08/28/more-on-databinding-to-a-wpf-listview.aspx"&gt;previous blog&lt;/A&gt;, a collection of objects was used as the data source. The formatting in that second example was a bit plain. So, in this blog I will look at some ways of breaking away from the standard monochrome ListView.&lt;/P&gt;
&lt;P&gt;First, let's revisit those Column Headers. Instead of the plain block Yellow I used in the first example, we can use a Gradient Brush for the TextBlock background and place a matching color Border round the outside. The finished headers will look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/BlueHeaders.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As before, it is best to try and centralize as much of the XAML for the GUI as possible. To do this we use DataTemplates and Styles. &lt;/P&gt;
&lt;P&gt;First, there is a Style for the blue border which surrounds each column header TextBlock, which I have chosen to store in the Application.xaml file as an application wide Resource:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="BlueBorder"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Border"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="BorderBrush"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="#FF6B93CC"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="BorderThickness"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CornerRadius"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Padding"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;There is a LinearGradientBrush which is used to give the TextBlock background the blue and white gradient look. Again I have put this in Application.xaml:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SubtleBlue"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; EndPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0.476,-0.09"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; StartPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0.476,1.363"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="#FF7A8EEC"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0.013"/&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="#FF6B93CC"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="#FFF7F6F7"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0.54"/&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="#FFEDEEF4"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="0.46"/&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: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The TextBlocks in the column headers also use a Style. This Style, as you can see, incorporates that LinearGradientBrush:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ColHeaderText"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TextBlock"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="FontSize"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="14" /&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="FontWeight"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold" /&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Background"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; SubtleBlue&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Foreground"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Black" /&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Padding"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;So far, we have Styles for the Border and the TextBlock. The next step is to use these styles in a DataTemplate for the Column Headers.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IDColHeader"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; BlueBorder&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;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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Product ID "&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ColHeaderText&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&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;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp; &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: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="NameColHeader"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; BlueBorder&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;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Product Name "&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ColHeaderText&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="PackageColHeader"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; BlueBorder&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;TextBlock&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Pack Size "&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ColHeaderText&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;These three DataTemplates are essentially the same, the only difference being the text content. It would be possible to have only one DataTemplate for all the TextBlocks and use TemplateBinding to pass in the required text from the ListView markup, but I thought I would try and keep things as simple as possible for you at this stage.&lt;/P&gt;
&lt;P&gt;We now have everything we need in the way of resources to build the GUI of the ListView. Taking things one step at a time, here is the first pass at the ListView markup:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductsListView"&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;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="5,25"&lt;/SPAN&gt;&amp;nbsp; &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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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;GridView&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: #008000"&gt;&lt;!-- Product ID --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Product Name --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Pack Size --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackageColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The data to be displayed comes from the bound DataSource. (This is covered in the previous blog item).&lt;/P&gt;
&lt;P&gt;Each GridViewColumn uses its own HeaderTemplate to create the gradient TextBlock with blue border and appropriate text.&lt;/P&gt;
&lt;P&gt;If you were to run this now, you will see that the headers have the right look, but the data isn't what you want:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/WrongData.png"&gt;&lt;/P&gt;
&lt;P&gt;This is because I haven't yet set the DataTemplates for each of the cells - that is, each item in each row. More specifically, I haven't set the appropriate Binding that will link the correct field in the data source to the column. &lt;/P&gt;
&lt;P&gt;I will do this by means of another DataTemplate. As well as fixing up the Binding, I'll play with the text settings, so you can see how easy it is to create a different look for each column, if you need to. In this case, I've decided that I'll make all the data text Blue, but will make the detail of the Product Names stand out.&lt;/P&gt;
&lt;P&gt;Here are the three DataTemplates:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="IDCellTemplate"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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: #ff0000"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Calibri"&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;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductID}" /&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: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="NameCellTemplate"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="DarkBlue"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; FontWeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold"&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;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductName}" /&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: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="PackCellTemplate"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MediumBlue"&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;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=PackageType}"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;So, the final step is simply to point to these DataTemplates from the GridViewColumn's CellTemplate property. The ProductID column, for example:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #ff0000"&gt;&amp;nbsp;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDCellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;}"&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;The final complete markup for the ListView is as follows:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductsListView"&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;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="5,25"&lt;/SPAN&gt;&amp;nbsp; &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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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;GridView&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: #008000"&gt;&lt;!-- Product ID --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; IDCellTemplate&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;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Product Name --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; NameCellTemplate&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;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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: #008000"&gt;&lt;!-- Pack Size --&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;GridViewColumn&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;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackageColHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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: #ff0000"&gt;CellTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; PackCellTemplate&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;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;And the finished look is:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/Finished.png"&gt;&lt;/P&gt;
&lt;P&gt;This example only scratches the surface of the changes you can make to the look of the ListView. Some of them will take quite a lot more work (more than it should, you may think) and I will look at those in future blogs.&lt;/P&gt;
&lt;P&gt;You may have noticed in the examples that by default the column widths are set to a size that allows the widest item to be displayed. Of course, the user can resize the column widths at run time and a useful trick to know is this: If the column width is too small for all the data to be read, double-clicking on the &lt;B&gt;divider&lt;/B&gt; between the two columns will cause the column to the left to resize. All its data will then be visible again. It's a little weird that you have to click on the divider, not the column header, but it works just fine. &lt;/P&gt;
&lt;P&gt;NB. Another thing to note: If you don't want to re-run the project after each change, sometimes you will need to Rebuild the solution to get the new look to appear in the Design Pane.&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&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/9389.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>More on DataBinding to a WPF ListView</title><link>http://blogs.vbcity.com/xtab/archive/2009/08/28/9383.aspx</link><pubDate>Fri, 28 Aug 2009 14:22:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/08/28/9383.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9383.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9383.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/08/28/9383.aspx#comment</comments><slash:comments>1</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9383.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;In a &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/08/23/how-to-use-the-wpf-listview.aspx"&gt;previous Blog&lt;/A&gt;, I showed how to databind an XML file to a WPF ListView. As some people are more comfortable with collections of objects than they are with XML, in this blog item I thought we could look at binding to a collection. &lt;/P&gt;
&lt;P&gt;One difference to note is that if you use XML data and XPath, you have the benefit of seeing all the data in the Design Pane at design time. With this collection of objects approach, the data is being created on the fly, so of course it can't be seen at design time because it doesn't exist. It isn't usually a problem, but if you have become used to seeing the data at design time, this can be disconcerting at first. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;Creating a Collection of Objects&lt;/U&gt; &lt;BR&gt;Constructing a class that you can use to create objects is exactly the same as with Windows Forms. Here is a simple class named DrinkProduct: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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; DrinkProduct&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;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; ProductID &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; ProductName &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; PackageType &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&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;.ProductID = ProductID&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;.ProductName = ProductName&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;.PackageType = PackageType&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;Private&lt;/SPAN&gt; _ProductID &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt;&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;Property&lt;/SPAN&gt; ProductID() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&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;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; _ProductID&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;&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; &lt;SPAN style="COLOR: blue"&gt;String&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; _ProductID = value&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;&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; _ProductName &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt;&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;Property&lt;/SPAN&gt; ProductName() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&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;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; _ProductName&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;&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; &lt;SPAN style="COLOR: blue"&gt;String&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; _ProductName = value&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;&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;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; _PackageType &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt;&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;Property&lt;/SPAN&gt; PackageType() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&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;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; _PackageType&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;&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; &lt;SPAN style="COLOR: blue"&gt;String&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; _PackageType = value&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;&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;&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;&lt;/P&gt;
&lt;P&gt;The next step is to create a collection of DrinkProduct objects. Again, there is nothing new here:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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; StockCheck() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: blue"&gt;Of&lt;/SPAN&gt; DrinkProduct)&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; CurrentProducts &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: blue"&gt;Of&lt;/SPAN&gt; DrinkProduct)&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; CurrentProducts&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; .Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"CF1kg"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Instant Coffee"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"1 Kg"&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; .Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"CFG500g"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Ground Coffee"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&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; .Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"Te500g"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Tea"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"500 g"&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; .Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"SMlk1lt"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Skimmed Milk"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"1 Litre"&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; .Add(&lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; DrinkProduct(&lt;SPAN style="COLOR: #a31515"&gt;"HiJ300g"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"HiJuice Drink Mix"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"300 g"&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;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;Return&lt;/SPAN&gt; CurrentProducts&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;Where you place the above function is a matter of choice, depending on what kind of scope you want it to have within the application. I've chosen to place it in a helper module named modStockControl so that it is available application wide. &lt;/P&gt;
&lt;P&gt;The next step includes a small change. The link between that collection of objects and the ListView that will display them in will be a DataContext. This is very much like the DataSource object that you will be familiar with from Windows Forms. In the code-behind for the Window, insert the following code: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; CurrentProducts &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; List(&lt;SPAN style="COLOR: blue"&gt;Of&lt;/SPAN&gt; DrinkProduct)&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; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Part2_Loaded(&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.RoutedEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Loaded&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentProducts = StockCheck()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ProductsListView.DataContext = CurrentProducts&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;Clearly, all this does is create an empty List, then generates some data to populate the List. The final line sets the DataContext of the ListView specifically to be the that List. At the risk of confusing the issue at this early stage, it isn't necessary to bind directly to the ListView. I could have set the DataContext on the Window or the Grid, for example and it may still be accessible by the ListView. This is something I will cover in a future blog. &lt;/P&gt;
&lt;P&gt;Let's turn our attention to the ListView markup. A skeleton version is:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;ListView&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ProductsListView"&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;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;}"&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;ListView.View&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;GridView&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: green"&gt;&amp;lt;!-- Product ID --&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;GridViewColumn&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;Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ProductID"&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;GridViewColumn.CellTemplate&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;DataTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&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;TextBlock&lt;/SPAN&gt;&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;=ProductID}" /&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;DataTemplate&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;GridViewColumn.CellTemplate&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;GridViewColumn&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;&amp;lt;!-- Remaining two columns removed for brevity --&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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;ListView.View&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;ListView&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;As you can see in the markup, the ListView is named and this name is the one we used in the code-behind to link to the DataContext. Even more crucially, the ItemsSource property is set to point to that same DataContext. Even though it only contains the word "Binding", WPF is smart enough to work out which particular binding is the appropriate one. So those two properties are the glue that enables the ListView to be populated with DrinkProduct objects.&lt;/P&gt;
&lt;P&gt;The remaining markup creates a View and in that View there are three GridViewColumns (although I have only shown the markup for the first one). Inside the GridViewColumn markup you see a CellTemplate and a DataTemplate, both of which are simply devices for packaging the look of the data. In this case, a basic TextBlock is used to house the text data. &lt;/P&gt;
&lt;P&gt;The line of markup:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;TextBlock&lt;/SPAN&gt;&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;=ProductID}" /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;is the final piece of the Binding puzzle. The pointer to the "Binding" ensures that WPF looks back up the tree to find the source of the data that has been set. (In this case, it looks no further than the ItemsSource which in turn knows that the data will come from that collection of DrinkProduct items.) &lt;/P&gt;
&lt;P&gt;The Path identifies the exact field in the data source that is to be bound to this column. For this column it is the ProductID field. &lt;/P&gt;
&lt;P&gt;So, as you can see from the few steps we have taken above, data binding the ListView to a data source is a trivial task.&lt;/P&gt;
&lt;P&gt;At the moment, the GUI isn't too impressive, because I've stripped out everything but the basics:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/BasicListView.png"&gt;&lt;/P&gt;
&lt;P&gt;I originally intended to look at several other tweaks that you can make to the look and layout of WPF ListViews. But to keep this blog to a reasonable length (and so as not to confuse the data binding technique with other peripheral stuff) I'll cover that in my next blog. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9383.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Configuring ListView Column Headers</title><link>http://blogs.vbcity.com/xtab/archive/2009/08/25/9382.aspx</link><pubDate>Tue, 25 Aug 2009 20:00:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/08/25/9382.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9382.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9382.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/08/25/9382.aspx#comment</comments><slash:comments>199</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9382.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: Calibri"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;A recent question here on VBCity came from a member who was searching for a way of changing the background color, font and border of the Column Headers in a ListView. This has always been&amp;nbsp;a particularly tough call in Windows Forms. (A DataGridView, on the other hand, &lt;EM&gt;does&lt;/EM&gt; have this feature, so that might often be an easy workaround.)&lt;/P&gt;
&lt;P&gt;But, as usual when questions of difficult layout come up, my mind&amp;nbsp;turns to WPF as a possible solution. Usually I would say 'an easy solution', but in this case honesty forces me to say that I've always found the WPF ListView to be one of its less user-friendly elements. Windows Forms certainly makes it easier to create data by hand, with the ability to add sub-items via the properties window. WPF effectively forces you to use data binding as the means of populating the ListView - although the data source can be a relatively simple collection of objects.&amp;nbsp;&amp;nbsp; So I thought it might be useful to blog how to create a relatively uncomplicated ListView in WPF - one with a differently colored Column Headers,of course.&lt;/P&gt;
&lt;P&gt;There is quite a lot of repetition of the graphical characteristics of the various sub-elements of a WPF ListView - the Column Headers and the content of the columns themselves, for example. So, it is always worth spending the time to create Styles or Templates which can be reused. Not only does this save time in the long run, it reduces the amount of markup used to create the actual ListView itself in the Window which usually makes it a little easier to read.&lt;/P&gt;
&lt;P&gt;The first version isn't going to be&amp;nbsp;too ambitious and will look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/ColoredListView.png"&gt;&lt;/P&gt;
&lt;P&gt;Of course I could have added lots of other graphics junk in there, but I want to try and keep things as straightforward as possible. By the time we've worked our way through the Styles, Templates and XML Data Provider, I think that will be quite enough for one session. In a later blog, I plan to expand on this version.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;The Basic ListView&lt;/SPAN&gt;&lt;BR&gt;The first step is to drag an empty ListView from the Toolbox and drop it on the XAML pane. Note that I say XAML pane, not the Design pane. As in this case, it is often easier to start with an empty element rather than have to edit the default&amp;nbsp;property settings&amp;nbsp;that you will see in the XAML if you drop it on to the Design pane.&lt;/P&gt;
&lt;P&gt;In order to display the content, a WPF ListView requires the use of a View. This has the same role as the View property in the Windows Forms ListView, i.e. it controls the manner in which the data is laid out. The similarities end there, however. At the time of writing, the WPF ListView only has one choice of view - the GridView. In its basic form, this is similar to the WinForms ListView Details View, (except of course that WPF isn't limited in the way you can package and display the data). &lt;/P&gt;
&lt;P&gt;As you can see from the following screenshot, even if you wanted to choose a value for the View property, this is something that has to be created in XAML. Future versions of WPF may perhaps increase this choice, but WPF already gives you the freedom to use the equivalent of Large Icon, Small Icon, List, etc, if that is the look you want, so maybe not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/View.png"&gt;&lt;/P&gt;
&lt;P&gt;The markup to create the View is simple:&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;ListView&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;ListView.View&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;GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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;ListView.View&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;ListView&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;There will be very little to see in the Design Pane yet. The next step is to add some columns. Add three columns to the GridView of the ListView:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="85"&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;GridViewColumn&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;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&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;GridView&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;If you check the Design pane now, you will see a fine outline of the Column Headers. There is a divider after the first column, because I have set a Width value on it. The other two columns are not visible because they currently have a zero width.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/WPFListView/NoWidth.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Create a Reusable Style&lt;/SPAN&gt;&lt;BR&gt;Each of the three Column Headers will have some properties that are set to the same values as each other. Therefore it makes sense to set those property values in one place and assign them to each Column Header. The alternative approach would be to repeat virtually the same XAML three times, which clearly isn't a sensible way forward. WPF Styles is the technique which makes this very easy to implement. &lt;/P&gt;
&lt;P&gt;In this simple example I am going to use a TextBlock to hold the text of the Column Header. The following markup, which is placed in the Application.xaml file (for VB) or App.xaml file (for C#) creates a Style for a TextBlock:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ColHeaderText"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TargetType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TextBlock"&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Width"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="110" /&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Height"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="29" /&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="FontSize"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="14" /&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="FontWeight"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Bold" /&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: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Background"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Setter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Foreground"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Navy" /&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: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style&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;If you're not familiar with the concept of Styles, all it does is set values on an assortment of TextBlock properties. The Style is assigned a key - in this case 'ColHeaderText'. This Style can now be applied to any TextBlock in the application.&lt;/P&gt;
&lt;P&gt;The markup for the ListView can now be extended to include a Header that contains a TextBlock:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&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;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="85"&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;GridViewColumn.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; &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;=" Product ID"&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: #ff0000"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ColHeaderText&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;}"&lt;/SPAN&gt;&amp;nbsp; &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;GridViewColumn.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;GridViewColumn&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;The TextBlock created by this markup has Text content of 'Product ID' and its color, font, etc are all set by the values stored in the Style. You can see the result in the Design pane screenshot below.&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/WPFListView/OneColumn.png"&gt;&lt;/P&gt;
&lt;P&gt;In the final version, I have added similar markup for the remaining two columns. I have left them out of the snippet above for brevity.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="TEXT-DECORATION: underline"&gt;Populating with Data&lt;/SPAN&gt;&lt;BR&gt;As I mentioned earlier, you need to use some form of data binding to populate the ListView. In this example I am using a simple XML file. You can view this file &lt;A href="http://www.xtabvbcity.plus.com/Blogs/WPFListView/Products.xml"&gt;here&lt;/A&gt;. The markup that creates the link between the application and the XML file is straightforward: &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;XmlDataProvider&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;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductList"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Products.xml" /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;It uses an XMLDataProvider which I've keyed as 'ProductList' so that it can be referred to elsewhere in the project. The source data comes from the Products.xml file, which is located with the other project files in Solution Explorer.&lt;/P&gt;
&lt;P&gt;Now that we have a data source, the ListView's ItemsSource property can be set to point to it. The markup is a bit tortuous, but not as complex as it might first appear. Essentially, the ItemsSource property is assigned a Binding and that Binding links to the ProductsList data provider. From the ProductsList, XPath syntax is used to point directly to the Product elements in the XML file. XPath isn't always the easiest syntax to use, but in the case of our simple XML file this is relatively straightforward.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;={&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ProductList&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;},&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; XPath&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=Products&lt;/SPAN&gt;/&lt;SPAN style="COLOR: #0000ff"&gt;Product}"&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Next, the various columns can be bound to the appropriate fields. The GridViewColumn has a DisplayMemberBinding property which , as its name implies, sets the Binding to be used for the content of the column. Once again, XPath is used for this.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #ff0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;DisplayMemberBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; XPath&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=ProductID}"&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;In the above snippet, DisplayMemberPath is assigned a Binding which links back to the ProductID element of the Products.xml file. (Note: If the field in the data source is an XML Attribute, as opposed to an Element, it is necessary to add a leading @ symbol to the XPath name.)&lt;/P&gt;
&lt;P&gt;For this basic ListView, that's all that is needed. You can view the Application.xaml file &lt;A href="http://www.xtabvbcity.plus.com/Blogs/WPFListView/Application.xml"&gt;here&lt;/A&gt;, and the markup for the Window &lt;A href="http://www.xtabvbcity.plus.com/Blogs/WPFListView/Window2.xml"&gt;here&lt;/A&gt;. In a future blog, I'll improve this basic version and look at some other functionality, but if you haven't previously dealt with WPF ListViews I hope this will get you started.&lt;/P&gt;&lt;/SPAN&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9382.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>How To Create a Splash Screen with WPF</title><link>http://blogs.vbcity.com/xtab/archive/2009/08/25/9381.aspx</link><pubDate>Tue, 25 Aug 2009 19:57:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/08/25/9381.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9381.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9381.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/08/25/9381.aspx#comment</comments><slash:comments>352</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9381.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: Calibri"&gt;
&lt;P&gt;One small but sometimes useful new feature that was bundled with Service Pack 1 (SP1) of Visual Studio 2008 is the Splash Screen feature of WPF. This enables you to create an image file which is then used as splash while the main application spins up and loads.&lt;/P&gt;
&lt;P&gt;Probably the main selling point of this feature is its ease of use. Here are the steps involved:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Create or select a suitable image file &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Add it to the project in the Solution Explorer. &lt;/LI&gt;
&lt;LI&gt;Left-click on the file name in Solution Explorer to select it &lt;/LI&gt;
&lt;LI&gt;Set its Build Action to Splash Screen. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;I chose to use a simple image with some text, but you can be as artistic as you like &lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/LoadingScreen.png"&gt;&lt;/P&gt;
&lt;P&gt;At its simplest, that's really all there is to it. If you run the project now, you will see the splash screen appear, followed by the main startup form of the application. If you have a fast machine and a small project, the length of time the splash screen appears may be very short. &lt;/P&gt;
&lt;P&gt;This isn't necessarily a problem. After all, the idea is usually to reassure the user that something is happening in the background. If the boot up time is short, then maybe you don't need a splash screen at all. &lt;/P&gt;
&lt;P&gt;Of course, you may not know the speed of systems on which your application is going to be installed. Or you may have an opening message that you particularly want to display in any event. In that case, you need some way of controlling how long the splash screen stays on view. And as you probably guessed, this feature is also available.&lt;/P&gt;
&lt;P&gt;Remembering that the splash screen is shown at the very start of the application life cycle, it makes sense for the code to be placed in the Application.xaml.vb file. Specifically, in the Application_Startup event. &lt;/P&gt;
&lt;P&gt;There are three elements to the code required. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The first step is to create a variable for the required splash screen. &lt;/LI&gt;
&lt;LI&gt;The second step is to turn off the AutoClose option of the splash screen (this being the option that you will have seen if you followed the steps first described above). &lt;/LI&gt;
&lt;LI&gt;Finally, you use the Close method of the splash screen, but set a TimeSpan for the delay before the splash screen totally disappears. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;That expression 'totally disappears' bears a little more explanation. What actually happens is that the splash screen fades from an Opacity level of 1 (fully opaque) to a level of 0 (completely transparent) over the period set by the TimeSpan.&lt;/P&gt;
&lt;P&gt;Here is the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt; Application_Startup(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; System.Windows.StartupEventArgs) &lt;SPAN style="COLOR: #0000ff"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Me&lt;/SPAN&gt;.Startup&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;Dim&lt;/SPAN&gt; splash &lt;SPAN style="COLOR: #0000ff"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; System.Windows.SplashScreen(&lt;SPAN style="COLOR: #a31515"&gt;"LoadingScreen.png"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; splash.Show(&lt;SPAN style="COLOR: #0000ff"&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; splash.Close(&lt;SPAN style="COLOR: #0000ff"&gt;New&lt;/SPAN&gt; TimeSpan(0, 0, 6))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;The above snippet displays the splash screen for 6 seconds. &lt;/P&gt;
&lt;P&gt;In most cases, the splash screen works best if you just use it in those cases where you genuinely have, or expect, a delay in the startup. One problem otherwise is that you have to start fiddling with the timing and possibly the opacity of the display of the startup Window so that it synchs with the splash screen. If you don't, then the startup Window may appear (fully opaque) while the splash screen is still gently fading out. This generally doesn't look right. But for a straightforward "Don't worry, this application is working" message to users, the WPF Splash Screen is great. &lt;/P&gt;
&lt;P&gt;If you haven't yet installed SP1, you can access it &lt;A href="http://www.microsoft.com/downloads/details.aspx?familyid=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;/SPAN&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9381.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Using the ElementHost in Visual Studio 2010</title><link>http://blogs.vbcity.com/xtab/archive/2009/07/31/9369.aspx</link><pubDate>Fri, 31 Jul 2009 19:52:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/07/31/9369.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9369.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9369.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/07/31/9369.aspx#comment</comments><slash:comments>169</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9369.aspx</trackback:ping><source url="http://blogs.vbcity.com/xtab/rss.aspx">XTab's Blog</source><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: calibri"&gt;&lt;/SPAN&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I'm a big fan of WPF and WinForms Interop, so have often advised people to try the ElementHost when they want to do something graphically complex on a Windows Form. This useful little container allows you to create a WPF UserControl right there inside the WinForms project and then display those WPF graphics in a Windows Form. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;One of the negative things about this in VS 2008 is that you always get a kind of error message inside the ElementHost at Design Time which reads "Unable to generate a preview". It's not really an error, but it is negative feedback.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Error.png"&gt;&lt;/P&gt;
&lt;P&gt;Although this message is disconcerting at first, you soon get used to it, and the WPF UserControl will display nicely once you actually run the project. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I was hoping that VS 2010 would fix this issue and that you would be able to see the WPF content in the ElementHost right there on the Window at Design time. The good news is that you can. The bad news is that the pseudo-error has been replaced with a genuine error!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; The error message is: "Type 'WindowsFormsIntegration.Design.HostedComponent' is not available in the target framework". This message appears whether you choose Version 3.5 or 4 of the .NET Framework for the project. I was particularly surprised that I still got the error with 3.5 apps. You wouldn't have thought that a problem with v4 would be a breaking change in the earlier Framework, but this seems to be the case. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; Anyway, I did some searching and found the fix documented in the &lt;A href="http://download.microsoft.com/download/7/A/0/7A023209-096F-4F7D-B2BC-831ECC68FF5B/NetFramework4Readme.htm#Windows Presentation Foundation (WPF)"&gt;Microsoft .NET Framework 4 Beta 1 Readme&lt;/A&gt;. It requires an additional Reference which is tucked away in the Visual Studio 2010 sub-folder in the Program Files folder. The exact path in my installation is: &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\WindowsFormsIntegration.Design.dll &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;You have to use the 'Browse' Tab instead of the more usual .NET tab of course to find and add this dll. You may also see a further warning message regarding the use of this dll with earlier versions of the Framework. This indicates that if you have your Framework set to 3.5 you don't need this dll (because it is a Framework 4 requirement). However, I couldn't get ElementHost to work properly in either 3.5 or 4 mode before I added this Reference, so that all left me a little confused - but happy, because it now works as it should. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Having sorted that out, I can now see the WPF UserControl on the Windows Form at Design Time, as you can see from the screenshot below. This is much more useful because it is often necessary to tweak the layout of the UserControl or other settings to make it fit in with the layout of other Windows Forms controls on the Form. Now that I can see it at Design time, I don't have to keep running and re-running the project to see the effect of changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I hope that this requirement to add the reference will be fixed by the time the final version of VS 2010 ships, but in the meantime I'll not complain about the small amount of work needed to gain the additional benefit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/ElementHost.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Don't forget that you should already have the standard: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;PresentationCore 
&lt;LI&gt;PresentationFramework 
&lt;LI&gt;WindowsBase 
&lt;LI&gt;WindowsFormsIntegration &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;References in place for this kind of Interop task. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9369.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>How To Format a String to Currency</title><link>http://blogs.vbcity.com/xtab/archive/2009/07/31/9368.aspx</link><pubDate>Fri, 31 Jul 2009 19:47:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/07/31/9368.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9368.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9368.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/07/31/9368.aspx#comment</comments><slash:comments>113</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9368.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;Here's a useful little tip for if you have a numeric value and you need to convert it into your local currency.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Let's assume you take in a value as a Double and you want the output to be in the format of currency, with two decimal places (in the case of the UK to represent Pence).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Here's the Double:&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="BACKGROUND-COLOR: #e0e0e0; FONT-FAMILY: 'Courier New'; FONT-SIZE: 15px; OVERFLOW: auto"&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; TotalCost&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Double&lt;/FONT&gt; = 123.4567&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;To show this formatted, you can use the String.Format method, a placeholder for the variable and the 'c' attribute to ensure the currency format is used:&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="BACKGROUND-COLOR: #e0e0e0; FONT-FAMILY: 'Courier New'; FONT-SIZE: 15px; OVERFLOW: auto"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Label1.Text =&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;.Format(&lt;FONT color=#a31515&gt;"Total Cost = {0:c}"&lt;/FONT&gt;, TotalCost)&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The result would look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/Currency.png"&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Notice that it automatically rounds up for you, changing '4567' to '46'. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9368.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>Sorting Arrays</title><link>http://blogs.vbcity.com/xtab/archive/2009/07/06/9352.aspx</link><pubDate>Mon, 06 Jul 2009 08:14:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/07/06/9352.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9352.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9352.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/07/06/9352.aspx#comment</comments><slash:comments>102</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9352.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;Sorting a single array is a simple task. You just run the Shared Sort method on the array:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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; arCustomers() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt; = {&lt;SPAN style="COLOR: #a31515"&gt;"Williams"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Brown"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Smith"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Jones"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&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; Array.Sort(arCustomers)&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; &lt;SPAN style="COLOR: blue"&gt;Each&lt;/SPAN&gt; Str &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;In&lt;/SPAN&gt; arCustomers&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; Console.WriteLine(Str)&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;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The resulting output is:&lt;/P&gt;&lt;FONT size=2 face="Courier New"&gt;
&lt;P&gt;Brown &lt;BR&gt;Green &lt;BR&gt;Jones &lt;BR&gt;Smith &lt;BR&gt;Williams&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;Things get more complicated if you have two arrays that have a logical link - maybe one array contains a list of names and a second array contains a numeric value for each of those names:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; arNames() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt; = {&lt;SPAN style="COLOR: #a31515"&gt;"Smith"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Jones"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"White"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Mead"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Knobbe"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Baranovsky"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Bonner"&lt;/SPAN&gt;}&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; arIDNumber() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Integer&lt;/SPAN&gt; = {234, 123, 765, 999, 357, 543, 666}&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If you want to sort the Names array so that the name with the lowest IDNumber is first and the name with the highest IDNumber is last, then you can use an overloaded version of the Sort method:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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; Sort the array of Names based on their IDNumbers&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Array.Sort(arIDNumber, arNames)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Note that you must assign the Key (the IDNumbers array) before the Item (the Names array) to get the correct result, which is:&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2 face="Courier New"&gt;Jones &lt;BR&gt;Smith &lt;BR&gt;Knobbe &lt;BR&gt;Baranovsky &lt;BR&gt;Bonner &lt;BR&gt;White &lt;BR&gt;Mead&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Jones has an IDNumber of 123 and Mead has an IDNumber of 999.&lt;/P&gt;
&lt;P&gt;Of course, the sort doesn't have to have a numeric key. It is just as easy to sort the IDNumber values based on the alphabetical order of the Names, if this is needed.&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Array.Sort(arNames, arIDNumber)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;One potential Gotcha that isn't immediately obvious is that this Sort action will also sort the IDNumber array at the same time. It makes complete sense for this to happen when you think about it, but if for some reason you only wanted the re-sorted arrays to be temporary, you will have take a slightly different approach.&lt;/P&gt;
&lt;P&gt;One of the easiest ways is to create a clone of the original arrays and you can sort the cloned copies while leaving the original in their default order.&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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; arNames2() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt; = arNames.Clone()&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; arScores2() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Integer&lt;/SPAN&gt; = arIDNumber.Clone()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Array.Sort(arScores2, arNames2)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You will then have your original arrays left unchanged and the index sorted versions available for use.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9352.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><item><title>How To Animate a Gradient Brush</title><link>http://blogs.vbcity.com/xtab/archive/2009/07/05/9349.aspx</link><pubDate>Sun, 05 Jul 2009 19:29:00 GMT</pubDate><guid isPermaLink="true">http://blogs.vbcity.com/xtab/archive/2009/07/05/9349.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9349.aspx</wfw:comment><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9349.aspx</wfw:commentRss><comments>http://blogs.vbcity.com/xtab/archive/2009/07/05/9349.aspx#comment</comments><slash:comments>98</slash:comments><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9349.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;In &lt;A href="http://blogs.vbcity.com/xtab/archive/2009/07/03/9348.aspx"&gt;the previous blog item&lt;/A&gt; in this series, I created a simple Animation in Visual Basic Code. This used a DoubleAnimation to animate the thickness of the gradient border. That example doesn't even begin to scratch the surface of what you can achieve with WPF Animation and - as you have seen demonstrated in the previous items - how you can include these animations in Windows Forms. &lt;/P&gt;
&lt;P&gt;In this part, we will look at a slightly more complex animation. Or at least one that seems complex at first, but a quick analysis reveals that it is really rather simple and easily created by writing the XAML by hand.&lt;/P&gt;
&lt;P&gt;In order to see the animation effect, I recommend you download the HandBuiltAnimation project &lt;A href="http://www.xtabvbcity.plus.com/Blogs/HandBuiltAnimation.zip"&gt;from here&lt;/A&gt; and run it. When you click the Button if there is no text in the TextBox, two animations will run. The first is the resize border one that was covered in the previous blog. The second animation changes the position of each of the colors in the gradient to give the impression of movement. &lt;/P&gt;
&lt;P&gt;If you are new to WPF, you perhaps won't be too comfortable with the idea of hand-writing the XAML. You can of course use a tool, such as Expression Blend, to create the XAML for you. A time-limited trial version of Expression Blend is available, so if you decide that the hand-written route isn't for you, then you can certainly use Blend instead. (That said, there is something of a learning curve involved in getting to grips with Blend too - especially if, like me, you have more of a Developer mindset than Designer). &lt;/P&gt;
&lt;P&gt;One of the reasons I decided to add this part to the blog was that sometimes you need to start the animation running from some user action. In this case, the user action will be the clicking of a button on a totally unrelated UI - a Windows Form, as it happens (although of course the same approach works fine with an all-WPF application too.) &lt;/P&gt;
&lt;P&gt;So, firstly, here is the XAML that goes in the WPF UserControl to create the moving gradient effect:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;Storyboard&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;="MoveColors"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DoubleAnimation&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;By&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Duration&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:1.3"&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;AutoReverse&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True"&lt;/SPAN&gt;&amp;nbsp; &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;Storyboard.TargetName&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; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetProperty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BorderBrush.GradientStops[6].Offset"&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;BeginTime&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:0.6"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DoubleAnimation&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;By&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Duration&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:1.3"&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: red"&gt;AutoReverse&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; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetName&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; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetProperty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BorderBrush.GradientStops[5].Offset"&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;BeginTime&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:0.6" /&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DoubleAnimation&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;By&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Duration&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:1.3"&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: red"&gt;AutoReverse&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;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetName&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; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetProperty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BorderBrush.GradientStops[4].Offset"&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;BeginTime&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:0.6" /&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DoubleAnimation&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;By&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Duration&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:1.3"&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: red"&gt;AutoReverse&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; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetName&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; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetProperty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BorderBrush.GradientStops[3].Offset"&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;BeginTime&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:0.6" /&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DoubleAnimation&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;By&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Duration&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:1.3"&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: red"&gt;AutoReverse&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;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetName&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; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetProperty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BorderBrush.GradientStops[2].Offset"&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;BeginTime&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:0.6" /&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DoubleAnimation&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;By&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Duration&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:1.3"&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: red"&gt;AutoReverse&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: red"&gt;Storyboard.TargetName&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; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetProperty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BorderBrush.GradientStops[1].Offset"&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;BeginTime&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:0.6" /&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp; &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; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DoubleAnimation&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;By&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Duration&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:1.3"&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: red"&gt;AutoReverse&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;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetName&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; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetProperty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BorderBrush.GradientStops[0].Offset"&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;BeginTime&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:0.6" /&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;&lt;/&lt; SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Storyboard&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;That may look like a lot of typing, but there's a whole lot of repetition in there, which means you can copy and paste the majority of it, then just make minor tweaks.&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;Storyboard&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;="MoveColors"&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;The first line shown above simply creates a new Storyboard instance and assigns it a name, or Key, that we can use to reference it.&lt;/P&gt;
&lt;P&gt;The next block creates a DoubleAnimation. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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;DoubleAnimation&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;By&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Duration&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:1.3"&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;AutoReverse&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True"&lt;/SPAN&gt;&amp;nbsp; &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;Storyboard.TargetName&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; &lt;SPAN style="COLOR: red"&gt;Storyboard.TargetProperty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BorderBrush.GradientStops[6].Offset"&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;BeginTime&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0:0:0.6"&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;Most of us tend not to think of Types such as Double numeric values when we are thinking about animation. In our mind's eye we are more likely to picture the physical result of such a change - the size of an element or its position, its shape or its color, perhaps. But it is perfectly possible to change the value of a Double Type, taking a set amount of time to make the change, and then having this change be visible to a user by assigning it to a property of an element that takes type Double. &lt;/P&gt;
&lt;P&gt;That's exactly what we are doing here - changing the value of the Double that is being used to set the position of a GradientStop in a LinearGradientBrush. Here's a more detailed breakdown of what's going on: &lt;/P&gt;
&lt;P&gt;&lt;B&gt;By &lt;/B&gt;changes the Double value by the amount stated - in this case by 0.2. In our demonstration animation this moves one of the colors that make up the gradient 0.2 along the gradient's linear scale.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Duration&lt;/B&gt; sets the length of time taken to change the value from its starting value to the end of the By value. In this case it is 1.3 seconds.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;AutoReverse&lt;/B&gt; set to True will ensure that the value returns to its starting value by the end of the Duration. In our gradient example this will cause the color to move 0.2 out and then return the same 0.2 distance back.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Storyboard.TargetName &lt;/B&gt;uses the WPF Attached Property syntax to identify which element is the target of the animation. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Storyboard.TargetProperty&lt;/B&gt; in a similar way identifies the property of the target element which is to be animated. See the further explanation below about the identification of the property. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;BeginTime&lt;/B&gt; is an optional pause feature. The animation will only begin after an initial pause of (in this example) 0.6 seconds. &lt;/P&gt;
&lt;P&gt;The TargetProperty in each of these DoubleAnimations is the Offset value of a GradientStop. If you look at the XAML which creates the BrightGradient LinearGradientBrush, you will see that it contains seven colors, each of which has its position in the gradient assigned by its Offset value. All we are doing in this animation is shunting each of the colors along by a value of 0.2 and this creates the effect of the color movement. &lt;/P&gt;
&lt;P&gt;The particular block of XAML shown above animates the last GradientStop, which has an index of 6 - the index being zero based. When you look at the six DoubleAnimations which follow that one, the only difference is that the Index has changed so that the next GradientStop is targeted. So by copying and pasting the first DoubleAnimation, pasting it six times and then changing the value of the Index, this complex looking animation is shown to be very basic in reality. &lt;/P&gt;
&lt;P&gt;All that remains now is to wire up this Storyboard in the code-behind. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&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; MoveColors()&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; SB &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; Storyboard = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(FindResource(&lt;SPAN style="COLOR: #a31515"&gt;"MoveColors"&lt;/SPAN&gt;), Storyboard)&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; SB &lt;SPAN style="COLOR: blue"&gt;IsNot&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Nothing&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; SB.Begin(&lt;SPAN style="COLOR: blue"&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;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;"Can't find storyboard"&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;The FindResource method is very useful in these kind of situations in WPF. I used it in the original example to change the LinearGradientBrush on the Border element and now we can employ it to find the animation. It allows you to dig into the XAML, find the markup you need for a particular task and use it. In this cas, the Resource we are looking for is the Storyboard that has a Key of 'MoveColors' - the one we have just dissected above. &lt;/P&gt;
&lt;P&gt;Over in the Windows Forms Form1 code, the Button click has only one additional line. This calls the MoveColors procedure shown above, which in turn runs the animation. The additional line is:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-FAMILY: Courier New; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; MovingGradientTextBox1.MoveColors()&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You can see the remaining unchanged Button Click event code in the sample project attached.&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9349.aspx" width = "1" height = "1" /&gt;</description><dc:creator>Ged Mead</dc:creator></item><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>110</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>114</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>195</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>126</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>126</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>106</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>122</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>66</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>91</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>61</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>66</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;My new blog URL is &lt;A href="http://sergeb.com/blog/"&gt;http://sergeb.com/blog/&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;New feed is &lt;A href="http://feedproxy.google.com/SergeB"&gt;http://feedproxy.google.com/SergeB&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>159</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>118</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>68</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>117</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></channel></rss>
