<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>Visual Basic 2010</title><link>http://blogs.vbcity.com/xtab/category/219.aspx</link><description>... coming to a developer's workstation near you soon.</description><managingEditor>Ged Mead</managingEditor><dc:language>et</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Ged Mead</dc:creator><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 12:23:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/27/9429.aspx</guid><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></item><item><dc:creator>Ged Mead</dc:creator><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 12:41:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/26/9428.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9428.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2009/10/26/9428.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9428.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9428.aspx</trackback:ping><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></item><item><dc:creator>Ged Mead</dc:creator><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 13:26:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/25/9425.aspx</guid><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></item><item><dc:creator>Ged Mead</dc:creator><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 13:25:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/25/9424.aspx</guid><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></item><item><dc:creator>Ged Mead</dc:creator><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 13:22:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/25/9423.aspx</guid><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></item><item><dc:creator>Ged Mead</dc:creator><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 13:20:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/25/9421.aspx</guid><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></item><item><dc:creator>Ged Mead</dc:creator><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 13:18:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/25/9420.aspx</guid><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></item><item><dc:creator>Ged Mead</dc:creator><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 13:17:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/25/9419.aspx</guid><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></item><item><dc:creator>Ged Mead</dc:creator><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 13:12:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/10/25/9418.aspx</guid><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></item><item><dc:creator>Ged Mead</dc:creator><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 20:52:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/07/31/9369.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9369.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2009/07/31/9369.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9369.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9369.aspx</trackback:ping><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></item></channel></rss>