<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!-- generator="wordpress/2.2" --><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>.NET BLOG</title>
	<link>http://www.dotnet-blog.com</link>
	<description>Windows Presentation Foundation and more ...</description>
	<pubDate>Fri, 08 May 2009 06:49:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DotNetBlogCom" /><feedburner:info uri="dotnetblogcom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Moonlight 2.0 Preview 1</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/Laoo1Cv0EL0/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/05/08/moonlight-20-preview-1/#comments</comments>
		<pubDate>Fri, 08 May 2009 06:49:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/05/08/moonlight-20-preview-1/</guid>
		<description><![CDATA[Moonlight is an implementation of Silverlight for Unix systems. Now, Moonlight 2.0 preview 1 is available and comes with many features.
The cool thing first: Moonlight is also available in a 64 bit version, not just a 32 bit version as Silverlight does!
&#160;
Find a list of features below:

First preview release. First release of a full Mono [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Moonlight" href="http://go-mono.com/moonlight-preview/" target="_blank"><img style="margin: 0px 5px 5px 0px; display: inline" border="0" alt="" align="left" src="http://blog.norberteder.com/images/moonlight_logo.png" width="75" height="94" /></a>Moonlight is an implementation of Silverlight for Unix systems. Now, <a href="http://go-mono.com/moonlight-preview/" target="_blank">Moonlight 2.0 preview 1</a> is available and comes with many features.</p>
<p>The cool thing first: Moonlight is also available in a 64 bit version, not just a 32 bit version as Silverlight does!</p>
<p>&#160;</p>
<p>Find a list of features below:</p>
<ul>
<li>First preview release. First release of a full Mono VM in a browser plugin. </li>
<li>Includes initial work on CoreCLR and metadata/instruction verification (<a href="http://www.moonlight-project.com/SecurityStatus"><strong>preview 1 security status</strong></a> (<i>http://www.moonlight-project.com/SecurityStatus</i>)) </li>
<li>Includes the Microsoft MS-PL Controls. </li>
<li>Negotiated layout, where controls can autosize themselves. We&#8217;ve also had big performance increase over recent svn in this department. </li>
<li>Includes deepzoom functionality, so sites like <a href="http://memorabilia.hardrock.com/"><strong>Hard Rock Cafe Memorabilia</strong></a> (<i>http://memorabilia.hardrock.com</i>) and <a href="http://playboy.covertocover.com/"><strong>The Playboy Archive (nsfw)</strong></a> (<i>http://playboy.covertocover.com</i>) should work. </li>
<li>Development tools for building xaps (if you build from source. stay tuned for a moonlight devel-esque rpm which will include them).</li>
</ul>
<p>Also, there are some Silverlight 3 features:</p>
<ul>
<li>ng functions </li>
<li>SaveFileDialog </li>
<li>MultiScaleImage 3.0 API enhancements </li>
<li>MediaStreamSource now supports PCM audio data, RGBA and YV12 video data. </li>
<li>WriteableBitmap is supported.</li>
</ul>
<p>Have a look at <a title="Moonlight Downloads" href="http://go-mono.com/moonlight-preview/" target="_blank">Moonlight’s Downloads page</a> as a good starting point.</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/Laoo1Cv0EL0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/05/08/moonlight-20-preview-1/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/05/08/moonlight-20-preview-1/</feedburner:origLink></item>
		<item>
		<title>XAML Power Toys 4.0 Released</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/cuU2OZ3sYVM/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/02/10/xaml-power-toys-40-released/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 19:35:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/02/10/xaml-power-toys-40-released/</guid>
		<description><![CDATA[Very cool. Just read on Karl’s blog that he has released a new version of his XAML Power Toys.
What the hell is that?
XAML Power Toys is a Visual Studio 2008 SP1 Multi-AppDomain Add-In that empowers WPF &#38; Silverlight developers while working in the XAML editor.&#160; Its Line of Business form generation tools, Grid tools,&#160; DataGrid [...]]]></description>
			<content:encoded><![CDATA[<p>Very cool. Just read on <a href="http://karlshifflett.wordpress.com/2009/02/10/xaml-power-toys-40-released-code-name-mvvm/" target="_blank">Karl</a>’s blog that he has released a new version of his <a href="http://karlshifflett.wordpress.com/xaml-power-toys/" target="_blank">XAML Power Toys</a>.</p>
<p>What the hell is that?</p>
<blockquote><p>XAML Power Toys is a Visual Studio 2008 SP1 Multi-AppDomain Add-In that empowers WPF &amp; Silverlight developers while working in the XAML editor.&#160; Its Line of Business form generation tools, Grid tools,&#160; DataGrid and ListView generation really shorten the XAML page layout time.</p>
</blockquote>
<p>New features? Of course:</p>
<li>Extract properties to a Style allows selecting a control, choosing desired properties and have those selected properties extracted to a newly created style </li>
<li>Create ViewModel Class from a VB.NET or C# code window.&#160; Easily create a ViewModel stub that includes commands and exposed data class. </li>
<li>Group into GroupBox </li>
<li>Option to generate x:Name for controls </li>
<li>Option to add ForeReRead converter to TextBox bindings (both VB.NET &amp; C# converters included in source and binary downloads.&#160; Converter is also included in the OceanFramework.WPF namespace.) </li>
<li>Option to add TargetNullValue to TextBox.Text bindings when Source property is Nullable </li>
<li>Corrected secondary application domain load issue reported by <a href="http://www.devexpress.com/Support/Center/p/B131164.aspx">DevExpress</a>.&#160; This fix also solves another edge case secondary application domain load issue.</li>
<p>And here is a screenshot to see the power of this Visual Studio add-in:</p>
<p><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/02/image3.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="70" alt="image" src="http://www.dotnet-blog.com/wp-content/uploads/2009/02/image-thumb3.png" width="244" border="0" /></a> </p>
<p>Very cool. Thank you Karl.</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/cuU2OZ3sYVM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/02/10/xaml-power-toys-40-released/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/02/10/xaml-power-toys-40-released/</feedburner:origLink></item>
		<item>
		<title>Loading and Saving Data of an InkCanvas Control</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/wmL0_L3mOMQ/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/02/10/loading-and-saving-data-of-an-inkcanvas-control/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 10:23:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/02/10/loading-and-saving-data-of-an-inkcanvas-control/</guid>
		<description><![CDATA[The InkCanvas control is a pretty cool control for drawing free-hand strokes. In most cases it will be necessary to save and load all strokes. Here is a simple approach how to accomplish this requirement.
Given is a very simple user interface: an InkCanvas control and some buttons for clearing the canvas, saving and loading data.
Here’s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/02/image2.png"><img title="WPF InkCanvas Control" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 5px 5px; border-right-width: 0px" height="157" alt="WPF InkCanvas Control" src="http://www.dotnet-blog.com/wp-content/uploads/2009/02/image-thumb2.png" width="157" align="right" border="0" /></a>The <font face="Courier New">InkCanvas</font> control is a pretty cool control for drawing free-hand strokes. In most cases it will be necessary to save and load all strokes. Here is a simple approach how to accomplish this requirement.</p>
<p>Given is a very simple user interface: an <font face="Courier New">InkCanvas</font> control and some buttons for clearing the canvas, saving and loading data.</p>
<p>Here’s the markup:</p>
<pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">DockPanel</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">StackPanel</span> <span style="color: #ff0000">DockPanel</span>.<span style="color: #ff0000">Dock</span>=<span style="color: #0000ff">&quot;Bottom&quot;</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">x</span>:<span style="color: #ff0000">Name</span>=<span style="color: #0000ff">&quot;ClearButton&quot;</span>
                <span style="color: #ff0000">Content</span>=<span style="color: #0000ff">&quot;Clear&quot;</span>
                <span style="color: #ff0000">Click</span>=<span style="color: #0000ff">&quot;ClearButton_Click&quot;</span><span style="color: #0000ff">/&gt;</span>

        <span style="color: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">x</span>:<span style="color: #ff0000">Name</span>=<span style="color: #0000ff">&quot;SaveButton&quot;</span>
                <span style="color: #ff0000">Content</span>=<span style="color: #0000ff">&quot;Save&quot;</span>
                <span style="color: #ff0000">Click</span>=<span style="color: #0000ff">&quot;SaveButton_Click&quot;</span><span style="color: #0000ff">/&gt;</span>

        <span style="color: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">x</span>:<span style="color: #ff0000">Name</span>=<span style="color: #0000ff">&quot;LoadButton&quot;</span>
                <span style="color: #ff0000">Content</span>=<span style="color: #0000ff">&quot;Load&quot;</span>
                <span style="color: #ff0000">Click</span>=<span style="color: #0000ff">&quot;LoadButton_Click&quot;</span><span style="color: #0000ff">/&gt;</span>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">InkCanvas</span> <span style="color: #ff0000">x</span>:<span style="color: #ff0000">Name</span>=<span style="color: #0000ff">&quot;DrawingPane&quot;</span><span style="color: #0000ff">/&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">DockPanel</span><span style="color: #0000ff">&gt;</span></pre>
<p>All the drawings are strokes. They are stored in the <font face="Courier New">Strokes</font>-Collection. Using <font face="Courier New">XamlWriter</font> and <font face="Courier New">XamlReader</font> we are able to (de)serialize this collection easily:</p>
<pre><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> SaveButton_Click(
    <span style="color: #0000ff">object</span> sender,
    RoutedEventArgs e)
{
    <span style="color: #0000ff">using</span> (XmlWriter xmlWriter =
                XmlWriter.Create(&quot;<span style="color: #8b0000">Strokes.xml</span>&quot;))
    {
        XamlWriter.Save(DrawingPane.Strokes, xmlWriter);
        xmlWriter.Flush();
    }

}

<span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> LoadButton_Click(
    <span style="color: #0000ff">object</span> sender,
    RoutedEventArgs e)
{
    <span style="color: #0000ff">object</span> tempObj = <span style="color: #0000ff">null</span>;

    <span style="color: #0000ff">using</span> (XmlReader xmlReader =
                XmlReader.Create(&quot;<span style="color: #8b0000">Strokes.xml</span>&quot;))
    {
        tempObj = XamlReader.Load(xmlReader);
    }

    <span style="color: #0000ff">if</span> (tempObj != <span style="color: #0000ff">null</span> &amp;&amp; tempObj <span style="color: #0000ff">is</span> StrokeCollection)
    {
        DrawingPane.Strokes.Clear();
        <span style="color: #0000ff">foreach</span> (Stroke s <span style="color: #0000ff">in</span> tempObj <span style="color: #0000ff">as</span> StrokeCollection)
            DrawingPane.Strokes.Add(s);
    }

}

<span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> ClearButton_Click(
    <span style="color: #0000ff">object</span> sender,
    RoutedEventArgs e)
{
    DrawingPane.Strokes.Clear();
}</pre>
<p>That’s all you have to do.</p>
<p>To to able to play a bit with it, here’s the download of the whole solution:</p>
<p><iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-c8d8cb313db8e795.skydrive.live.com/embedrowdetail.aspx/%c3%96ffentlich/Samples/InkCanvasDemo.zip" frameborder="0" scrolling="no"></iframe></p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/wmL0_L3mOMQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/02/10/loading-and-saving-data-of-an-inkcanvas-control/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/02/10/loading-and-saving-data-of-an-inkcanvas-control/</feedburner:origLink></item>
		<item>
		<title>Filtering and Sorting a ListBox</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/Eml7tQmRuII/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/02/06/filtering-and-sorting-a-listbox/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 19:42:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/02/06/filtering-and-sorting-a-listbox/</guid>
		<description><![CDATA[It’s easy to bind a collection to a list-control (e.g. ListBox, ListView and so on). In many cases it is necessary to sort or filter this list. This article shows how to do this.
Normally you have your source (Collection) which is bound to a list control. To enable sorting and filtering you have to use [...]]]></description>
			<content:encoded><![CDATA[<p>It’s easy to bind a collection to a list-control (e.g. ListBox, ListView and so on). In many cases it is necessary to sort or filter this list. This article shows how to do this.</p>
<p>Normally you have your source (Collection) which is bound to a list control. To enable sorting and filtering you have to use the <font face="Courier New">CollectionViewSource</font> as an decorator. This means: Provide your collection (e.g. within the resource section of your window) and create a <font face="Courier New">CollectionViewSource</font>. The property <font face="Courier New">Source</font> is bound to the collection. The <font face="Courier New">CollectionViewSource</font> provides mechanism for sorting, filtering and grouping data.</p>
<p>Let’s have a look at the sample. We use a class <font face="Courier New">Person</font> and a Collection of that type (both can be found in the sample application). Within the constructor of the collection some sample data is added (you won’t do that in reality, but it’s ok for a sample).</p>
<div class="CodeFormatContainer">
<pre class="csharpcode">&lt;Window x:Class=<span class="str">&quot;SortFilterDemo.MainWindow&quot;</span>
    xmlns=<span class="str">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>
    xmlns:x=<span class="str">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>
    xmlns:local=<span class="str">&quot;clr-namespace:SortFilterDemo&quot;</span>
    Title=<span class="str">&quot;Sort and Filter Sample&quot;</span>
    SizeToContent=<span class="str">&quot;WidthAndHeight&quot;</span>&gt;

    &lt;Window.Resources&gt;
        &lt;local:PersonCollection x:Key=<span class="str">&quot;PersonList&quot;</span>/&gt;
        &lt;CollectionViewSource
            x:Key=<span class="str">&quot;PersonViewSource&quot;</span>
            Source=<span class="str">&quot;{Binding Source={StaticResource PersonList}}&quot;</span>/&gt;

        &lt;DataTemplate DataType=<span class="str">&quot;{x:Type local:Person}&quot;</span>&gt;
            &lt;StackPanel Orientation=<span class="str">&quot;Horizontal&quot;</span>&gt;
                &lt;TextBlock Text=<span class="str">&quot;{Binding Path=LastName}&quot;</span>/&gt;
                &lt;TextBlock Text=<span class="str">&quot;, &quot;</span>/&gt;
                &lt;TextBlock Text=<span class="str">&quot;{Binding Path=FirstName}&quot;</span>/&gt;
            &lt;/StackPanel&gt;
        &lt;/DataTemplate&gt;
    &lt;/Window.Resources&gt;

    &lt;StackPanel&gt;
        &lt;TextBlock Text=<span class="str">&quot;People&quot;</span> FontWeight=<span class="str">&quot;Bold&quot;</span> FontSize=<span class="str">&quot;18&quot;</span> Margin=<span class="str">&quot;5&quot;</span>/&gt;
        &lt;ListBox
            ItemsSource=<span class="str">&quot;{Binding Source={StaticResource PersonViewSource}}&quot;</span>
            Margin=<span class="str">&quot;5&quot;</span>/&gt;
        &lt;StackPanel Orientation=<span class="str">&quot;Horizontal&quot;</span>&gt;
            &lt;Button x:Name=<span class="str">&quot;SortLastNameButton&quot;</span>
                    Content=<span class="str">&quot;Sort Lastname&quot;</span>
                    Click=<span class="str">&quot;SortLastNameButton_Click&quot;</span>
                    Margin=<span class="str">&quot;5&quot;</span>/&gt;
            &lt;Button x:Name=<span class="str">&quot;SortFirstNameButton&quot;</span>
                    Content=<span class="str">&quot;Sort Firstname&quot;</span>
                    Click=<span class="str">&quot;SortFirstNameButton_Click&quot;</span>
                    Margin=<span class="str">&quot;5&quot;</span>/&gt;
        &lt;/StackPanel&gt;
        &lt;CheckBox x:Name=<span class="str">&quot;FilterCheckBox&quot;</span>
                  IsChecked=<span class="str">&quot;False&quot;</span>
                  Content=<span class="str">&quot;Filter List&quot;</span>
                  Click=<span class="str">&quot;FilterCheckBox_Click&quot;</span>
                  Margin=<span class="str">&quot;5&quot;</span>/&gt;
    &lt;/StackPanel&gt;
&lt;/Window&gt;</pre>
</div>
<p>As you can see in the markup, there are three things created within the resource section of the window:</p>
<ul>
<li>First there is the instantiation of the base collection </li>
<li>Second there is an instantiation of the CollectionViewSource which has a binding to the base collection </li>
<li>Third there is a data template declared. This describes the appearance of each entry. </li>
</ul>
<p>The <font face="Courier New">ListBox</font> element has a binding to the <font face="Courier New">CollectionViewSource</font>. Furthermore there are two buttons which are used for defining the sorting. Last but not least there is a checkbox element for turning on or off the filtering. As you can see there is some code behind necessary. Let’s have a look on it:</p>
<div class="CodeFormatContainer">
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> FilterCheckBox_Click(<span class="kwrd">object</span> sender, RoutedEventArgs e)
{
    CollectionViewSource collSource =
        FindResource(<span class="str">&quot;PersonViewSource&quot;</span>) <span class="kwrd">as</span> CollectionViewSource;
    <span class="kwrd">if</span> (collSource != <span class="kwrd">null</span>)
    {
        <span class="kwrd">if</span> (FilterCheckBox.IsChecked == <span class="kwrd">true</span>)
        {
            collSource.Filter += collSource_Filter;
        }
        <span class="kwrd">else</span>
        {
            collSource.Filter -= collSource_Filter;
        }
    }
}

<span class="kwrd">void</span> collSource_Filter(<span class="kwrd">object</span> sender, FilterEventArgs e)
{
    Person pers = e.Item <span class="kwrd">as</span> Person;
    <span class="kwrd">if</span> (pers != <span class="kwrd">null</span>)
    {
        <span class="kwrd">if</span> (pers.LastName.Equals(<span class="str">&quot;Eder&quot;</span>,
            StringComparison.InvariantCultureIgnoreCase))
            e.Accepted = <span class="kwrd">true</span>;
        <span class="kwrd">else</span>
            e.Accepted = <span class="kwrd">false</span>;
    }
}

<span class="kwrd">private</span> <span class="kwrd">void</span> SortLastNameButton_Click(<span class="kwrd">object</span> sender, RoutedEventArgs e)
{
    Sort(<span class="str">&quot;LastName&quot;</span>);
}

<span class="kwrd">private</span> <span class="kwrd">void</span> SortFirstNameButton_Click(<span class="kwrd">object</span> sender, RoutedEventArgs e)
{
    Sort(<span class="str">&quot;FirstName&quot;</span>);
}

<span class="kwrd">private</span> <span class="kwrd">void</span> Sort(String propertyName)
{
    CollectionViewSource collSource =
        FindResource(<span class="str">&quot;PersonViewSource&quot;</span>) <span class="kwrd">as</span> CollectionViewSource;
    <span class="kwrd">if</span> (collSource != <span class="kwrd">null</span>)
    {
        collSource.SortDescriptions.Clear();
        collSource.SortDescriptions.Add(<span class="kwrd">new</span> SortDescription(propertyName,
            ListSortDirection.Ascending));
    }
}</pre>
</div>
<p>There are event handlers for the buttons which call a method called Sort. This method has one parameter defining the property we want to use for sorting. Within the Sort method we add an entry to the <font face="Courier New">SortDescriptions</font> collection of the <font face="Courier New">CollectionViewSource</font>. That’s all of the magic stuff.</p>
<p>For the filter functionality we use a <font face="Courier New">CheckBox</font> control which is used to turn the filtering on or off. If turned on, an event handler is added for the <font face="Courier New">Filter</font> event. If turned of, the event handler is removed.</p>
<p>The handler is called for each entry in the collection. There we can define our behavior. Use the <font face="Courier New">Accecpeted</font> property of the event arguments for setting the visibility of the entry.</p>
<p>Here’s a screenshot of the sample application:</p>
<p><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/02/image1.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="171" alt="image" src="http://www.dotnet-blog.com/wp-content/uploads/2009/02/image-thumb1.png" width="187" border="0" /></a> </p>
<p>And here is the download:</p>
<p><iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-c8d8cb313db8e795.skydrive.live.com/embedrowdetail.aspx/%c3%96ffentlich/Samples/SortFilterDemo.zip" frameborder="0" scrolling="no"></iframe></p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/Eml7tQmRuII" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/02/06/filtering-and-sorting-a-listbox/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/02/06/filtering-and-sorting-a-listbox/</feedburner:origLink></item>
		<item>
		<title>Organize your ToDos easily</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/Dt5cNFKZOmw/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/02/05/organize-your-todos-easily/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 17:10:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/02/05/organize-your-todos-easily/</guid>
		<description><![CDATA[As a developer/consultant it’s absolutely necessary to have an overview over all your tasks. There are a some different approaches (e.g. GTD, Getting Things Done). In reality there is very often one problem:
You own several computers and you want to edit your todos wherever you are. In fact you need a system where your data [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer/consultant it’s absolutely necessary to have an overview over all your tasks. There are a some different approaches (e.g. GTD, Getting Things Done). In reality there is very often one problem:</p>
<p>You own several computers and you want to edit your todos wherever you are. In fact you need a system where your data is stored at one place. Maybe you have Microsoft Exchange or something like that. But the possibilities are not the best ones and maybe you can use it just in combination with your job.</p>
<p>So, what’s an easy solution?</p>
<p>There is a very famous tool at <a href="http://www.codeproject.com" target="_blank">The Code Project</a>, called <a href="http://www.codeproject.com/KB/applications/todolist2.aspx" target="_blank">ToDoList</a>. It’s a very cool tool with a lot of options.</p>
<p><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/02/image.png"><img title="ToDoList" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="193" alt="ToDoList" src="http://www.dotnet-blog.com/wp-content/uploads/2009/02/image-thumb.png" width="244" border="0" /></a> </p>
<p>It allows to have different data files for different projects, customers or whatever. So, what you can do is: Install <a href="http://www.dotnet-blog.com/index.php/2009/01/02/live-mesh-a-summary/" target="_blank">Windows Live Mesh</a> and this tool on every computer you own. Store all the data files of ToDoList within the Mesh folder and you have them available, independent which computer you use and where you are.</p>
<p>This is a very simple solution, cheap and you have a powerful tool for managing your todos.</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/Dt5cNFKZOmw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/02/05/organize-your-todos-easily/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/02/05/organize-your-todos-easily/</feedburner:origLink></item>
		<item>
		<title>RSS Feed URI has changed</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/w-EAWtO6LvY/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/02/04/rss-feed-uri-has-changed/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 09:06:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/02/04/rss-feed-uri-has-changed/</guid>
		<description><![CDATA[Due to some reasons I had to change the location of my RSS feed.The new feed is located athttp://feeds2.feedburner.com/DotNetBlogCom
Copyright &#169; 2009 .NET BLOG. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.dotnet-blog.com/wp-content/themes/ShinyRoad/images/rss_feed.png" align="left" style="display: inline; margin: 0px" />Due to some reasons I had to change the location of my RSS feed.The new feed is located at<a href="http://feeds2.feedburner.com/DotNetBlogCom">http://feeds2.feedburner.com/DotNetBlogCom</a></p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/w-EAWtO6LvY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/02/04/rss-feed-uri-has-changed/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/02/04/rss-feed-uri-has-changed/</feedburner:origLink></item>
		<item>
		<title>WPF Blogger now with Spanish Blogs</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/0daFsbOzNbA/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/01/31/wpf-blogger-now-with-spanish-blogs/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 18:10:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/01/31/wpf-blogger-now-with-spanish-blogs/</guid>
		<description><![CDATA[ 
Some of you may know my project wpf-blogger.com. It’s currently a feed aggregation system for WPF and Silverlight developers. Till now it was available in German, English and French language. Today I added a new language: Spanish. I was asked several times to do this but till now I didn’t know any blogs about [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/01/wpf-blogger.png"><img title="wpf_blogger" style="border-right: 0px; border-top: 0px; display: inline; margin: 0px 5px 5px 0px; border-left: 0px; border-bottom: 0px" height="80" alt="wpf_blogger" src="http://www.dotnet-blog.com/wp-content/uploads/2009/01/wpf-blogger-thumb.png" width="145" align="left" border="0" /></a> </p>
<p>Some of you may know my project <a href="http://wpf-blogger.com" target="_blank">wpf-blogger.com</a>. It’s currently a feed aggregation system for WPF and Silverlight developers. Till now it was available in German, English and French language. Today I added a new language: Spanish. I was asked several times to do this but till now I didn’t know any blogs about WPF and Silverlight written in Spanish. </p>
<p>So, If there are some Spanish speaking people out there knowing another useful blogs, please leave a message.</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/0daFsbOzNbA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/01/31/wpf-blogger-now-with-spanish-blogs/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/01/31/wpf-blogger-now-with-spanish-blogs/</feedburner:origLink></item>
		<item>
		<title>DataTemplate + DataType + x:Type + Inner Class –&gt; Type not found</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/6VL3UM55feY/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/01/31/datatemplate-datatype-xtype-inner-class-type-not-found/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 13:37:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/01/31/datatemplate-datatype-xtype-inner-class-type-not-found/</guid>
		<description><![CDATA[When creating a data template you have two possibilities to define the property DataType:

Use it as a simple property setter. 
Use the type markup extension to define the type

If you use the type markup extension in combination with an inner class you might run into the problem that your type won’t be found. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>When creating a data template you have two possibilities to define the property <font face="Courier New">DataType</font>:</p>
<ul>
<li>Use it as a simple property setter. </li>
<li>Use the type markup extension to define the type</li>
</ul>
<p>If you use the type markup extension in combination with an inner class you might run into the problem that your type won’t be found. Here is an example. </p>
<p>We use the following class:</p>
<pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Demo
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> DataItem
    {
        <span style="color: #0000ff">public</span> DataItem(<span style="color: #0000ff">string</span> last, <span style="color: #0000ff">string</span> first)
        {
            LastName = last;
            FirstName = first;
        }

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> LastName { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FirstName { <span style="color: #0000ff">get</span>; <span style="color: #0000ff">set</span>; }

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">string</span> ToString()
        {
            <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.LastName + &quot;<span style="color: #8b0000">, </span>&quot; + <span style="color: #0000ff">this</span>.FirstName;
        }
    }
}</pre>
<p>As you can see, there is an inner class called <font face="Courier New">DataItem</font>, which is the type we want to use for the <font face="Courier New">DataType </font>of an data template.</p>
<p>Now let us have a look on the data template definition. Your first try might be the following one:</p>
<pre>&lt;DataTemplate x:Key=&quot;<span style="color: #8b0000">DataItemTemplate</span>&quot;
              DataType=&quot;<span style="color: #8b0000">{x:Type local:DataItem}</span>&quot;&gt;</pre>
<p>This won’t work, as the type couldn’t be found. Now you might use the complete indirection:</p>
<pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">DataTemplate</span> <span style="color: #ff0000">x</span>:<span style="color: #ff0000">Key</span>=<span style="color: #0000ff">&quot;DataItemTemplate&quot;</span>
              <span style="color: #ff0000">DataType</span>=<span style="color: #0000ff">&quot;{x:Type local:Demo.DataItem}&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<p>You’ll also receive an error.</p>
<p>The solution is to use the type as you will receive it with a <font face="Courier New">GetType().Name</font>:</p>
<pre><span style="color: #0000ff">&lt;</span><span style="color: #800000">DataTemplate</span> <span style="color: #ff0000">x</span>:<span style="color: #ff0000">Key</span>=<span style="color: #0000ff">&quot;DataItemTemplate&quot;</span>
              <span style="color: #ff0000">DataType</span>=<span style="color: #0000ff">&quot;{x:Type local:Demo+DataItem}&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<p>That’s the trick.</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/6VL3UM55feY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/01/31/datatemplate-datatype-xtype-inner-class-type-not-found/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/01/31/datatemplate-datatype-xtype-inner-class-type-not-found/</feedburner:origLink></item>
		<item>
		<title>WPF PropertyGrid Control Updated</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/YAwCfWoYduc/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/01/29/wpf-propertygrid-control-updated/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 17:49:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/01/29/wpf-propertygrid-control-updated/</guid>
		<description><![CDATA[The WPF PropertyGrid Control has been updated today. It’s a pretty cool control having a lot of features. Here is a list:

100% WPF Component (no Windows Forms interop, no native code calls, etc.) 
Same property editing approach introduced by Visual Studio 2008 WPF Designer (&#34;Cider&#34;) and Expression Blend, same steps for creating inline and dialog [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/01/wpfpropertygrid01.png"><img title="WPF PropertyGrid" style="border-right: 0px; border-top: 0px; display: inline; margin: 0px 0px 0px 10px; border-left: 0px; border-bottom: 0px" height="244" alt="WPF PropertyGrid" src="http://www.dotnet-blog.com/wp-content/uploads/2009/01/wpfpropertygrid01-thumb.png" width="136" align="right" border="0" /></a>The <a href="http://www.codeplex.com/wpfpropertygrid" target="_blank">WPF PropertyGrid Control</a> has been updated today. It’s a pretty cool control having a lot of features. Here is a list:</p>
<ul>
<li>100% WPF Component (no Windows Forms interop, no native code calls, etc.) </li>
<li>Same property editing approach introduced by Visual Studio 2008 WPF Designer (&quot;Cider&quot;) and Expression Blend, same steps for creating inline and dialog based editors </li>
<li>Built-in property editors and support for editors customization, injection </li>
<li>Property grouping, sorting and filtering, property display schemas based on multiple rule sets </li>
<li>Several display modes for properties (Native CLR properties, Dependency properties, All properties) </li>
<li>Optional display of Attached or Read-only properties </li>
<li>Category initial mode configuration (expanded or collapsed by default) </li>
<li>Property metadata (DisplayNameAttribute, CategoryAttribute, DescriptionAttribute, etc) and ICustomTypeDescriptor support </li>
<li>All property metadata is accessible from custom editors, MetadataStore support </li>
<li>Property &quot;Search Box&quot; with live view updates, possibility to hide/show search box </li>
<li>Basic support for Windows Forms interopability, display of non-dependency objects, integration into Windows Forms application)</li>
</ul>
<p>And there are <a href="http://www.codeplex.com/wpfpropertygrid/Wiki/View.aspx?title=full%20feature%20list&amp;referringTitle=Home" target="_blank">more features</a>.</p>
<p>How does it look like? Here are some screens:</p>
<p><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/01/wpfpropertygrid02.png"><img title="WPF PropertyGrid" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="113" alt="WPF PropertyGrid" src="http://www.dotnet-blog.com/wp-content/uploads/2009/01/wpfpropertygrid02-thumb.png" width="244" border="0" /></a><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/01/wpfpropertygrid03.png"><img title="WPF PropertyGrid" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="111" alt="WPF PropertyGrid" src="http://www.dotnet-blog.com/wp-content/uploads/2009/01/wpfpropertygrid03-thumb.png" width="244" border="0" /></a></p>
<p>Pretty cool control.</p>
<p>Project: <a href="http://www.codeplex.com/wpfpropertygrid">http://www.codeplex.com/wpfpropertygrid</a></p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/YAwCfWoYduc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/01/29/wpf-propertygrid-control-updated/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/01/29/wpf-propertygrid-control-updated/</feedburner:origLink></item>
		<item>
		<title>How to Style and Animate a WPF ListBox</title>
		<link>http://feedproxy.google.com/~r/DotNetBlogCom/~3/pzlQToBg2VM/</link>
		<comments>http://www.dotnet-blog.com/index.php/2009/01/29/how-to-style-and-animate-a-wpf-listbox/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 17:25:00 +0000</pubDate>
		<dc:creator>Norbert Eder</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.dotnet-blog.com/index.php/2009/01/29/how-to-style-and-animate-a-wpf-listbox/</guid>
		<description><![CDATA[It’s a common question in forums. How to style and animate a list box in WPF. I’ll come up with an example and explanations. What can you lean from this article?

How to animate list box items 
How to override the item focus 
How to style the selected item 

First, let’s have a look at the [...]]]></description>
			<content:encoded><![CDATA[<p>It’s a common question in forums. How to style and animate a list box in WPF. I’ll come up with an example and explanations. What can you lean from this article?</p>
<ul>
<li>How to animate list box items </li>
<li>How to override the item focus </li>
<li>How to style the selected item </li>
</ul>
<p>First, let’s have a look at the result:</p>
<p><a href="http://www.dotnet-blog.com/wp-content/uploads/2009/01/image11.png"><img title="WPF ListBox Style and Animation Sample" style="border-right: 0px; border-top: 0px; display: inline; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="446" alt="WPF ListBox Style and Animation Sample" src="http://www.dotnet-blog.com/wp-content/uploads/2009/01/image-thumb11.png" width="179" border="0" /></a> </p>
<p>To display the data, objects of type of <font face="Courier New">Person</font> are used. This is a simple data class, having nothing special:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Person
{
    <span class="kwrd">public</span> String FirstName { get; set; }
    <span class="kwrd">public</span> String LastName { get; set; }

    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()
    {
        <span class="kwrd">return</span> String.Format(<span class="str">&quot;{0}, {1}&quot;</span>, LastName, FirstName);
    }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>For getting sample data, there is a mock object called <font face="Courier New">PersonMock</font>:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> PersonMock
{
    <span class="kwrd">private</span> <span class="kwrd">static</span> PersonCollection people =
        <span class="kwrd">new</span> PersonCollection();

    <span class="kwrd">public</span> <span class="kwrd">static</span> PersonCollection GetPeople()
    {
        <span class="kwrd">if</span> (people.Count &gt; 0)
            <span class="kwrd">return</span> people;

        <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; 10; i++)
            people.Add
                (
                    <span class="kwrd">new</span> Person
                    {
                        FirstName = <span class="str">&quot;FirstName&quot;</span> + i.ToString(),
                        LastName = <span class="str">&quot;LastName&quot;</span> + i.ToString()
                    }
                );

        <span class="kwrd">return</span> people;
    }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>As you can see, there is also a collection, which can be found in the attached sample application.</p>
<p>For the styling we have to create a <font face="Courier New">DataTemplate</font>. The <font face="Courier New">DataTemplate</font> will be the <font face="Courier New">ItemTemplate</font> of the <font face="Courier New">ListBox</font> element and declares how each item will be displayed:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">DataType</span><span class="kwrd">=&quot;Person&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Border</span>
        <span class="attr">Cursor</span><span class="kwrd">=&quot;Hand&quot;</span>
        <span class="attr">Name</span><span class="kwrd">=&quot;BorderControl&quot;</span>
        <span class="attr">Background</span><span class="kwrd">=&quot;WhiteSmoke&quot;</span>
        <span class="attr">BorderThickness</span><span class="kwrd">=&quot;0&quot;</span>
        <span class="attr">CornerRadius</span><span class="kwrd">=&quot;5&quot;</span>
        <span class="attr">Padding</span><span class="kwrd">=&quot;5&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
            <span class="attr">Name</span><span class="kwrd">=&quot;TextControl&quot;</span>
            <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;0&quot;</span>
            <span class="attr">Text</span><span class="kwrd">=&quot;{Binding}&quot;</span>
            <span class="attr">Background</span><span class="kwrd">=&quot;Transparent&quot;</span>
            <span class="attr">Padding</span><span class="kwrd">=&quot;4&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock.Style</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Style</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;TextBlock&quot;</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">Style.Triggers</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">DataTrigger</span>
                            <span class="attr">Binding</span><span class="kwrd">=&quot;{Binding ElementName=BorderControl,Path=IsMouseOver}&quot;</span>
                            <span class="attr">Value</span><span class="kwrd">=&quot;True&quot;</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;Foreground&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;White&quot;</span><span class="kwrd">/&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;FontWeight&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;Bold&quot;</span><span class="kwrd">/&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">DataTrigger</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">Style.Triggers</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">Style</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">TextBlock.Style</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">TextBlock</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Border</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">DataTemplate.Triggers</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">EventTrigger</span>
            <span class="attr">SourceName</span><span class="kwrd">=&quot;BorderControl&quot;</span>
            <span class="attr">RoutedEvent</span><span class="kwrd">=&quot;TextBlock.MouseEnter&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">BeginStoryboard</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Storyboard</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">ColorAnimation</span> <span class="attr">Storyboard</span>.<span class="attr">TargetName</span><span class="kwrd">=&quot;BorderControl&quot;</span>
                        <span class="attr">Storyboard</span>.<span class="attr">TargetProperty</span><span class="kwrd">=&quot;Background.Color&quot;</span>
                        <span class="attr">To</span><span class="kwrd">=&quot;DarkRed&quot;</span> <span class="attr">Duration</span><span class="kwrd">=&quot;00:00:00.2&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">Storyboard</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">BeginStoryboard</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">EventTrigger</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">EventTrigger</span>
            <span class="attr">SourceName</span><span class="kwrd">=&quot;BorderControl&quot;</span>
            <span class="attr">RoutedEvent</span><span class="kwrd">=&quot;TextBlock.MouseLeave&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">BeginStoryboard</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Storyboard</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">ColorAnimation</span> <span class="attr">Storyboard</span>.<span class="attr">TargetName</span><span class="kwrd">=&quot;BorderControl&quot;</span>
                        <span class="attr">Storyboard</span>.<span class="attr">TargetProperty</span><span class="kwrd">=&quot;Background.Color&quot;</span>
                        <span class="attr">To</span><span class="kwrd">=&quot;WhiteSmoke&quot;</span> <span class="attr">Duration</span><span class="kwrd">=&quot;00:00:00.2&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">Storyboard</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">BeginStoryboard</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">EventTrigger</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">DataTemplate.Triggers</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The data template itself is really simple. It just defines a border having a <font face="Courier New">TextBlock</font> element inside.</p>
<p>The most interesting parts are the used triggers. There is one data trigger for the <font face="Courier New">TextBlock</font> and some event triggers for the data template. What’s the difference between <font face="Courier New">DataTrigger</font> and <font face="Courier New">EventTrigger</font>:</p>
<p>A data trigger is bound to a property and watches if there are changes. If so, you can set other properties to change their values.</p>
<p>An event trigger is used to listen to events. If an event is raised the event trigger recognizes this and you are able to create an animation for example.</p>
<p>In the XAML markup above you can see that there are some event triggers listening to the <font face="Courier New">MouseEnter</font> and <font face="Courier New">MouseLeave</font> events. In case of the mouse enters the element, an animation is started. If the mouse leaves the element, another animation is started to reconstruct the original appearance.</p>
<p>If you haven’t used animations till now: there are many helpful articles on MSDN.</p>
<p>To style the selected items and to remove the focus rectangle we have to create another style which has to be set at the <font face="Courier New">ItemContainerStyle</font> of the list box.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Style</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;GlowContainer&quot;</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;{x:Type ListBoxItem}&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;FocusVisualStyle&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Style</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;Control.Template&quot;</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">ControlTemplate</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">Border</span>
                                <span class="attr">Background</span><span class="kwrd">=&quot;Transparent&quot;</span>
                                <span class="attr">Opacity</span><span class="kwrd">=&quot;0&quot;</span>
                                <span class="attr">CornerRadius</span><span class="kwrd">=&quot;0&quot;</span><span class="kwrd">&gt;</span>
                                <span class="kwrd">&lt;</span><span class="html">Rectangle</span>
                                    <span class="attr">Margin</span><span class="kwrd">=&quot;0&quot;</span>
                                    <span class="attr">StrokeThickness</span><span class="kwrd">=&quot;0&quot;</span>
                                    <span class="attr">Stroke</span><span class="kwrd">=&quot;Transparent&quot;</span>
                                    <span class="attr">StrokeDashArray</span><span class="kwrd">=&quot;1 2&quot;</span><span class="kwrd">/&gt;</span>
                            <span class="kwrd">&lt;/</span><span class="html">Border</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">ControlTemplate</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">Setter</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Style</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Setter</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;Template&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ControlTemplate</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;{x:Type ListBoxItem}&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Border</span> <span class="attr">Background</span><span class="kwrd">=&quot;WhiteSmoke&quot;</span>
                            <span class="attr">CornerRadius</span><span class="kwrd">=&quot;5&quot;</span>
                            <span class="attr">BorderThickness</span><span class="kwrd">=&quot;2&quot;</span>
                            <span class="attr">x:Name</span><span class="kwrd">=&quot;ItemBorder&quot;</span>
                            <span class="attr">Margin</span><span class="kwrd">=&quot;6,3,6,3&quot;</span> <span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">ContentPresenter</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">Border</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ControlTemplate.Triggers</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">Trigger</span> <span class="attr">Property</span><span class="kwrd">=&quot;IsSelected&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;true&quot;</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">Setter</span>
                            <span class="attr">TargetName</span><span class="kwrd">=&quot;ItemBorder&quot;</span>
                            <span class="attr">Property</span><span class="kwrd">=&quot;BitmapEffect&quot;</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
                                <span class="kwrd">&lt;</span><span class="html">OuterGlowBitmapEffect</span>
                                    <span class="attr">GlowColor</span><span class="kwrd">=&quot;DarkRed&quot;</span>
                                    <span class="attr">GlowSize</span><span class="kwrd">=&quot;5&quot;</span> <span class="kwrd">/&gt;</span>
                            <span class="kwrd">&lt;/</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">Setter</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">Trigger</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">ControlTemplate.Triggers</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">ControlTemplate</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Setter.Value</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Setter</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Style</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The first setter of this style defines a control template for the <font face="Courier New">FocusVisualStyle</font>. In our case we define a transparent border. This results in an invisible focus for the selected item.</p>
<p>The second setter defines another control template: this includes a border and a trigger listening the <font face="Courier New">IsSelected</font> property. If an item is selected an <font face="Courier New">OuterGlowBitmapEffect</font> is applied to the border.</p>
<p>That’s all to get the list box you can see in the screenshot above. I recommend to have a look at control templates, data templates, triggers, effects and animations to get a whole picture of what is going on here, or try the sample application:</p>
<p><iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-c8d8cb313db8e795.skydrive.live.com/embedrowdetail.aspx/%c3%96ffentlich/Samples/ListBoxStylingDemo.zip" frameborder="0" scrolling="no"></iframe></p>
<hr/>Copyright &copy; 2009 <strong><a href="http://www.dotnet-blog.com">.NET BLOG</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact csharp@gmx.at so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span><img src="http://feeds.feedburner.com/~r/DotNetBlogCom/~4/pzlQToBg2VM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dotnet-blog.com/index.php/2009/01/29/how-to-style-and-animate-a-wpf-listbox/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dotnet-blog.com/index.php/2009/01/29/how-to-style-and-animate-a-wpf-listbox/</feedburner:origLink></item>
	</channel>
</rss>

