<?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"?><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:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:series="http://unfoldingneurons.com/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>.NET Rocker</title>
	
	<link>http://tonychampion.net/blog</link>
	<description>The .NET ramblings of Tony Champion</description>
	<lastBuildDate>Tue, 07 Feb 2012 04:10:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/tonychampion" /><feedburner:info uri="tonychampion" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Silverlight ComboBoxItem IsEnabled, SL5 Style</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/2jckaGq-RMQ/</link>
		<comments>http://tonychampion.net/blog/index.php/2012/02/silverlight-comboboxitem-isenabled-sl5-style/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 04:10:29 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[ComboBoxItem]]></category>
		<category><![CDATA[silverlight 5]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=364</guid>
		<description><![CDATA[I was recently working with another developer on a ComboBox, where he needed to be able to disable certain items in the ComboBox (aka make them non-selectable).&#160; Having been a while since I looked at it, all I could remember was it was not as easy as it should be.&#160; In coming up with a [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently working with another developer on a ComboBox, where he needed to be able to disable certain items in the ComboBox (aka make them non-selectable).&#160; Having been a while since I looked at it, all I could remember was it was not as easy as it should be.&#160; In coming up with a solution, we realized that Silverlight 5 makes this rather easy.</p>
<p><span id="more-364"></span>
<p>So why would we want to disable a ComboBoxItem in the first place?&#160; If you can disable individual items in a ComboBox, then you can still present the user with all of the available data, without making them all an actionable option.&#160; In our example we are going to create a product list ComboBox.&#160; In this scenario we want the user to see all of the products that we carry, but they should only be able to select the items that we currently have in stock.</p>
<p>To start off our project, we will create a new Silverlight 5 Application.&#160; Plain and simple with no bells and whistles.</p>
<p>The first thing we need to do is to create our data object.&#160; For this demo we will only have two properties, Name and IsAvailable.&#160; Our class will also have a static method that will return our test data.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Product
{
    <span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }
    <span class="kwrd">public</span> <span class="kwrd">bool</span> IsAvailable { get; set; }

    <span class="kwrd">public</span> <span class="kwrd">static</span> IEnumerable&lt;Product&gt; GetProducts()
    {
        <span class="kwrd">return</span> <span class="kwrd">new</span> List&lt;Product&gt;()
                    {
                        <span class="kwrd">new</span> Product() { Name=<span class="str">&quot;Saw&quot;</span> ,
                            IsAvailable = <span class="kwrd">true</span>},
                        <span class="kwrd">new</span> Product() { Name=<span class="str">&quot;Hammer&quot;</span> ,
                            IsAvailable = <span class="kwrd">true</span>},
                        <span class="kwrd">new</span> Product() { Name=<span class="str">&quot;Clamp&quot;</span> ,
                            IsAvailable = <span class="kwrd">false</span>},
                        <span class="kwrd">new</span> Product() { Name=<span class="str">&quot;Level&quot;</span> ,
                            IsAvailable = <span class="kwrd">true</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>Now we can create our testing UI.&#160; It will be a simple Grid containing our CombBox and a few TextBlocks.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Width</span><span class="kwrd">=&quot;Auto&quot;</span> <span class="attr">Height</span><span class="kwrd">=&quot;Auto&quot;</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
      <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;Auto&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;Auto&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">=&quot;Auto&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">=&quot;Auto&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;Combo Box : &quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;Selected Item : &quot;</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">ComboBox</span>
            <span class="attr">x:Name</span><span class="kwrd">=&quot;cbTest&quot;</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;1&quot;</span>
            <span class="attr">DisplayMemberPath</span><span class="kwrd">=&quot;Name&quot;</span> <span class="kwrd">/&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">=&quot;1&quot;</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;1&quot;</span>
        <span class="attr">Text</span><span class="kwrd">=&quot;{Binding SelectedItem.Name, ElementName=cbTest}&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Grid</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>If you look at our ComboBox, we will be displaying the Product Name property.&#160; The last TextBlock maps its Text property to the Name property of the SelectedItem of our ComboBox.&#160; Fairly straight forward, right?</p>
<p>Just for completion sake, I added some Style resources to the UserControl.Resources in order to make the project a bit more readable.</p>
<pre class="csharpcode"><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">Setter</span> <span class="attr">Property</span><span class="kwrd">=&quot;FontSize&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;22&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;Margin&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;0,10,20,0&quot;</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">Style</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;ComboBox&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;FontSize&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;22&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;Height&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;30&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;Width&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;150&quot;</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>If you run the project, you should see something like this :</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/02/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/02/image_thumb3.png" width="374" height="140" /></a></p>
<p>The last thing we need to add is come data.&#160; In order to do that, let’s add the following line to our MainPage code behind:</p>
<pre class="csharpcode">cbTest.ItemsSource = Product.GetProducts();</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>Running our project again, you should now have data.&#160; Selecting an item should update the Selected Item text.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/02/image4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/02/image_thumb4.png" width="381" height="141" /></a></p>
<p>Now the we have our project set up, how can we disable individual items?&#160; The default Item container for a CombBox is the CombBoxItem.&#160; That means that for every item that you create, regardless if you are using the DisplayMemberPath or a custom ItemTemplate, is set inside a ComboBoxItem.&#160; It just so happens that the ComboBoxItem object has an IsEnabled property that we can use to enable/disable the items.</p>
<p>Prior to Silverlight 5, there were several ways of attacking this problem, however Silverlight 5 offers a much simpler approach.&#160; On day 6 of my <a href="http://tonychampion.net/blog/index.php/series/12-days-of-silverlight/" target="_blank">12 Days of Silverlight series</a> I talked about the new Silverlight 5 feature of <a href="http://tonychampion.net/blog/index.php/2011/12/6th-day-of-silverlight-binding-in-style-setters/" target="_blank">Binding in Style setters</a>.&#160; So how about we show this new feature in action?</p>
<p>We can use the new binding feature to make using the IsEnabled property a snap.&#160; Let’s add the following Style settings to our User.Resources.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Style</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;ComboBoxItem&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;IsEnabled&quot;</span> <span class="attr">Value</span><span class="kwrd">=&quot;{Binding IsAvailable}&quot;</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>Now the IsEnabled property of the ComboBoxItem will be triggered off of our IsAvailable Product property.&#160; Yep, it’s that easy.&#160; Let’s rerun our application and see what we have.&#160; If you expand the ComboBox, you will notice that the Clamp item is greyed out and you cannot select it.&#160; And you thought you wouldn’t use binding in Style setters.&#160; Tisk tisk…</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/02/image5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/02/image_thumb5.png" width="357" height="195" /></a></p>
<p>This post was really about two things.&#160; The first was to solve the direct problem of disabling items in your ComboBox.&#160; The second was to give a real life example of using the binding in Style setters.</p>
<p>You can download the code for the project : <a href="http://tonychampion.net/blog/wp-content/uploads/Projects/SL5ComboBoxItemEnabled.zip" target="_blank">SL5ComboBoxItemEnabled.zip</a></p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/2jckaGq-RMQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2012/02/silverlight-comboboxitem-isenabled-sl5-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tonychampion.net/blog/index.php/2012/02/silverlight-comboboxitem-isenabled-sl5-style/</feedburner:origLink></item>
		<item>
		<title>PivotViewer Basics: Custom Item Adorners</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/bXEHEEDvYlY/</link>
		<comments>http://tonychampion.net/blog/index.php/2012/02/pivotviewer-basics-custom-item-adorners/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 19:26:01 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[PivotViewer]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[item adorners]]></category>
		<category><![CDATA[pivotviewer]]></category>
		<category><![CDATA[silverlight 5]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=354</guid>
		<description><![CDATA[Well we are coming to the end of the PivotViewer Basics series.&#160; To round it out, I thought I would continue on with the last post which discussed Basic Item Adorners.&#160; In that post we looked at implementing the custom actions that you found in the first PivotViewer.&#160; This post will look at taking it [...]]]></description>
			<content:encoded><![CDATA[<p>Well we are coming to the end of the <a href="http://tonychampion.net/blog/index.php/series/pivotviewer-basics/" target="_blank">PivotViewer Basics series</a>.&#160; To round it out, I thought I would continue on with the last post which discussed <a href="http://tonychampion.net/blog/index.php/2012/01/pivotviewer-basics-basic-item-adorners/" target="_blank">Basic Item Adorners</a>.&#160; In that post we looked at implementing the custom actions that you found in the first PivotViewer.&#160; This post will look at taking it one step further and look at what it takes to build our own item adorners.&#160; </p>
<p><span id="more-354"></span><br />
<h3>Basic Border Adorner</h3>
<p>As we have done in the rest of the series, we will start with the code from the first post in this series, <a href="http://tonychampion.net/blog/index.php/2011/11/pv-basics-client-side-collections/" target="_blank">Client-Side Collections</a>.&#160; You can download that project here : <a href="http://tonyc.me/tUL3PR" target="_blank">PVB01_ClientSideCreation.zip</a>.</p>
<p>We are going to start the first example with the basics.&#160; Once you set your own item adorner, you will lose the very basic adorner that comes out of the box, the highlight border.&#160; If you need to refresh your memory, run the project above and you will see that every time you mouse over or select an item it is highlighted with a light blue border around it.</p>
<p>If you dig into the PivotViewer XAML you will find that there is actually a bug here.&#160; That light blue border is actually the selected border.&#160; The mouse over border is a different color.&#160; The item adorner defines a couple visual states in the group “ItemStates”.&#160; The selected border is driven off of the “IsSelected” state.&#160; However, the “IsSelected” state also fires on a simple mouse over, even if the items itself is not selected.&#160; Since the selected border sits on top of the mouse over border, you will always see the selected one.&#160; What does this mean for us?&#160; It simply means we are not going to use the “IsSelected” visual state to drive our adorner.</p>
<p>Now that we have that out of the way, let’s create our item adorner.&#160; If you read the last post , you might recall that the PivotViewer has a <strong>ItemAdornerStyle</strong> where we implemented the <strong>PivotViewerBasicItemAdorner</strong>.&#160; Our first item adorner is going to look very similar, except we are going to remove the basic item adorner.&#160; In fact, to show a point, it is going to look rather blank.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Style</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;basicAdorner&quot;</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;pivot:PivotViewerItemAdorner&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;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">Grid</span> <span class="attr">Background</span><span class="kwrd">=&quot;Transparent&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">Grid</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>To assign our adorner to the PivotViewer, we can set the ItemAdornerStyle property to our new style.</p>
<pre class="csharpcode">&lt;pivot:PivotViewer x:Name=<span class="str">&quot;pViewer&quot;</span>
ItemAdornerStyle=<span class="str">&quot;{StaticResource basicAdorner}&quot;</span>&gt;
   ...
&lt;/pivot:PivotViewer&gt;</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>If you run the project you will see that it’s not very exciting.&#160; In fact, you will notice that the highlight border is missing completely.&#160; However, that’s good.&#160; The gives us a nice blank canvas to start from.&#160; In order to add our highlight border back, we are going to add two <strong>Border</strong> objects to our <strong>Grid</strong>.&#160; The first one will be visible when we you mouse over an item.&#160; The second will show when the item is selected.&#160; By adding the selected <strong>Border</strong> second, it will hide the mouse over one when an item is selected and the mouse is over it.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Style</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;basicAdorner&quot;</span> <span class="attr">TargetType</span><span class="kwrd">=&quot;pivot:PivotViewerItemAdorner&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;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">Grid</span> <span class="attr">Background</span><span class="kwrd">=&quot;Transparent&quot;</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">VisualStateManager.VisualStateGroups</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">VisualStateGroup</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;CommonStates&quot;</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">VisualState</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;Normal&quot;</span><span class="kwrd">/&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">VisualState</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;MouseOver&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">DoubleAnimationUsingKeyFrames</span>
                   <span class="attr">Storyboard</span>.<span class="attr">TargetProperty</span><span class="kwrd">=&quot;(UIElement.Opacity)&quot;</span>
                       <span class="attr">Storyboard</span>.<span class="attr">TargetName</span><span class="kwrd">=&quot;ButtonBorder&quot;</span><span class="kwrd">&gt;</span>
                                 <span class="kwrd">&lt;</span><span class="html">EasingDoubleKeyFrame</span> <span class="attr">KeyTime</span><span class="kwrd">=&quot;0&quot;</span>
                                        <span class="attr">Value</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
                                 <span class="kwrd">&lt;/</span><span class="html">DoubleAnimationUsingKeyFrames</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">VisualState</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">VisualState</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;Disabled&quot;</span><span class="kwrd">/&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">VisualStateGroup</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">VisualStateGroup</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;ItemStates&quot;</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">VisualState</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;Default&quot;</span><span class="kwrd">/&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">VisualState</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;IsSelected&quot;</span><span class="kwrd">/&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">VisualStateGroup</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">VisualStateManager.VisualStateGroups</span><span class="kwrd">&gt;</span>
                  <span class="kwrd">&lt;</span><span class="html">conv:CustomAdorner</span> <span class="attr">DataContext</span><span class="kwrd">=&quot;{Binding .}&quot;</span><span class="kwrd">/&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">Border</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;ButtonBorder&quot;</span>
                                        <span class="attr">Margin</span><span class="kwrd">=&quot;-1&quot;</span>
                                        <span class="attr">BorderThickness</span><span class="kwrd">=&quot;4&quot;</span>
                                        <span class="attr">BorderBrush</span><span class="kwrd">=&quot;#AAfffc08&quot;</span>
                                        <span class="attr">Opacity</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">Border</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;FocusedItemBorder&quot;</span>
                             <span class="attr">Visibility</span><span class="kwrd">=&quot;{Binding IsItemSelected,
                  RelativeSource={RelativeSource TemplatedParent},
                             Converter={StaticResource convBool}}&quot;</span>
                                        <span class="attr">Margin</span><span class="kwrd">=&quot;-1&quot;</span>
                                        <span class="attr">BorderThickness</span><span class="kwrd">=&quot;4&quot;</span>
                                        <span class="attr">BorderBrush</span><span class="kwrd">=&quot;Purple&quot;</span>
                                    <span class="attr">Opacity</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">Grid</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>Now we have some meat to work with here.&#160; Let’s take a closer look at what is going on.&#160; First you will notice that we added a couple of <strong>VisualStateGroups</strong>.&#160; For this example we are going to leave the IsSelected blank due to that bug I discussed earlier.&#160; In the MouseOver state we are setting our ButtonBorder <strong>Border</strong> objects <strong>Opacity</strong> to 1.</p>
<p>So how do we show the FocusedItemBorder?&#160; The PivotViewerItemAdorner class (whose style we are currently setting) has a <strong>IsItemSelected</strong> property.&#160; By binding the <strong>Visibility</strong> of our <strong>Border</strong> to it, we can toggle based off of that value.&#160; In order to convert the IsItemSelected property from a bool to a <strong>Visibility</strong>, I had to create a <strong>ValueConverter </strong>that looks like this.</p>
<p><em>*Note: This is a handy little <strong>ValueConverter</strong> and you should keep this type of converter handy for your projects.</em></p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> BoolToVisibility : IValueConverter
{

    <span class="kwrd">public</span> <span class="kwrd">object</span> Convert(<span class="kwrd">object</span> <span class="kwrd">value</span>,
        Type targetType, <span class="kwrd">object</span> parameter,
        System.Globalization.CultureInfo culture)
    {
        <span class="kwrd">if</span>(<span class="kwrd">value</span> <span class="kwrd">is</span> <span class="kwrd">bool</span>)
        {
            <span class="kwrd">if</span>((<span class="kwrd">bool</span>)<span class="kwrd">value</span>)
            {
                <span class="kwrd">return</span> Visibility.Visible;
            }
        }

        <span class="kwrd">return</span> Visibility.Collapsed;
    }

    <span class="kwrd">public</span> <span class="kwrd">object</span> ConvertBack(<span class="kwrd">object</span> <span class="kwrd">value</span>,
        Type targetType, <span class="kwrd">object</span> parameter,
        System.Globalization.CultureInfo culture)
    {
        <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
    }
}</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>Don’t forget to add the ValueConverter to our XAML so we can reference it in our adorner.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">conv:BoolToVisibility</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;convBool&quot;</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>If you rerun your application, you should now have two different borders that show on your trading cards.&#160; A yellow border on the mouse over and a purple one when you select the item.&#160; If you were wanting nothing more to get the default borders to work correctly, you are now done.&#160; Hopefully you want to stick around and see how to take this a bit further though. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://tonychampion.net/blog/wp-content/uploads/2012/02/wlEmoticon-smile.png" /></p>
<h3></h3>
<h3>Adding Custom XAML</h3>
<p>The above example is a great starting point, but what if we want to add a bit more interactivity in our adorners?&#160; Turns out, it is rather easy (with a few minor catches) to do this.&#160; We are going to wrap the rest of our adorner in a <strong>UserControl</strong>, CustomAdorner.xaml.&#160;&#160; Our UI is going to consist of a single button for the demo’s sake.&#160; Just to separate it from the default item adorner, we will center this button on the bottom of the card.&#160; Here is what our new UserControl looks like:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;LayoutRoot&quot;</span> <span class="attr">Background</span><span class="kwrd">=&quot;Transparent&quot;</span>  <span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;spContainer&quot;</span> <span class="attr">Orientation</span><span class="kwrd">=&quot;Horizontal&quot;</span>
       <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span> <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Bottom&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">Content</span><span class="kwrd">=&quot;Time for Change&quot;</span> <span class="attr">Width</span><span class="kwrd">=&quot;200&quot;</span>
               <span class="attr">Height</span><span class="kwrd">=&quot;50&quot;</span> <span class="attr">Click</span><span class="kwrd">=&quot;Button_Click&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Grid</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 <strong>Button</strong> has a <strong>Click</strong> event handler.&#160; Jumping to our code behind, we will show a simple <strong>MessageBox</strong> to prove we are getting what we expect.</p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> Button_Click(<span class="kwrd">object</span> sender, RoutedEventArgs e)
{
    <span class="kwrd">if</span>(DataContext <span class="kwrd">is</span> DemoItem)
    {
        MessageBox.Show(<span class="str">&quot;DemoItem : &quot;</span>
              + (DataContext <span class="kwrd">as</span> DemoItem).ShortName);
    }
}</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>With our <strong>UserControl</strong> completed, let’s add it to our item adorner.&#160; </p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Background</span><span class="kwrd">=&quot;Transparent&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">VisualStateManager.VisualStateGroups</span><span class="kwrd">&gt;</span>
...
    <span class="kwrd">&lt;/</span><span class="html">VisualStateManager.VisualStateGroups</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">conv:CustomAdorner</span> <span class="attr">DataContext</span><span class="kwrd">=&quot;{Binding .}&quot;</span>
        <span class="attr">Visibility</span><span class="kwrd">=&quot;{Binding IsItemSelected,
        RelativeSource={RelativeSource TemplatedParent},
        Converter={StaticResource convBool}}&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Border</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;ButtonBorder&quot;</span>
                <span class="attr">Margin</span><span class="kwrd">=&quot;-1&quot;</span>
                <span class="attr">BorderThickness</span><span class="kwrd">=&quot;4&quot;</span>
                <span class="attr">BorderBrush</span><span class="kwrd">=&quot;#AAfffc08&quot;</span>
                <span class="attr">Opacity</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Border</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;FocusedItemBorder&quot;</span>
            <span class="attr">Visibility</span><span class="kwrd">=&quot;{Binding IsItemSelected,
            RelativeSource={RelativeSource TemplatedParent},
            Converter={StaticResource convBool}}&quot;</span>
                <span class="attr">Margin</span><span class="kwrd">=&quot;-1&quot;</span>
                <span class="attr">BorderThickness</span><span class="kwrd">=&quot;4&quot;</span>
                <span class="attr">BorderBrush</span><span class="kwrd">=&quot;Purple&quot;</span>
            <span class="attr">Opacity</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.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>If you rerun the project, you will see that our button is now shown on the trading cards whenever you mouse over a trading card.&#160; If you click the button, you will get a <strong>MessageBox</strong> with the name of the DemoItem displayed.&#160; Instant success right?&#160; Well, sort of.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/02/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/02/image_thumb.png" width="307" height="206" /></a></p>
<p>You might notice that this isn’t exactly what we are looking for.&#160; If you zoom into an item, the button is positioned nice and neat in the bottom center of card.&#160; However, when zoomed in it looks something like above.&#160; </p>
<p>Why is this happening?&#160; It is important to remember that the trading cards are XAML that have been rendered to an image.&#160; When you define a ItemTemplate, it is always important to design for the largest size that you want to display.&#160; This will insure that your cards always look clean.</p>
<p>This same philosophy is carried over to the item adorners.&#160; The <strong>Grid</strong> in our <strong>UserControl</strong> is adjusting to the current display width and height of the trading card.&#160; However, we defined our <strong>Button</strong> to a static width and height.&#160; Therefore, as you zoom out, the <strong>Button</strong> begins to take up too much space.&#160; The opposite is true if you design it too small.&#160; Zooming into the object will make the <strong>Button</strong> look out of place by being too small.</p>
<p>So how do we address this?&#160; Your first thought might be to change the size of the <strong>Button</strong> as the <strong>Grid</strong> changes its size.&#160; While this will work, what happens when you have more than one element?&#160; What if the item isn’t on the bottom, but is some set offset from the top?&#160; Scaling can quickly become an issue.&#160; </p>
<p>Fortunately, Silverlight has already provided an answer for us. Silverlight 5 contains a control called the <strong>ViewBox</strong>, which use to be a part of the Toolkit.&#160; The <strong>ViewBox</strong> will automatically scale the UI within it to the appropriate size while maintaining accurate spacing, etc. This means that we can scale our <strong>Grid</strong> and everything within it will scale accordingly.</p>
<p>In order to implement our <strong>ViewBox</strong> scenario, we first must decide a base size for our adorner.&#160; This is the size that all of the child elements will be designed to.&#160; For our example, let’s choose 500&#215;500.&#160; We are going to wrap our <strong>StackPanel</strong> inside a new Grid that is set to the 500&#215;500.&#160; That <strong>Grid</strong> will then be wrapped in a <strong>ViewBox</strong>.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;LayoutRoot&quot;</span> <span class="attr">Background</span><span class="kwrd">=&quot;Transparent&quot;</span> <span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Viewbox</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;Container&quot;</span> <span class="attr">Background</span><span class="kwrd">=&quot;Transparent&quot;</span>
              <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
              <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
              <span class="attr">Height</span><span class="kwrd">=&quot;500&quot;</span> <span class="attr">Width</span><span class="kwrd">=&quot;500&quot;</span>
              <span class="attr">RenderTransformOrigin</span><span class="kwrd">=&quot;0.5,0.5&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;spContainer&quot;</span>
                        <span class="attr">Orientation</span><span class="kwrd">=&quot;Horizontal&quot;</span>
                        <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                        <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Bottom&quot;</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">Content</span><span class="kwrd">=&quot;Time for Change&quot;</span>
                            <span class="attr">Width</span><span class="kwrd">=&quot;200&quot;</span>
                            <span class="attr">Height</span><span class="kwrd">=&quot;50&quot;</span> <span class="attr">Click</span><span class="kwrd">=&quot;Button_Click&quot;</span>
                            <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                       <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Viewbox</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Grid</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>If you rerun your application, you will now see that the button scales according to the size of the trading card.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/02/image1.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/02/image_thumb1.png" width="265" height="178" /></a></p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/02/image2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/02/image_thumb2.png" width="256" height="259" /></a></p>
<p>If you wanted the button to only show up when the item is selected, then we can borrow the <strong>Visibility</strong> binding for our selected <strong>Border</strong>.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">conv:CustomAdorner</span> <span class="attr">DataContext</span><span class="kwrd">=&quot;{Binding .}&quot;</span>
                    <span class="attr">Visibility</span><span class="kwrd">=&quot;{Binding IsItemSelected,
    RelativeSource={RelativeSource TemplatedParent},
    Converter={StaticResource convBool}}&quot;</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>And there you have it.&#160; The sky is now the limit on what you can do.&#160; Well, that is until you run into a wall somewhere that I haven’t found.&#160; Regardless, this does open up a great deal of possibilities on what you can add to your trading cards.</p>
<p>You can download the source to this post here : <a href="http://tonyc.me/zSZ9is" target="_blank">PVB05_CustomAdorner.zip</a></p>
<p>As I said at the beginning of this post, this wraps up our basics series.&#160; What’s next?&#160; Well I have a stack of random posts that need to be written to address various topics.&#160; I thought I would then come back and maybe do a series on trading card designs. Until then…</p>
<p>Happy Pivoting…</p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/bXEHEEDvYlY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2012/02/pivotviewer-basics-custom-item-adorners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[PivotViewer Basics]]></series:name>
	<feedburner:origLink>http://tonychampion.net/blog/index.php/2012/02/pivotviewer-basics-custom-item-adorners/</feedburner:origLink></item>
		<item>
		<title>PivotViewer Basics : Basic Item Adorners</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/ZkjZXuTe8Gw/</link>
		<comments>http://tonychampion.net/blog/index.php/2012/01/pivotviewer-basics-basic-item-adorners/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 22:25:43 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[PivotViewer]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[item adorners]]></category>
		<category><![CDATA[pivotviewer]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=343</guid>
		<description><![CDATA[After a break to review some of my favorite Silverlight 5 features in the 12 Days of Silverlight series, it’s time to get back to some PivotViewer action.&#160; This is the 4th post in the PivotViewer Basics series focused on some of the basics of the Silverlight 5 PivotViewer.&#160; In this post we will look [...]]]></description>
			<content:encoded><![CDATA[<p>After a break to review some of my favorite Silverlight 5 features in the <a href="http://tonychampion.net/blog/index.php/series/12-days-of-silverlight/" target="_blank">12 Days of Silverlight</a> series, it’s time to get back to some PivotViewer action.&#160; This is the 4th post in the <a href="http://tonychampion.net/blog/index.php/series/pivotviewer-basics/" target="_blank">PivotViewer Basics</a> series focused on some of the basics of the Silverlight 5 PivotViewer.&#160; In this post we will look at item adorners, what they are and how to use them.</p>
<p><span id="more-343"></span>
<p>In the original PivotViewer, there was a concept of custom actions.&#160; Defining custom actions allowed you to add a button on top of the selected trading card.&#160; In fact, you could add several items to the card.&#160; This gave you the ability to provide limited interactivity with the trading card to the user.&#160; The new Silverlight does away with custom actions and replaces them with item adorners. (<em>note: if you implemented custom actions in the previous version, this is another breaking code change</em>)</p>
<p>Simply put, an item adorner is XAML that is placed over a trading card.&#160; If you define an item adorner it is displayed over a trading card when either a mouse over event happens or the item is selected.&#160; This opens a wide range of possibilities for your trading cards.&#160; Now you can add additional information or interactive controls without the need to leave the PivotViewer.&#160; PivotViewer comes with a default adorner, <strong>PivotViewerDefaultItemAdorner</strong> (yep, gotta love those short names).&#160; This adorner mimics the functionality of the custom actions in the previous version.&#160; In this post we will take a look at this new control.</p>
<h3>Implementing the Default Item Adorner</h3>
<p>In order to get us up and running quicker, we are going to start with the project created in the 1st post of the series, <a href="http://tonychampion.net/blog/index.php/2011/11/pv-basics-client-side-collections/" target="_blank">Client-Side Collections</a>.&#160; You can download the code here: <a href="http://tonyc.me/tUL3PR" target="_blank">PVB01_ClientSideCreation.zip</a></p>
<p>Adding the default item adorner is not the most trivial thing in the world, however it’s not overly complicated.&#160; PivotViewer exposes&#160; an <strong>ItemAdornerStyle</strong> property where you can set a style to define your item adorner.&#160; Let’s look at what this style will look like using the <strong>PivotViewerDefaultItemAdorner</strong>.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Style</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;basicAdorner&quot;</span>
          <span class="attr">TargetType</span><span class="kwrd">=&quot;pivot:PivotViewerItemAdorner&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;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">pivot:PivotViewerDefaultItemAdorner</span>
                    <span class="attr">IsItemSelected</span><span class="kwrd">=&quot;{Binding IsItemSelected,
                RelativeSource={RelativeSource TemplatedParent}}&quot;</span>
              <span class="attr">CommandsRequested</span><span class="kwrd">=&quot;basicAdorner_CommandsRequested&quot;</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>This code creates a style of a <strong>PivotViewerItemAdorner</strong>.&#160; In the template of that control, we are adding a <strong>PivotViewerDefaultItemAdorner</strong>.&#160; The IsItemSelected property binds that property to the base <strong>PivotViewerItemAdorner</strong>.&#160; This let’s us know when the item is simply a mouse-over event or the item has been selected.&#160; The <strong>CommandsRequested</strong> property allows us to create custom commands and display/interact with them on the current trading card.</p>
<p>Here is an example of what the <strong>CommandsRequested</strong> event handler will look like.</p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> basicAdorner_CommandsRequested(<span class="kwrd">object</span> sender,
    PivotViewerCommandsRequestedEventArgs e)
{
     e.Commands.Add(<span class="kwrd">new</span> AddCommand());
}</pre>
<p>The <strong>PivotViewerCommandRequestedEventArgs</strong> has 3 important properties.&#160; The first, as shown above, is a collection of <strong>IPivotViewerUICommand</strong> objects that defines what commands (aka buttons) to add to the control.&#160; Next is an <strong>Item</strong> property that gives you access to the data object being referred to.&#160; Finally, an <strong>IsItemSelected</strong> property tells us if the object has been selected or not.&#160; We will look at that more in a little while.</p>
<p>The <strong>IPivotViewerUICommand</strong> interface allows you to define what it being displayed to the user and what do to if the user selects it.&#160; Here is what a base implementation of the interface will look like.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Class1 : IPivotViewerUICommand
{

    <span class="kwrd">public</span> <span class="kwrd">string</span> DisplayName
    {
        get { <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException(); }
    }

    <span class="kwrd">public</span> Uri Icon
    {
        get { <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException(); }
    }

    <span class="kwrd">public</span> <span class="kwrd">object</span> ToolTip
    {
        get { <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException(); }
    }

    <span class="kwrd">public</span> <span class="kwrd">bool</span> CanExecute(<span class="kwrd">object</span> parameter)
    {
        <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
    }

    <span class="kwrd">public</span> <span class="kwrd">event</span> EventHandler CanExecuteChanged;

    <span class="kwrd">public</span> <span class="kwrd">void</span> Execute(<span class="kwrd">object</span> parameter)
    {
        <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
    }
}</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 isn’t a whole lot going on here.&#160; The <strong>DisplayName</strong>, <strong>ToolTip</strong>, and <strong>Icon</strong> properties are used for the display.&#160; If <strong>CanExecute</strong> returns true, then the <strong>Execute</strong> method is called when the user selects it.&#160; If you go back to our event handler above, you will see that I added an <strong>AddCommand</strong> to the item.&#160; The <strong>AddCommand</strong> class will display a <strong>MessageBox</strong> if the user selects the command.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> AddCommand : IPivotViewerUICommand
{

    <span class="kwrd">public</span> <span class="kwrd">string</span> DisplayName
    {
        get { <span class="kwrd">return</span> <span class="str">&quot;Add Item&quot;</span>; }
    }

    <span class="kwrd">public</span> Uri Icon
    {
        get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
    }

    <span class="kwrd">public</span> <span class="kwrd">object</span> ToolTip
    {
        get { <span class="kwrd">return</span> <span class="str">&quot;Add Item to cart.&quot;</span>; }
    }

    <span class="kwrd">public</span> <span class="kwrd">bool</span> CanExecute(<span class="kwrd">object</span> parameter)
    {
        <span class="kwrd">return</span> <span class="kwrd">true</span>;
    }

    <span class="kwrd">public</span> <span class="kwrd">event</span> EventHandler CanExecuteChanged;

    <span class="kwrd">public</span> <span class="kwrd">void</span> Execute(<span class="kwrd">object</span> parameter)
    {
        var itm = parameter <span class="kwrd">as</span> DemoItem;
        MessageBox.Show( itm.ShortName + <span class="str">&quot; was added&quot;</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 only thing left to do is to let our PivotViewer know of the new <strong>ItemAdornerStyle</strong> that we wish to use.&#160; You can set this in code of XAML.&#160; Here we will simply set it in our XAML.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">pivot:PivotViewer</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;pViewer&quot;</span>
    <span class="attr">ItemAdornerStyle</span><span class="kwrd">=&quot;{StaticResource basicAdorner}&quot;</span><span class="kwrd">&gt;</span>
...
<span class="kwrd">&lt;/</span><span class="html">pivot:PivotViewer</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>If you run the project, you will now see a new command on each trading card when you select it.&#160; Clicking the Add Item button will show a <strong>MessageBox</strong> letting you know that your item has been added to our mythical shopping cart, bug list, or what ever we decide to build. </p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image7.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb7.png" width="203" height="198" /></a></p>
<p>You may also notice that the command will show up whether the item is selected or if you simply mouse over it.&#160; This gets us back to the <strong>IsItemSelected</strong> property of the <strong>PivotViewerCommandRequestedEventArgs</strong>. We can take advantage of this property in our event handler and only add the <strong>AddCommand</strong> if the item is actually selected.</p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> basicAdorner_CommandsRequested(<span class="kwrd">object</span> sender,
    PivotViewerCommandsRequestedEventArgs e)
{
    <span class="kwrd">if</span> (e.IsItemSelected)
    {
        e.Commands.Add(<span class="kwrd">new</span> AddCommand());
    }
}</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>If you re-run your application, you will notice that we are no longer showing the command on the mouse over.</p>
<h3>Creating an Interactive Adorner</h3>
<p>The above example shows you how to use the <strong>PivotViewerDefaultItemAdorner</strong> to mimic the custom actions of the first release.&#160; However, this isn’t the first release, so let’s advance things just a bit to get a better feel for how this can work.</p>
<p>For this example, we are going to create a new command.&#160; This new <strong>ColorCommand</strong> will allow us to change the color of the current object.&#160; Like the <strong>AddCommand</strong>, this command is rather straight forward.&#160; However, in the <strong>Execute</strong> method, we will assign the item’s color to the <strong>CommandColor</strong> property defined in the command.&#160; It wasn’t addressed in the example above, but the <strong>parameter</strong> argument that is passed into the <strong>Execute</strong> method is the data object that we are currently interacting with.&#160; Here is what the new ColorCommand looks like.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> ColorCommand : IPivotViewerUICommand
{

    <span class="kwrd">public</span> <span class="kwrd">string</span> CommandColor { get; set; }

    <span class="kwrd">public</span> <span class="kwrd">string</span> DisplayName
    {
        get { <span class="kwrd">return</span> CommandColor; }
    }

    <span class="kwrd">public</span> Uri Icon
    {
        get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
    }

    <span class="kwrd">public</span> <span class="kwrd">object</span> ToolTip
    {
        get { <span class="kwrd">return</span> <span class="str">&quot;Change color to &quot;</span> + CommandColor; }
    }

    <span class="kwrd">public</span> <span class="kwrd">bool</span> CanExecute(<span class="kwrd">object</span> parameter)
    {
        <span class="kwrd">return</span> <span class="kwrd">true</span>;
    }

    <span class="kwrd">public</span> <span class="kwrd">event</span> EventHandler CanExecuteChanged;

    <span class="kwrd">public</span> <span class="kwrd">void</span> Execute(<span class="kwrd">object</span> parameter)
    {
        var itm = parameter <span class="kwrd">as</span> DemoItem;

        itm.Color = CommandColor;
    }
}</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>Now we need to modify our event handler to add the new command.&#160; We are going to add several command in this example.&#160; The commands we add will be based on the current item’s color.&#160; For example, if the current item is red, then we will add a blue, green, and purple command.&#160; By adding logic into the command creation, we are able to provide a better experience to the user.&#160; For instance, what good does a red button have on a red object?</p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> basicAdorner_CommandsRequested(<span class="kwrd">object</span> sender,
    PivotViewerCommandsRequestedEventArgs e)
{

    <span class="kwrd">if</span> (e.IsItemSelected)
    {
        var itm = e.Item <span class="kwrd">as</span> DemoItem;

        <span class="kwrd">if</span>(itm.Color != <span class="str">&quot;Red&quot;</span>)
            e.Commands.Add(<span class="kwrd">new</span> ColorCommand()
                               {
                                   CommandColor = <span class="str">&quot;Red&quot;</span>
                               });
        <span class="kwrd">if</span> (itm.Color != <span class="str">&quot;Blue&quot;</span>)
            e.Commands.Add(<span class="kwrd">new</span> ColorCommand()
                               {
                                   CommandColor = <span class="str">&quot;Blue&quot;</span>
                               });
        <span class="kwrd">if</span> (itm.Color != <span class="str">&quot;Green&quot;</span>)
            e.Commands.Add(<span class="kwrd">new</span> ColorCommand()
                               {
                                   CommandColor = <span class="str">&quot;Green&quot;</span>
                               });
        <span class="kwrd">if</span> (itm.Color != <span class="str">&quot;Purple&quot;</span>)
            e.Commands.Add(<span class="kwrd">new</span> ColorCommand()
                               {
                                   CommandColor = <span class="str">&quot;Purple&quot;</span>
                               });
    }
}</pre>
<p>Running our application now, you will notice that any selected item will have 3 commands.&#160; Selecting the command will update the object and dynamically change the color of the trading card.&#160; Hopefully you can see how this could be very beneficial to you in more advanced situations.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image8.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb8.png" width="244" height="243" /></a></p>
<p>In the next post in this series, we are going to look at creating our own item adorners.&#160; I have received a lot of questions on this subject and thought we would explore it some.&#160; You can download the source code for this project here: <a href="http://tonyc.me/xanELe" target="_blank">PVB04_BasicItemAdorners.zip</a></p>
<p>Until then… Happy Pivoting…</p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/ZkjZXuTe8Gw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2012/01/pivotviewer-basics-basic-item-adorners/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<series:name><![CDATA[PivotViewer Basics]]></series:name>
	<feedburner:origLink>http://tonychampion.net/blog/index.php/2012/01/pivotviewer-basics-basic-item-adorners/</feedburner:origLink></item>
		<item>
		<title>The Art of Speaking: Scott Hanselman</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/JU6uro-WmV4/</link>
		<comments>http://tonychampion.net/blog/index.php/2012/01/the-art-of-speaking-scott-hanselman/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 16:04:00 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[Presentation]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=336</guid>
		<description><![CDATA[After giving my latest talk last night on the Windows 8 XAML story, I thought I would do a little review of the Scott Hanselman’s TekPub video on The Art of Speaking.&#160; Why?&#160; Truthfully, so that I would have a baseline to come back and review further down the road and I thought a few [...]]]></description>
			<content:encoded><![CDATA[<p>After giving my latest talk last night on the Windows 8 XAML story, I thought I would do a little review of the <a href="http://www.hanselman.com/" target="_blank">Scott Hanselman’s</a> TekPub video on <a href="http://tekpub.com/hanselman" target="_blank">The Art of Speaking</a>.&#160; Why?&#160; Truthfully, so that I would have a baseline to come back and review further down the road and I thought a few people might be interested as well.</p>
<p><span id="more-336"></span><br />
<h3>Setting the Stage</h3>
<p>Before I get into the review itself, let me set the stage a bit first.&#160; I have been giving technical presentations for the last two years.&#160; I don’t really get the opportunity to present as often as I would like, but I give about a dozen presentations a year.&#160; I have had the opportunity to speak at some great conferences, like VS Live, and am looking forward to future opportunities.&#160; Not being a naturally gifted speaker, I still remember my first presentation and what a train wreck it was (it was bad…).</p>
<p>However things have gotten better over the last two years and my presentations continue to improve. I have learned a ton of things over the this time, mostly what not to do, and have received a lot of tips from some very accomplished speakers.&#160; When Scott released the new TekPub video I decided to give a look.&#160; I watched it a few weeks ago and tried to put some of the things I learned into practice last night.&#160; So how did it go?&#160; Well…</p>
<p>I don’t really want to give out too much of the video, but I started off with a bang.&#160; Scott talks about his need to make sure he knows the exact setup of the room, hardware, connectivity, etc.&#160; That point got beat into my head last night with a sledge hammer.</p>
<p>I had given a presentation at this user group a few months back and the projector had a HDMI port.&#160; So I thought nothing off it last night and showed up with my fancy new ultrabook to present my Windows 8 talk on.&#160; I even had a backup machine in case I needed it.&#160; However, it was the Build tablet and guess what, only HDMI.&#160; So imagine how happy I was when a room change put us in a room with no HDMI port.&#160;&#160; After running through several attempts to get a work around, we were finally successful.&#160; Now you geeks out there will probably like this.&#160; We had to create an Ad-Hoc network on another laptop (one with a VGA port) and remote desktop into my box.&#160; It killed my one demo that needed internet access, but it got me up and running.&#160; Boys and girls, anyone care to guess what the lesson we learned here was?</p>
<p>After getting off to a very shaky start, the presentation went well enough.&#160; Ok, no one fell asleep so I figure that has to be a win, right?&#160; On the way home I was reviewing the talk and decided it would be a good idea to write this review.</p>
<h3>Finally, the Video Review…</h3>
<p>Hopefully that gives you a better idea of where I am coming from on this review.&#160; I started off as most technical presenters do and am still working my way to becoming a better speaker.&#160; So that brought me to Scott’s video.&#160; </p>
<p>To sum it up, the video itself is excellent and has probably been the most I have learned about giving presentations in a single shot.&#160; In the video <a href="http://blog.wekeroad.com/" target="_blank">Rob Conery</a> presents Scott with a topic and asks him to prepare and give a 15 minute presentation on it.&#160; That is where the value of this video comes in.&#160; Scott has written several posts over the years on tips to becoming a better speaker and there are several other great resources out there as well.&#160; However, being able to watch an accomplish speaker prep for a talk has a ton of value that you can not get from a list of tips.&#160; It gives you a chance to see how he dissects the topic, preps the demos, and how it all comes together in the final presentation.&#160; Of course the process is scaled back so that it will all fit in a reasonable length video, but you still are able to get a sense of the his process.</p>
<p>So I put some of the things I learned in the video to the test.&#160; First off, preparing for my talk was much easier and I felt much more comfortable with what I had going into my presentation (that is before the HDMI fiasco).&#160; As for the talk itself, I honestly didn’t see a lot of changes though.&#160; Which, at first, was a bit disappointing.&#160; However, when I was reviewing the talk on my way home I started making several connections.&#160; Instead of simply thinking that the talk could have gone better, I began to map specific things that I did or did not do to some of the things I saw in the video.&#160; It gave me a better understanding of what needed to be changed and an example of how I could change it.&#160; To me, that is a win.&#160; It is always easier to improve something when you have an idea of what to improve and how to improve it.</p>
<p>Would I recommend this video? Without a doubt I would.&#160; I believe you can purchase the video by itself for $18.&#160; I went for the annual subscription to TekPub instead.&#160; I honestly think Scott’s video alone would be worth the price of the annual subscription but now I get access to all of TekPub’s other great material as well.&#160; </p>
<p>Scott has some more information about the video and links to his other posts on speaking at <a href="http://speakinghacks.com/" target="_blank">SpeakingHacks.com</a>.&#160; Scott and Rob also have a podcast that is quite interesting called <a href="http://thisdeveloperslife.com/" target="_blank">This Developer’s Life</a>.&#160; Of course they both have very active twitter accounts (@shanselman and @robconery).</p>
<p>For any of the speakers out there, especially the ones just starting or thinking about starting, I wish you all the best.&#160; While speaking is something that I forced myself to start doing, I have really began to enjoy it and hope others do as well.</p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/JU6uro-WmV4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2012/01/the-art-of-speaking-scott-hanselman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tonychampion.net/blog/index.php/2012/01/the-art-of-speaking-scott-hanselman/</feedburner:origLink></item>
		<item>
		<title>12th Day of Silverlight: PivotViewer</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/hleub6ay49I/</link>
		<comments>http://tonychampion.net/blog/index.php/2012/01/12th-day-of-silverlight-pivotviewer/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 15:25:01 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[PivotViewer]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[pivotviewer]]></category>
		<category><![CDATA[silverlight 5]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=333</guid>
		<description><![CDATA[This has been the longest series that I have done and I’ve really had a lot of fun doing it.&#160; If you have missed any of them, you can catch the whole series here: 12 Days of Silverlight.&#160; It’s really nice to see the level of interest in Silverlight 5.&#160; Make sure to drop me [...]]]></description>
			<content:encoded><![CDATA[<p>This has been the longest series that I have done and I’ve really had a lot of fun doing it.&#160; If you have missed any of them, you can catch the whole series here: 12 Days of Silverlight.&#160; It’s really nice to see the level of interest in Silverlight 5.&#160; Make sure to drop me a note if you have anything specific you would like to see more about.&#160; I’m always looking for more topics to write about.&#160; So, for the grand finale…</p>
<p>On the twelfth day of Silverlight the team delivered to me… PivotViewer.</p>
<p><span id="more-333"></span>
<p>Anyone who knows me, knows I have a special interest in the PivotViewer.&#160; Simply poking around this blog should show you that.&#160; I’ve given talks across the country on the subject, I’ve blogged about it, and I’ve even tried to write a book on the subject (although I couldn’t find a publisher to pick it up).&#160; Why the interest?&#160; Because I think it is an amazing example of data visualization.&#160; </p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb4.png" width="545" height="293" /></a></p>
<h3>History of PivotViewer</h3>
<p>PivotViewer got it’s start in the Live Labs team.&#160; It original appeared as a WPF application called Pivot.&#160; Although no longer supported, you can still download the original application on <a href="http://research.microsoft.com/en-us/downloads/dd4a479f-92d6-496f-867d-666c87fbaada/default.aspx" target="_blank">Microsoft’s Research page</a>.</p>
<p>The first version of PivotViewer was release in 2010 and worked with Silverlight 4.&#160; While containing most of the features you have in the latest version, it’s data was largely static in nature.&#160; It utilized a XML format, CXML, and mapped data items to members of a DeepZoom collection (which was also written by the Live Labs team).&#160; While useful in certain use cases, it’s limited API and static image nature kept the control from being used in many scenarios.</p>
<p>Even with these limitations, the PivotViewer was well received and in time the team moved to the Silverlight team and PivotViewer became an official Silverlight control.&#160; With a major revamp the new PivotViewer came packed with a lot of new goodies.&#160; While still supporting CXML, you can now create client side collections and generate your visuals dynamically with XAML data templates.&#160; The API has been expanded and you now have a lot more control over appearance and behavior.</p>
<p>While still not perfect, it has come a long way and can now be used in a lot of scenarios that it previously couldn’t.</p>
<h3>Anatomy of PivotViewer</h3>
<p>The first two things you need is data and visualizations (hey, maybe that’s where data visualizations came from &lt;grin&gt;).&#160; The new PivotViewer gives you several ways to accomplish this.&#160; Once you populate PivotViewer with both of these, your screen will load and you will see 3 distinct areas.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb5.png" width="478" height="316" /></a></p>
<p>The main area is the collection container.&#160; It is the heart of the control.&#160; You are able to zoom in and out, pan and scroll with the mouse, etc.&#160; The collection container has two different views: grid view and histogram view.&#160; The grid view lays out your items in a nice grid based on the selected sorting property.&#160; The histogram view will group the items (based on the sorting property) and show them in more of a bar chart.&#160; This gives the user a powerful visualization of comparing counts based on a selected property.&#160; A nice bonus is if you double click a histogram column, it will drill down into that column to give you a finer resolution of the data within.</p>
<p>Above the collection container you have the control bar.&#160; It contains items such as a zoom bar, the sorting property selector, and the ability to switch between grid and histogram view.</p>
<p>To the left you will find the filter panel.&#160; The nicest thing about the filter panel is that it is generated for you.&#160; Each property you define in your data objects is displayed here.&#160; It automatically generates data ranges, value selections, etc.&#160; Adjusting the filter conditions will instantly adjust the items included in the collection container.&#160; Not bad functionality for free.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb6.png" width="480" height="407" /></a></p>
<p>If you select an item you will see an additional panel displayed on the right, the detail pane.&#160; This contains the specifics about the selected item.&#160; While having a built in view, the new PivotViewer also allows you to create a custom detail pane and I show you a walk through here : <a href="http://tonychampion.net/blog/index.php/2011/10/sl5-pivotviewer-custom-detailpanestyle/" target="_blank">Creating a Custom DetailPaneStyle</a>.</p>
<p>By far the best addition to PivotViewer in SL5 is the dynamic nature of it.&#160; If you make any changes to the data items within the application, the changes are instantly reflected in the information and visualization of the object within the PivotViewer.&#160; This creates a lot of use cases where PivotViewer would be a great fit.</p>
<h3>Developing with PivotViewer</h3>
<p>So I’m going to take the easy way out here and we are not going to run thru a PivotViewer example in this post.&#160; The reason is I have another series on doing just that.&#160; If you want to get your feet wet with the new PivotViewer take a look at my <a href="http://tonychampion.net/blog/index.php/series/pivotviewer-basics/" target="_blank">PivotViewer Basics series</a>.</p>
<p>I do want to make a quick shout out here.&#160; Chris Arnold has two great products out there that include PivotViewer: <a href="http://www.photopivot.com/" target="_blank">PhotoPivot</a> and <a href="http://www.percollate.com/" target="_blank">Percollate</a>. If you want to see some of the exciting ways you can use PivotViewer in your applications, I highly recommend checking both of those out.</p>
<h3>The End of a Series…</h3>
<p>As I said at the beginning of this post, this has been a great series to write.&#160; I think the Silverlight 5 release goes a long ways in the right direction.&#160; There are a lot of additional features that this series did not touch on and I would encourage you to go explore them.&#160; You can find out all about the new release on <a href="http://silverlight.net" target="_blank">Silverlight.net</a>.</p>
<p>I will wrap up this series by stealing a phrase from a good friend of mine (who will probably exclude this post from his site because of it &lt;grin&gt;).</p>
<p>.. stay in the ‘light ..</p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/hleub6ay49I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2012/01/12th-day-of-silverlight-pivotviewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[12 Days of Silverlight]]></series:name>
	<feedburner:origLink>http://tonychampion.net/blog/index.php/2012/01/12th-day-of-silverlight-pivotviewer/</feedburner:origLink></item>
		<item>
		<title>11th Day of Silverlight : 3D</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/4XRjV2DDN94/</link>
		<comments>http://tonychampion.net/blog/index.php/2012/01/11th-day-of-silverlight-3d/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 13:28:24 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[silverlight 5]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=324</guid>
		<description><![CDATA[Rounding up the series, we are going to look at a couple of my favorite features in Silverlight 5.&#160; This one has been a hobby of mine sine my college days (which are a lot further away than I care to admit).&#160; Let’s face it, it’s just cool.&#160; That, and it’s let some people do [...]]]></description>
			<content:encoded><![CDATA[<p>Rounding up the series, we are going to look at a couple of my favorite features in Silverlight 5.&#160; This one has been a hobby of mine sine my college days (which are a lot further away than I care to admit).&#160; Let’s face it, it’s just cool.&#160; That, and it’s let some people do some amazing things.</p>
<p>On the eleventh day of Silverlight the team delivered to me… 3D.</p>
<p><span id="more-324"></span>
<p>Yep, that’s right, we now have a 3D stack in Silverlight.&#160; For any of you Xbox developers out there, it should look fairly familiar.&#160; The 3D stack in Silverlight is based off of the XNA framework.&#160; Call it a XNA lite if you will.&#160; While we are not going to build the next blockbuster game, I do think it will be fun to take a look at what 3D looks like inside of Silverlight.</p>
<h3>Creating a 3D Applications</h3>
<p>If you fire up Visual Studio, you will see two new Silverlight solution types available to you : Silverlight 3D Application and Silverlight 3D Library.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb.png" width="550" height="113" /></a></p>
<p>Our example is going to focus on the 3D Application.&#160; If you create the new solution you will see that it creates 4 projects for you.&#160; Two of them should be familiar to you, a SL project and a Web project.&#160; For our 3D application, we have two additional projects (one for the SL side and one for the web).&#160; These projects are there to hold your resources for your application.&#160; In fact, if you try and add a new item to either project you will notice that you are limited to the following items:</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image1.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb1.png" width="550" height="257" /></a></p>
<p>So now that we have a project created, let’s F5 it and see what we get.&#160; Isn’t that a nice little error?&#160; You probably are looking at a notification that you need to enable GPU acceleration.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/SNAGHTMLd67246.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLd67246" border="0" alt="SNAGHTMLd67246" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/SNAGHTMLd67246_thumb.png" width="470" height="192" /></a></p>
<p>Now the fun thing is that when you look at the created web pages, you should see that GPU acceleration is already turned on.&#160; So what’s going on?&#160; Well it turns out that elevated trust is required to run 3D applications.&#160; So turning on elevated trust, whether you are in-browser or out, will get you going.&#160; However, you will still need GPU acceleration so don’t turn that off.&#160; </p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb2.png" width="362" height="41" /></a></p>
<p>Giving the old F5 another try, we see that we have our first 3D application.&#160; It even comes complete with a spinning cube.</p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2012/01/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2012/01/image_thumb3.png" width="428" height="322" /></a></p>
<p>Going down the rabbit hole of developing 3D applications is beyond the scope of this post, but I did want you to at least get something up and running.&#160; Make sure you let me know what cool things you come up with.</p>
<p>Eleven down and one to go.&#160; Anyone care to guess what the last post is going be?&#160; See you soon.</p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/4XRjV2DDN94" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2012/01/11th-day-of-silverlight-3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[12 Days of Silverlight]]></series:name>
	<feedburner:origLink>http://tonychampion.net/blog/index.php/2012/01/11th-day-of-silverlight-3d/</feedburner:origLink></item>
		<item>
		<title>10th Day of Silverlight : O/S Integration</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/rQx9KIsXKKk/</link>
		<comments>http://tonychampion.net/blog/index.php/2012/01/10th-day-of-silverlight-os-integration/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 21:26:43 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[silverlight 5]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=310</guid>
		<description><![CDATA[Time flies.&#160; I took a week off for Christmas and the next thing I know it’s been a few weeks.&#160; The good news is I’ve gotten a new project off of the ground and can’t wait to start talking about it. So where were we?&#160; That’s right, the 10th day.&#160; I’ve received a lot of [...]]]></description>
			<content:encoded><![CDATA[<p>Time flies.&#160; I took a week off for Christmas and the next thing I know it’s been a few weeks.&#160; The good news is I’ve gotten a new project off of the ground and can’t wait to start talking about it.</p>
<p>So where were we?&#160; That’s right, the 10th day.&#160; I’ve received a lot of great feedback from folks and I wanted to thank everyone for all of the comments.</p>
<p>On the tenth day of Silverlight the team delivered to me… better O/S integration.</p>
<p><span id="more-310"></span>
<p>I touched on this subject back on day 1’s : <a href="http://tonychampion.net/blog/index.php/2011/12/1st-day-of-silverlight-native-windows/" target="_blank">Native Windows</a>.&#160; For me, the addition of native window support in Silverlight 5 was a big win.&#160; However, the team did not stop there.&#160; There are several more areas that the team focused on and I thought this would be a great post to talk about them.</p>
<h3>Power Awareness</h3>
<p>The first time I heard someone from the team present this feature, I have to admit, I didn’t really see the point.&#160; However, that very night it became clear to me that this is a nice little feature to have.&#160; Traditionally, Silverlight did not play a part in power management.&#160; So if you had an application, say a video player, running but there was no real interaction taking place the computer might go into sleep mode.&#160; Which, ironically, happened to me that evening when I was streaming some videos from the previous MIX conference.&#160; Silverlight 5 now takes care of that for you.&#160; If you happen to have a video playing, Silverlight won’t let your machine take a little nap.&#160; That means you don’t have to worry about occasionally moving the mouse around to keep things awake.&#160; The best thing about this feature is that it does not require any code to take advantage of it.</p>
<h3>P/Invoke</h3>
<p>So raise your hands if you have used the Silverlight 4 COM interop.&#160; Ok, now keep your hands up if you had fun doing it.&#160; Where did all of the hands go?&#160; COM interop was a very important addition to Silverlight 4.&#160; It really opened the door to allow you to create applications that stepped outside of the sandbox and interacted with the system.&#160; However, it did have one little flaw, COM. It’s like IE 6, just when you thought you had seen the last of it… I digress..</p>
<p>P/Invoke takes that interop access one step further.&#160; Now you have more direct access to the Win32 API and you can pretty much do anything you need to on the system.&#160; Of course, this is only available in elevated trust mode.&#160; There are a lot of examples out on the web that go into this in more detail.&#160; I would suggest strolling over to Pete Brown’s blog and take a look at his <a href="http://10rem.net/blog/2011/09/27/enumerating-printers-using-pinvoke-in-silverlight-5" target="_blank">Enumerating Printers using P/Invoke</a>&#160; post to really get a feel for P/Invoke in action.</p>
<h3></h3>
<h3>Unrestricted File System Access</h3>
<p>Silverlight 5 opens up access to the file system, again in elevated trust mode, to your applications.&#160; You are no longer constrained to certain paths for accessing files.</p>
<p>In thinking about this feature, I have to tell a little story.&#160; Being a Silverlight MVP has been a lot of fun and one of the great things about it is the interaction you get to have with the product team.&#160; This feature is one of the first times that I witnessed the team really listening to us non-blue badges (not that it was the first time, but simply the first time that I was able to be a part of it).&#160; Someone from the team asked the group about the file system access and purposed to open up the access to more locations but not the entire system.&#160; A few people responded with some use cases where full access might be better, and just like that, we have full access to the file system.&#160; It has been really interesting to be involved in that process.</p>
<h3>64-Bit Support</h3>
<p>All I can say is “finally”.&#160; Silverlight 5 now offers a 64-bit client.&#160; My understanding is that this was no small task.&#160; However, I am truly grateful that it is now available.&#160; There is no longer a need to attempt to explain to folks why their 64-bit IE wouldn’t load your Silverlight applications. Whew…&#160; Thank you Silverlight team…</p>
<h3>Full Trust for In-Browser Mode</h3>
<p>Full trust is no longer just for your out-of-browser applications.&#160; You can now implement it in-browser.&#160; This give you a leg up when having to install your applications is not the ideal solution.</p>
<h3>Save Dialog Default Name</h3>
<p>One last little nugget is you can now specify a default file name in the save file dialog.&#160; Doing this is rather straight forward.&#160; The SaveFileDialog has a new property, DefaultFileName.&#160; I bet you can’t guess how to use this feature….</p>
<p>This gives you a little more control, or at a minimum suggestive power, on what a file is named when saving.</p>
<p>So lot’s of goodies in Silverlight 5 when talking about the O/S integration.&#160; Make sure you take a look at them and take advantage of them in your next application.&#160; Two more days left and we will bring this series to a close.&#160; Don’t worry, you won’t have to wait a few weeks for the last two posts. </p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/rQx9KIsXKKk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2012/01/10th-day-of-silverlight-os-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[12 Days of Silverlight]]></series:name>
	<feedburner:origLink>http://tonychampion.net/blog/index.php/2012/01/10th-day-of-silverlight-os-integration/</feedburner:origLink></item>
		<item>
		<title>Welcome to 2012!</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/9emlIIYl7RU/</link>
		<comments>http://tonychampion.net/blog/index.php/2011/12/welcome-to-2012/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 05:06:37 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[Random Thoughts]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=307</guid>
		<description><![CDATA[Yep, it’s that time of year again.&#160; Out with the old and in with the new.&#160; With that in mind, Happy New Years! This past year was an amazing one for me.&#160; I met a ton of brilliant people in the community, was able to be a part of events like the Open Source Fest [...]]]></description>
			<content:encoded><![CDATA[<p>Yep, it’s that time of year again.&#160; Out with the old and in with the new.&#160; With that in mind, Happy New Years!</p>
<p>This past year was an amazing one for me.&#160; I met a ton of brilliant people in the community, was able to be a part of events like the Open Source Fest at MIX, and even had a chance to speak on the Microsoft campus at VS Live.&#160; There has been some major advancements in technology this year and it’s proving to be an exciting time to be a developer.&#160; So all in all, it’s been a lot of fun.</p>
<p>So on to the new year….</p>
<p><span id="more-307"></span><br />
<h3>Technology to Watch</h3>
<p>This year is going to be a very interesting year.&#160; Let’s start off with the big one.&#160; Windows 8 should be out sometime this summer and with it Microsoft should launch itself into the tablet space.&#160; There is going to be a lot of opportunities and I plan on taking advantage of them (care to join me?).&#160; In fact, if all goes well, I will have an entry in the upcoming App Contest (<a title="https://buildwindowscontest.com/" href="https://buildwindowscontest.com/">https://buildwindowscontest.com/</a>).&#160; I also have a couple of additional apps planned for later in the year.</p>
<p>WP7 continues to advance as a player in the mobile industry.&#160; Knowing some of the folks working on the WP7 platform, I’m expecting more great things to come over the next year (and no, I have no idea what those are).</p>
<p>It seems that the biggest news in our industry is the rise of HTML5.&#160; I have to admit, I really haven’t dug too much into it yet.&#160; However, it will be my language to learn in 2012.&#160; There are several great projects out there that bring some of the knowledge of the XAML frameworks (like MVVM) to javascript and I am looking forward to learning more about them.&#160; </p>
<p>Azure continues to evolve as well.&#160; I have recently really started to push on Azure a bit and have liked most of what I have seen.&#160; You will start to see some blog posts from me on my Azure experiences.&#160; I have a new product under development that is centered around Azure and it’s been fun watching it evolve.</p>
<p>Now what about Silverlight?&#160; I guess a Silverlight MVP can’t really talk about the next year without discussing it.&#160; Especially this year.&#160; I think the Silverlight 5 release is a very solid product and it is going to have it’s uses for some time to come.&#160; As far as Silverlight 6, I think I’m going to have to agree with Shawn Wildermuth on this one.&#160; He stated on The Table Show (<a title="http://thetabletshow.com/default.aspx?showNum=11" href="http://thetabletshow.com/default.aspx?showNum=11">http://thetabletshow.com/default.aspx?showNum=11</a>) that he really couldn’t tell you what new features he would want in a new major release (outside of some edge cases).&#160; I really couldn’t come up with much myself.&#160; With 10 years of support, I think it will work for me.</p>
<h3>What to Expect from me…</h3>
<p>I’ve put a great deal of thought into what this year will look like for me.&#160; I’ve got a few exciting things in the works that I can’t wait to tell folks about.&#160; But overall you are going to see a lot more diversity around here.</p>
<p>First and foremost, the PivotViewer posts aren’t going anywhere. The latest version has really advanced the control and I have a ton of articles to write on the subject.&#160; I have a new version of PivotViewer Lessons (<a href="http://pivotviewerlessons.codeplex.com">http://pivotviewerlessons.codeplex.com</a>) in the works, with plans for a second project to follow.</p>
<p>Of course Silverlight will continue to be a common topic around here.&#160; There are still a lot of things to explore in the latest release.&#160; However, you are going to see a lot of XAML posts in different areas as well (Metro and Wp7 for sure).</p>
<p>As I said earlier, HTML5 is going to consume a lot of my learning time this year.&#160; You can expect to see some of what I learn posted here as well.</p>
<p>So you guessed it, 2012 is going to involve a lot of writing on my part.&#160; I’m looking forward to it and hope a few of you will stick around to provide some feedback.</p>
<p>With 2012, you will hopefully see me speaking a bit more.&#160; I had a chance to speak at several interesting places last year and hope to be able to hit a few more this year.&#160; Like the blog, the topics will vary a bit, but you can expect some new Metro talks.</p>
<p>All in all, it should be a busy year with lots of exciting things going on.&#160; But just like most software projects, we will see where scope creep and project delays take us.</p>
<h3>Final Thoughts…</h3>
<p>Well midnight is fast approaching Texas, so I will wrap this up.&#160; I wanted to thank everyone for all of the great feedback and for simply taking the time to stop by my blog every once and a while.&#160; A special thanks to the hand full of friends I made this year and for all of their support and advice they have given me.&#160; I’ve had a lot to learn this year and your expertise has really helped me along the way.</p>
<p>I hope everyone has a great 2012!&#160; I wish you and your family happiness and good fortune.&#160; I also want to challenge everyone to continue to grow within the community.&#160; Whether you are currently an active participant or have yet to start a blog, this next year will be a great one to get involved in a bit more.&#160; I look forward to seeing everyone around the water cooler…</p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/9emlIIYl7RU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2011/12/welcome-to-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tonychampion.net/blog/index.php/2011/12/welcome-to-2012/</feedburner:origLink></item>
		<item>
		<title>9th Day of Silverlight : Implicit Data Templates</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/paRPmLPfNh4/</link>
		<comments>http://tonychampion.net/blog/index.php/2011/12/9th-day-of-silverlight-implicit-data-templates/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 06:23:35 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[implicit data templates]]></category>
		<category><![CDATA[silverlight 5]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=304</guid>
		<description><![CDATA[Only a couple of days left before Christmas and I’m busy wrapping up a few more posts to put them under the tree.&#160; This one is another favorite of mine. On the ninth day of Silverlight, the team delivered to me… implicit data templates. Prior to Silverlight 4, all styles and data templates were explicit.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Only a couple of days left before Christmas and I’m busy wrapping up a few more posts to put them under the tree.&#160; This one is another favorite of mine.</p>
<p>On the ninth day of Silverlight, the team delivered to me… implicit data templates.</p>
<p><span id="more-304"></span>
<p>Prior to Silverlight 4, all styles and data templates were explicit.&#160; This meant that every time you referenced one you had to do so by the key name.&#160; Silverlight 4 introduced implicit styles where you could use the new property TargetType to set the default style of a control.&#160; This was a monumental leap in component reusability and style management.</p>
<p>Silverlight 5 introduced the next piece by providing implicit data templates.&#160; The best way to really discuss implicit data templates and their benefits is to walk thru it.</p>
<h3>Using Data Templates</h3>
<p>Let’s get started with taking a brief look at data templates themselves.&#160; After starting a new Silverlight project, we will create a templated ListBox.&#160; First we need to create a data object to work with.&#160; For this first example let’s create a simple Vehicle class:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Vehicle
{
    <span class="kwrd">public</span> <span class="kwrd">string</span> Make { get; set; }
    <span class="kwrd">public</span> <span class="kwrd">string</span> Model { get; set; }
    <span class="kwrd">public</span> Color Color { get; set; }
}</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>Now will we create a simple ListBox to display some data.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;LayoutRoot&quot;</span> <span class="attr">Background</span><span class="kwrd">=&quot;White&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">ListBox</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;myList&quot;</span>
                <span class="attr">Width</span><span class="kwrd">=&quot;325&quot;</span>
                <span class="attr">Height</span><span class="kwrd">=&quot;400&quot;</span>
                <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                <span class="attr">BorderThickness</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Grid</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 last step is to create some data in our code behind and set the ListBox’s ItemsSource property to it.</p>
<pre class="csharpcode"><span class="kwrd">public</span> MainPage()
{
    InitializeComponent();

    myList.ItemsSource = <span class="kwrd">new</span> List&lt;Vehicle&gt;()
    {
        <span class="kwrd">new</span> Vehicle() {Make = <span class="str">&quot;Dodge&quot;</span>,
                       Model = <span class="str">&quot;Charger&quot;</span>,
                       Color = Colors.Black},
        <span class="kwrd">new</span> Vehicle() {Make = <span class="str">&quot;Ford&quot;</span>,
                       Model = <span class="str">&quot;Mustang&quot;</span>,
                       Color = Colors.Red},
        <span class="kwrd">new</span> Vehicle() {Make = <span class="str">&quot;Chevy&quot;</span>,
                       Model = <span class="str">&quot;Corvette&quot;</span>,
                       Color = Colors.Yellow},
        <span class="kwrd">new</span> Vehicle() {Make = <span class="str">&quot;Ford&quot;</span>,
                       Model = <span class="str">&quot;Pinto&quot;</span>,
                       Color = Colors.Blue}
    };
}</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>Now if you run the example, you will get a list of items that have the full name of our Vehicle class.&#160; </p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2011/12/image23.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2011/12/image_thumb23.png" width="335" height="445" /></a></p>
<p>Not exactly a&#160; world class list box is it?&#160; So now let’s see a data template in action.&#160; We will create a DataTemplate on our page and assign the ListBox’s ItemTemplate property to it.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">UserControl.Resources</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">local:SolidColorBrushConverter</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;colConv&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;vehicleTemplate&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Width</span><span class="kwrd">=&quot;300&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">LinearGradientBrush</span> <span class="attr">StartPoint</span><span class="kwrd">=&quot;0,0&quot;</span>
                                        <span class="attr">EndPoint</span><span class="kwrd">=&quot;0,1&quot;</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;White&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;0&quot;</span><span class="kwrd">/&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;LightGray&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">LinearGradientBrush</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;225&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;75&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Margin</span><span class="kwrd">=&quot;10, 5, 0, 5&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
                    <span class="attr">FontSize</span><span class="kwrd">=&quot;18&quot;</span>
                    <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Make}&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
                    <span class="attr">FontSize</span><span class="kwrd">=&quot;14&quot;</span>
                    <span class="attr">Margin</span><span class="kwrd">=&quot;0,5,0,0&quot;</span>
                    <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Model}&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Rectangle</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;1&quot;</span>
                <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                <span class="attr">Height</span><span class="kwrd">=&quot;50&quot;</span>
                <span class="attr">Width</span><span class="kwrd">=&quot;50&quot;</span>
                <span class="attr">Fill</span><span class="kwrd">=&quot;{Binding Color,
                        Converter=
                        {StaticResource colConv}}&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">UserControl.Resources</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;LayoutRoot&quot;</span> <span class="attr">Background</span><span class="kwrd">=&quot;White&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">ListBox</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;myList&quot;</span>
            <span class="attr">Width</span><span class="kwrd">=&quot;325&quot;</span>
            <span class="attr">Height</span><span class="kwrd">=&quot;400&quot;</span>
            <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
            <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
            <span class="attr">ItemTemplate</span><span class="kwrd">=&quot;{StaticResource vehicleTemplate}&quot;</span>
            <span class="attr">BorderThickness</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Grid</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>You might notice I had to add a value converter in there.&#160; The converter takes a Color and returns a SolidColorBrush.&#160; Here is that value converter. </p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> SolidColorBrushConverter : IValueConverter
{

    <span class="kwrd">public</span> <span class="kwrd">object</span> Convert(<span class="kwrd">object</span> <span class="kwrd">value</span>,
        Type targetType,
        <span class="kwrd">object</span> parameter,
        System.Globalization.CultureInfo culture)
    {
        <span class="kwrd">if</span>(<span class="kwrd">value</span> <span class="kwrd">is</span> Color)
        {
            <span class="kwrd">return</span> <span class="kwrd">new</span> SolidColorBrush((Color)<span class="kwrd">value</span>);
        }

        <span class="kwrd">return</span> <span class="kwrd">null</span>;
    }

    <span class="kwrd">public</span> <span class="kwrd">object</span> ConvertBack(<span class="kwrd">object</span> <span class="kwrd">value</span>,
        Type targetType,
        <span class="kwrd">object</span> parameter,
        System.Globalization.CultureInfo culture)
    {
        <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
    }
}</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>Now running our application will yield a bit more information than last time.&#160; </p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2011/12/image24.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2011/12/image_thumb24.png" width="327" height="396" /></a></p>
<h3>Implicate Data Templates</h3>
<p>In the previous example we specifically set the ItemTemplate in the ListBox to our data template.&#160; However, with implicit data templates, we no longer need to do that.&#160; The DataTemplate class has a new property, much like the Style’s TargetType, DataType.&#160; By setting the DataType to our Vehicle class, we our telling Silverlight to use this data template unless otherwise told.&#160; We no longer need to set the ItemTemplate on our ListBox.&#160; The modified XAML should look like this:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">UserControl.Resources</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">local:SolidColorBrushConverter</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;colConv&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">DataType</span><span class="kwrd">=&quot;local:Vehicle&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Width</span><span class="kwrd">=&quot;300&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">LinearGradientBrush</span> <span class="attr">StartPoint</span><span class="kwrd">=&quot;0,0&quot;</span>
                                        <span class="attr">EndPoint</span><span class="kwrd">=&quot;0,1&quot;</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;White&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;0&quot;</span><span class="kwrd">/&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;LightGray&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">LinearGradientBrush</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;225&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;75&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Margin</span><span class="kwrd">=&quot;10, 5, 0, 5&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
                    <span class="attr">FontSize</span><span class="kwrd">=&quot;18&quot;</span>
                    <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Make}&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
                    <span class="attr">FontSize</span><span class="kwrd">=&quot;14&quot;</span>
                    <span class="attr">Margin</span><span class="kwrd">=&quot;0,5,0,0&quot;</span>
                    <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Model}&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Rectangle</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;1&quot;</span>
                <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                <span class="attr">Height</span><span class="kwrd">=&quot;50&quot;</span>
                <span class="attr">Width</span><span class="kwrd">=&quot;50&quot;</span>
                <span class="attr">Fill</span><span class="kwrd">=&quot;{Binding Color,
                        Converter=
                        {StaticResource colConv}}&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">UserControl.Resources</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;LayoutRoot&quot;</span> <span class="attr">Background</span><span class="kwrd">=&quot;White&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">ListBox</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;myList&quot;</span>
            <span class="attr">Width</span><span class="kwrd">=&quot;325&quot;</span>
            <span class="attr">Height</span><span class="kwrd">=&quot;400&quot;</span>
            <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
            <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
            <span class="attr">BorderThickness</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Grid</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>Running the application you will notice that is looks identical to the last run.&#160; Just for completion, you can change the ListBox to a ComboBox and will see that the same template is being used.&#160; </p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2011/12/image25.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2011/12/image_thumb25.png" width="299" height="74" /></a></p>
<p>Pretty slick stuff, huh?&#160; Now it is possible to start building components that are reusable and not reliant on specific names for data templates and can be a bit more flexible.&#160; However, as cool as that is, let’s crank it up a notch.&#160; What if we added 3 new classes that all inherit from the Vehicle class (Car, Motorcycle, Truck)?&#160; Let’s add these new classes, each with a unique new property :</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Car : Vehicle
{
    <span class="kwrd">public</span> <span class="kwrd">int</span> PassengerCount { get; set; }
}

<span class="kwrd">public</span> <span class="kwrd">class</span> Motorcycle : Vehicle
{
    <span class="kwrd">public</span> <span class="kwrd">string</span> Type { get; set; }
}

<span class="kwrd">public</span> <span class="kwrd">class</span> Truck : Vehicle
{
    <span class="kwrd">public</span> <span class="kwrd">int</span> TrailerLength { get; set; }
}</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>Next we will update our code that is creating our collection set to use our new objects.&#160; You might notice we kept the original Vehicle list since all of our objects inherit for the Vehicle class. </p>
<pre class="csharpcode">myList.ItemsSource = <span class="kwrd">new</span> List&lt;Vehicle&gt;()
{
    <span class="kwrd">new</span> Car() {Make = <span class="str">&quot;Dodge&quot;</span>,
                    Model = <span class="str">&quot;Charger&quot;</span>,
                    Color = Colors.Black,
                    PassengerCount = 5},
    <span class="kwrd">new</span> Car() {Make = <span class="str">&quot;Ford&quot;</span>,
                    Model = <span class="str">&quot;Mustang&quot;</span>,
                    Color = Colors.Red,
                    PassengerCount = 4},
    <span class="kwrd">new</span> Motorcycle() {Make = <span class="str">&quot;Harley Davidson&quot;</span>,
                    Model = <span class="str">&quot;Sporster&quot;</span>,
                    Color = Colors.Yellow,
                    Type = <span class="str">&quot;Cruiser&quot;</span>},
    <span class="kwrd">new</span> Truck() {Make = <span class="str">&quot;Peterbilt&quot;</span>,
                    Model = <span class="str">&quot;387&quot;</span>,
                    Color = Colors.Blue,
                    TrailerLength = 20}
};</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>Now if we run our application, you will notice that nothing has changed.&#160; That is because we are still using our Vehicle template.&#160; However, with our new classes, maybe we would like to display different data based on the type of class.&#160; For instance, maybe we can show the number of passengers a car can hold or the length of trailer a truck has.&#160; In SL4 you could accomplish this by creating a custom content control and define the content based off of the class (a neat little trick I picked up from the PivotViewer team).&#160; Now it is as simple as defining multiple data templates.&#160; So let’s add a few more data templates to our UserControl’s resources.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">DataType</span><span class="kwrd">=&quot;local:Car&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Width</span><span class="kwrd">=&quot;300&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">LinearGradientBrush</span> <span class="attr">StartPoint</span><span class="kwrd">=&quot;0,0&quot;</span>
                                <span class="attr">EndPoint</span><span class="kwrd">=&quot;0,1&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;White&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;0&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;LightGray&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">LinearGradientBrush</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;150&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;75&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;75&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Margin</span><span class="kwrd">=&quot;10, 5, 0, 5&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
            <span class="attr">FontSize</span><span class="kwrd">=&quot;18&quot;</span>
            <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Make}&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
            <span class="attr">FontSize</span><span class="kwrd">=&quot;14&quot;</span>
            <span class="attr">Margin</span><span class="kwrd">=&quot;0,5,0,0&quot;</span>
            <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Model}&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                    <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                    <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                        <span class="attr">FontSize</span><span class="kwrd">=&quot;22&quot;</span>
                        <span class="attr">FontWeight</span><span class="kwrd">=&quot;Bold&quot;</span>
                        <span class="attr">Text</span><span class="kwrd">=&quot;{Binding PassengerCount}&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">FontSize</span><span class="kwrd">=&quot;10&quot;</span>
                        <span class="attr">Text</span><span class="kwrd">=&quot;Passengers&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span class="html">Rectangle</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;2&quot;</span>
        <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
        <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
        <span class="attr">Height</span><span class="kwrd">=&quot;50&quot;</span>
        <span class="attr">Width</span><span class="kwrd">=&quot;50&quot;</span>
        <span class="attr">Fill</span><span class="kwrd">=&quot;{Binding Color,
                Converter=
                {StaticResource colConv}}&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">DataType</span><span class="kwrd">=&quot;local:Motorcycle&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Width</span><span class="kwrd">=&quot;300&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">LinearGradientBrush</span> <span class="attr">StartPoint</span><span class="kwrd">=&quot;0,0&quot;</span>
                                <span class="attr">EndPoint</span><span class="kwrd">=&quot;0,1&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;White&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;0&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;LightGray&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">LinearGradientBrush</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;225&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;75&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Margin</span><span class="kwrd">=&quot;10, 5, 0, 5&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
            <span class="attr">FontSize</span><span class="kwrd">=&quot;18&quot;</span>
            <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Make}&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Orientation</span><span class="kwrd">=&quot;Horizontal&quot;</span> <span class="attr">Margin</span><span class="kwrd">=&quot;0,5,0,0&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
            <span class="attr">FontSize</span><span class="kwrd">=&quot;14&quot;</span>
            <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Model}&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                    <span class="attr">FontSize</span><span class="kwrd">=&quot;14&quot;</span>
                    <span class="attr">FontStyle</span><span class="kwrd">=&quot;Italic&quot;</span>
                    <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Type}&quot;</span>
                    <span class="attr">Margin</span><span class="kwrd">=&quot;60,0,0,0&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Rectangle</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;2&quot;</span>
        <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
        <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
        <span class="attr">Height</span><span class="kwrd">=&quot;50&quot;</span>
        <span class="attr">Width</span><span class="kwrd">=&quot;50&quot;</span>
        <span class="attr">Fill</span><span class="kwrd">=&quot;{Binding Color,
                Converter=
                {StaticResource colConv}}&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">DataType</span><span class="kwrd">=&quot;local:Truck&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Width</span><span class="kwrd">=&quot;300&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">LinearGradientBrush</span> <span class="attr">StartPoint</span><span class="kwrd">=&quot;0,0&quot;</span>
                                <span class="attr">EndPoint</span><span class="kwrd">=&quot;0,1&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;White&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;0&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">=&quot;LightGray&quot;</span> <span class="attr">Offset</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">LinearGradientBrush</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid.Background</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;150&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;75&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">=&quot;75&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Margin</span><span class="kwrd">=&quot;10, 5, 0, 5&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
            <span class="attr">FontSize</span><span class="kwrd">=&quot;18&quot;</span>
            <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Make}&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span>
            <span class="attr">FontSize</span><span class="kwrd">=&quot;14&quot;</span>
            <span class="attr">Margin</span><span class="kwrd">=&quot;0,5,0,0&quot;</span>
            <span class="attr">Text</span><span class="kwrd">=&quot;{Binding Model}&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                    <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                    <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;1&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
                        <span class="attr">FontSize</span><span class="kwrd">=&quot;22&quot;</span>
                        <span class="attr">FontWeight</span><span class="kwrd">=&quot;Bold&quot;</span>
                        <span class="attr">Text</span><span class="kwrd">=&quot;{Binding TrailerLength}&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">FontSize</span><span class="kwrd">=&quot;10&quot;</span>
                        <span class="attr">Text</span><span class="kwrd">=&quot;Length&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span class="html">Rectangle</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">=&quot;2&quot;</span>
        <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
        <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Center&quot;</span>
        <span class="attr">Height</span><span class="kwrd">=&quot;50&quot;</span>
        <span class="attr">Width</span><span class="kwrd">=&quot;50&quot;</span>
        <span class="attr">Fill</span><span class="kwrd">=&quot;{Binding Color,
                Converter=
                {StaticResource colConv}}&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid</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>Running our application now gives us unique displays for each type of class.&#160; </p>
<p><a href="http://tonychampion.net/blog/wp-content/uploads/2011/12/image26.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://tonychampion.net/blog/wp-content/uploads/2011/12/image_thumb26.png" width="399" height="346" /></a></p>
<p>A thing to note is that this will still run if you keep the original Vehicle data template in there.&#160; This is helpful when only some of the inherited classes need to have generic interfaces.&#160; You can create an interface for the base class and use it as a fallback.&#160; </p>
<p>From here, it is possible to take things a step further.&#160; You can begin to create UI’s that are very dynamic and driven off of data templates.&#160; For instance, you can have generic master/detail screens that the UI is defined by the binding&#160; data type.&#160; Pretty slick stuff if you ask me and I will dig into more of that at a later date.</p>
<p>The code for this example can be found here: <a href="http://tonyc.me/tcQfHe" target="_blank">DaysOfSilverlight_ImplicitDataTemplates.zip</a></p>
<p>Down to the final three.&#160; As we are rolling into a big holiday weekend, I hope everyone has wonderful time celebrating with friends and family.&#160; See you back soon…</p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/paRPmLPfNh4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2011/12/9th-day-of-silverlight-implicit-data-templates/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<series:name><![CDATA[12 Days of Silverlight]]></series:name>
	<feedburner:origLink>http://tonychampion.net/blog/index.php/2011/12/9th-day-of-silverlight-implicit-data-templates/</feedburner:origLink></item>
		<item>
		<title>8th Day of Silverlight : Vector Printing</title>
		<link>http://feedproxy.google.com/~r/tonychampion/~3/fiOOgoMh3ww/</link>
		<comments>http://tonychampion.net/blog/index.php/2011/12/8th-day-of-silverlight-vector-printing/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 20:13:20 +0000</pubDate>
		<dc:creator>Tony Champion</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[printing]]></category>
		<category><![CDATA[silverlight 5]]></category>

		<guid isPermaLink="false">http://tonychampion.net/blog/?p=292</guid>
		<description><![CDATA[On the home stretch.&#160; I’ve had some great feedback from everyone and I do appreciate it.&#160; Going to be close to bring the series to an end before the 25th, but it will get there.&#160; So… On the eighth day of Silverlight, the team delivered to me… vector printing. Printing, printing, printing.&#160; Prior to SL4, [...]]]></description>
			<content:encoded><![CDATA[<p>On the home stretch.&#160; I’ve had some great feedback from everyone and I do appreciate it.&#160; Going to be close to bring the series to an end before the 25th, but it will get there.&#160; So…</p>
<p>On the eighth day of Silverlight, the team delivered to me… vector printing.</p>
<p><span id="more-292"></span>
<p>Printing, printing, printing.&#160; Prior to SL4, I couldn’t even begin to tell you how many times I had clients “absolutely have to have&quot; printing support.&#160; Over the last year and a half I written more demos about printing than I have implementations.&#160; Seems that everyone decided PDF exports worked just fine.&#160; Go figure.</p>
<p>However, vector printing is a great new feature for folks needing printing support.&#160; It offers several improvements over the SL4 bitmap printing and is worth discussing.</p>
<p>Let’s take a closer look at some of those benefits.&#160; The first thing to mention is that, from an API standpoint, printing is still backwards compatible with SL4.&#160; So it has the same PrintDocument class and it’s events are still the same.&#160; However, the Print() method now defaults to vector printing when available.&#160; You don’t have to make any changes to get the benefits of vector printing.</p>
<p>It is worth noting that the vector printing added to SL5 only supports PostScript vector printing.&#160; So if your printer, or more accurately your print driver, does not support PostScript Silverlight will print using the original bitmap printing.&#160; This is a subtle thing that is being over looked quite frequently.</p>
<p>Another time when that Silverlight will revert to bitmap printing is if you have any elements on your screen that Silverlight cannot convert to PostScript.&#160; Just a few things to keep in mind.&#160; However, if Silverlight does revert back to bitmap printing, it does so silently and without error.</p>
<p>The printing API has been extended slightly to give the developer a little more control.&#160; The first is a new method PrintBitmap().&#160; I bet you can’t guess what this does.&#160; Yep, it starts the SL4 version of bitmap printing.</p>
<p>The next change is a new Print() method.&#160; The original Print(string documentName) method is still there, however, SL5 adds a new signature that gives you a little more flexibility.&#160; The new method is:</p>
<p>Print(string name, PrinterFallbackSettings settings, bool useDefaultPrinter)</p>
<p>The first parameter is the document name and is treated the same as the other method.&#160; The next parameter exposes a new class PrinterFallbackSettings.</p>
<p>The PrinterFallbackSettings class only contains two properties.&#160; The first, ForceVector, is simply a bool value that determines whether Silverlight is forced to print in the vector format or not.&#160; </p>
<p>The second property, OpacityThreshold, is a bit more complicated.&#160; By default, if the XAML that you send to the print API contains any elements with the opacity set lower than 1.0, Silverlight will use bitmap printing.&#160; The OpacityThreshold allows you to adjust that value.&#160; The value you set, which should be between 0.0 and 1.0, tells Silverlight what is the cut-off opacity value.&#160; For instance, if you set the value to 0.5 any element that has an opacity set lower than 0.5 you bump you to printing in bitmap mode.&#160; One thing to remember is that if you lower the threshold any element whose opacity is still in range will print with the opacity set to 1.0.&#160; So if your element has a 0.5 opacity in our above example it will print, but the results just might not be what you are expecting.</p>
<p>The last property is a bool the lets you skip the Printer dialog box and go straight to the default printer.&#160; This only works when you have elevated trust enabled in your application. Otherwise an exception will bet thrown. Believe it or not, this little bool is a big deal for this release. There were several COM hacks written to allow this in SL4, especially for point-of-sale systems.&#160; </p>
<p>Wrapping up this post, you will probably notice there isn’t any code on this post.&#160; Since the API hasn’t changed all that much, there really wasn’t much to demo here.&#160; </p>
<p>The biggest complaint I here about printing in Silverlight is the minimalist API.&#160; It leaves a lot of work for you to do on your own.&#160; The plus side of this is that you can make it do exactly want you want.&#160; The down side is you have to write the code to make it do exactly what you want.&#160; There have been some great report writer projects kicked off on CodePlex and that is a great place to start when building out an API that is better suited to your needs.</p>
<p>Only four most posts in my <a href="http://tonychampion.net/blog/index.php/series/12-days-of-silverlight/" target="_blank">12 Days of Silverlight series</a>.&#160; And if you are wondering, yes, the next post will have code. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://tonychampion.net/blog/wp-content/uploads/2011/12/wlEmoticon-smile3.png" /></p>
<img src="http://feeds.feedburner.com/~r/tonychampion/~4/fiOOgoMh3ww" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tonychampion.net/blog/index.php/2011/12/8th-day-of-silverlight-vector-printing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<series:name><![CDATA[12 Days of Silverlight]]></series:name>
	<feedburner:origLink>http://tonychampion.net/blog/index.php/2011/12/8th-day-of-silverlight-vector-printing/</feedburner:origLink></item>
	</channel>
</rss>

