<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>DevDave - Dave Relyea's Silverlight Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/devdave/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/devdave/feed.xml</link>
    <description>Silverlight Phone and Rich Client Development</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:02:31 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>A better Slider for Windows Phone 7</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/a-better-slider-for-windows-phone-7</link>
      <pubDate>Mon, 04 Oct 2010 08:08:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2010/10/04/a-better-slider-for-windows-phone-7/</guid>
      <description><![CDATA[The Slider control as shipped with the Windows Phone Developer Tools has some problems, both due to...]]></description>
      <content:encoded><![CDATA[<p>The Slider control as shipped with the Windows Phone Developer Tools has some problems, both due to how it was templated, and also because it was originally designed for the desktop, where mice are very good at hitting small targets.</p>
<p>The visible Thumb was removed, and the invisible Thumb, even when you know where it is, is quite difficult to touch and drag. This means that most often, you end up pressing one of the RepeatButtons that will slowly increment or decrement the Slider&rsquo;s value. That may be what you intended, but the Slider on the phone shouldn&rsquo;t be used for precision adjustments. That will just frustrate the user.</p>
<p>It is quite difficult to manipulate a horizontal Slider to get the maximum value, and if you somehow do manage to do that, you will find that you have moved the invisible Thumb off of the Slider, where it will be clipped, and you have to press the decrement button a while to get it back.</p>
<p>I have re-templated the Slider, and added a small tick mark in the thumb for some sort of a visual cue, as when the Slider is on its minimum value, the darkened track is sometimes hard to see. It is easy to remove the tick if your application provides enough context to make it clear that there is a Slider and how to use it. I made the touchable area much wider&mdash;in fact, the Thumb has been expanded to cover the entire Slider area, so that the user can drag anywhere on the Slider without having to hit a small, invisible target.</p>
<p>Note that the Slider should be used judiciously. Controls that are manipulated by dragging should not be placed in situations where they are on a parent that uses drags of the same orientation. So, for example, you should not put a horizontal Slider inside of a Panorama or Pivot control, and you should not put a vertical Slider inside of a ListBox (I have a hard time imagining why you&rsquo;d want to do the latter.)</p>
<p>Here is the new Slider template. I started with the template that I found in </p>
<p>%ProgramFiles%\Microsoft SDKs\Windows Phone\v7.0\Design\System.Windows.xaml</p>
<p>although I could have used Blend, added a Slider, and then right-clicked on it and selected &ldquo;Edit Template&hellip;&rdquo; and then &ldquo;Edit a Copy&hellip;&rdquo;. I put my template in App.xaml:</p>
<div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:69c2cc9a-b025-4b3a-9b07-4a225cb4acc7" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Application</span> </li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Class</span><span style="color:#0000ff">="SliderApp.App"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">="https://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">x</span><span style="color:#0000ff">="https://schemas.microsoft.com/winfx/2006/xaml"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">phone</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">shell</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">local</span><span style="color:#0000ff">="clr-namespace:SliderApp"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#008000">&lt;!--Application Resources--&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Application.Resources</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ControlTemplate</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Key</span><span style="color:#0000ff">="PhoneSimpleRepeatButton"</span><span style="color:#ff0000"> TargetType</span><span style="color:#0000ff">="RepeatButton"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#0000ff">/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ControlTemplate</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ControlTemplate</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Key</span><span style="color:#0000ff">="PhoneSimpleThumbHorizontal"</span><span style="color:#ff0000"> TargetType</span><span style="color:#0000ff">="Thumb"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Border</span><span style="color:#ff0000"> Background</span><span style="color:#0000ff">="Transparent"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="-480,-18"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="2"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="6"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneForegroundBrush}</span><span style="color:#0000ff">"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Border</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ControlTemplate</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ControlTemplate</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Key</span><span style="color:#0000ff">="PhoneSimpleThumbVertical"</span><span style="color:#ff0000"> TargetType</span><span style="color:#0000ff">="Thumb"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Border</span><span style="color:#ff0000"> Background</span><span style="color:#0000ff">="Transparent"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="-6,-800"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="6"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="2"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="24,0,0,0"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneForegroundBrush}</span><span style="color:#0000ff">"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Border</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ControlTemplate</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Style</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Key</span><span style="color:#0000ff">="sliderStyle"</span><span style="color:#ff0000"> TargetType</span><span style="color:#0000ff">="local:PhoneSlider"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="BorderThickness"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="0"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="BorderBrush"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="Transparent"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="Maximum"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="10"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="Minimum"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="0"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="Value"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="0"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="Margin"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneHorizontalMargin}</span><span style="color:#0000ff">"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="Background"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneContrastBackgroundBrush}</span><span style="color:#0000ff">"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="Foreground"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneAccentBrush}</span><span style="color:#0000ff">"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter</span><span style="color:#ff0000"> Property</span><span style="color:#0000ff">="Template"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Setter.Value</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ControlTemplate</span><span style="color:#ff0000"> TargetType</span><span style="color:#0000ff">="local:PhoneSlider"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#ff0000"> Background</span><span style="color:#0000ff">="Transparent"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">VisualStateManager.VisualStateGroups</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">VisualStateGroup</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="CommonStates"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">VisualState</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="Normal"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">VisualState</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="MouseOver"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">VisualState</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="Disabled"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Storyboard</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">DoubleAnimation</span><span style="color:#ff0000"> Duration</span><span style="color:#0000ff">="0"</span><span style="color:#ff0000"> Storyboard.TargetName</span><span style="color:#0000ff">="HorizontalTrack"</span><span style="color:#ff0000"> Storyboard.TargetProperty</span><span style="color:#0000ff">="Opacity"</span><span style="color:#ff0000"> To</span><span style="color:#0000ff">="0.1" /&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">DoubleAnimation</span><span style="color:#ff0000"> Duration</span><span style="color:#0000ff">="0"</span><span style="color:#ff0000"> Storyboard.TargetName</span><span style="color:#0000ff">="VerticalTrack"</span><span style="color:#ff0000"> Storyboard.TargetProperty</span><span style="color:#0000ff">="Opacity"</span><span style="color:#ff0000"> To</span><span style="color:#0000ff">="0.1" /&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ObjectAnimationUsingKeyFrames</span><span style="color:#ff0000"> Storyboard.TargetName</span><span style="color:#0000ff">="HorizontalFill"</span><span style="color:#ff0000"> Storyboard.TargetProperty</span><span style="color:#0000ff">="Fill"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">DiscreteObjectKeyFrame</span><span style="color:#ff0000"> KeyTime</span><span style="color:#0000ff">="0"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneDisabledBrush}</span><span style="color:#0000ff">" /&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ObjectAnimationUsingKeyFrames</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ObjectAnimationUsingKeyFrames</span><span style="color:#ff0000"> Storyboard.TargetName</span><span style="color:#0000ff">="VerticalFill"</span><span style="color:#ff0000"> Storyboard.TargetProperty</span><span style="color:#0000ff">="Fill"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">DiscreteObjectKeyFrame</span><span style="color:#ff0000"> KeyTime</span><span style="color:#0000ff">="0"</span><span style="color:#ff0000"> Value</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneDisabledBrush}</span><span style="color:#0000ff">" /&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ObjectAnimationUsingKeyFrames</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Storyboard</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">VisualState</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">VisualStateGroup</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">VisualStateManager.VisualStateGroups</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="HorizontalTemplate"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid.ColumnDefinitions</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ColumnDefinition</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="*"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ColumnDefinition</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="0"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ColumnDefinition</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="auto"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid.ColumnDefinitions</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="HorizontalTrack"</span><span style="color:#ff0000"> IsHitTestVisible</span><span style="color:#0000ff">="False"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> Background}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Opacity</span><span style="color:#0000ff">="0.2"</span><span style="color:#ff0000"> Grid.ColumnSpan</span><span style="color:#0000ff">="3"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="12"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="0,22,0,50"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="HorizontalFill"</span><span style="color:#ff0000"> IsHitTestVisible</span><span style="color:#0000ff">="False"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> Foreground}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">="0"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="12"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="0,22,0,50"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RepeatButton</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="HorizontalTrackLargeChangeDecreaseRepeatButton"</span><span style="color:#ff0000"> IsTabStop</span><span style="color:#0000ff">="False"</span><span style="color:#ff0000"> Template</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneSimpleRepeatButton}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">="0" /&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RepeatButton</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="HorizontalTrackLargeChangeIncreaseRepeatButton"</span><span style="color:#ff0000"> IsTabStop</span><span style="color:#0000ff">="False"</span><span style="color:#ff0000"> Template</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneSimpleRepeatButton}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">="2" /&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Thumb</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="HorizontalThumb"</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="1"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="-1,0,0,0"</span><span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">="1"</span><span style="color:#ff0000"> Template</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneSimpleThumbHorizontal}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> RenderTransformOrigin</span><span style="color:#0000ff">="0.5,0.5"</span><span style="color:#ff0000"> CacheMode</span><span style="color:#0000ff">="BitmapCache"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="VerticalTemplate"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid.RowDefinitions</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="*"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="0"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="Auto"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid.RowDefinitions</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="VerticalTrack"</span><span style="color:#ff0000"> IsHitTestVisible</span><span style="color:#0000ff">="False"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> Background}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Opacity</span><span style="color:#0000ff">="0.2"</span><span style="color:#ff0000"> Grid.RowSpan</span><span style="color:#0000ff">="3"</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="12"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="24,0"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="VerticalFill"</span><span style="color:#ff0000"> IsHitTestVisible</span><span style="color:#0000ff">="False"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> Foreground}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">="2"</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="12"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="24,0"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RepeatButton</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="VerticalTrackLargeChangeDecreaseRepeatButton"</span><span style="color:#ff0000"> IsTabStop</span><span style="color:#0000ff">="False"</span><span style="color:#ff0000"> Template</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneSimpleRepeatButton}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">="0"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RepeatButton</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="VerticalTrackLargeChangeIncreaseRepeatButton"</span><span style="color:#ff0000"> IsTabStop</span><span style="color:#0000ff">="False"</span><span style="color:#ff0000"> Template</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneSimpleRepeatButton}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">="2"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Thumb</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="VerticalThumb"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="1"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="0,-1,0,0"</span><span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">="1"</span><span style="color:#ff0000"> Template</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneSimpleThumbVertical}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> RenderTransformOrigin</span><span style="color:#0000ff">="0.5,0.5"</span><span style="color:#ff0000"> CacheMode</span><span style="color:#0000ff">="BitmapCache"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ControlTemplate</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Setter.Value</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Setter</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Style</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Application.Resources</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Application.ApplicationLifetimeObjects</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#008000">&lt;!--Required object that handles lifetime events for the application--&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">shell</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationService</span> </li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> Launching</span><span style="color:#0000ff">="Application_Launching"</span><span style="color:#ff0000"> Closing</span><span style="color:#0000ff">="Application_Closing"</span> </li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> Activated</span><span style="color:#0000ff">="Application_Activated"</span><span style="color:#ff0000"> Deactivated</span><span style="color:#0000ff">="Application_Deactivated"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Application.ApplicationLifetimeObjects</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Application</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</div>
</div>
<p>This could also be placed in your page&rsquo;s resources or in generic.xaml. You will note that in lines 28 and 39, I have am not using TargetType=&rdquo;Slider&rdquo;, but I have used the name of my subclassed type. This is because I had to use some code-behind to handle the Clip area. Since I am using negative margins to make the Thumbs cover the entire Slider, and I had to make the Thumbs large enough to cover the entire Slider, no matter where it is positioned, I need code to handle the clipping, otherwise the Thumbs would extend way beyond the Slider&rsquo;s bounds, and cover up other controls. This is particularly a problem for vertical Sliders.</p>
<p>Fortunately, the code-behind isn&rsquo;t much:</p>
<div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4de8d2d5-d0c1-491e-be04-f3b0acd54436" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">using</span> System.Windows;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">using</span> System.Windows.Controls;</li>
<li><span style="color:#0000ff">using</span> System.Windows.Media;</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">namespace</span> SliderApp</li>
<li style="background: #f3f3f3">{</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">PhoneSlider</span> : <span style="color:#2b91af">Slider</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">public</span> PhoneSlider()</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SizeChanged += <span style="color:#0000ff">new</span> <span style="color:#2b91af">SizeChangedEventHandler</span>(PhoneSlider_SizeChanged);</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">void</span> PhoneSlider_SizeChanged(<span style="color:#0000ff">object</span> sender, <span style="color:#2b91af">SizeChangedEventArgs</span> e)</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">if</span> (e.NewSize.Width &gt; 0 &amp;&amp; e.NewSize.Height &gt; 0)</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Rect</span> clipRect = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Rect</span>(0, 0, e.NewSize.Width, e.NewSize.Height);</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">if</span> (Orientation == <span style="color:#2b91af">Orientation</span>.Horizontal)</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clipRect.X -= 12;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clipRect.Width += 24;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">object</span> margin = Resources[<span style="color:#a31515">"PhoneHorizontalMargin"</span>];</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">if</span> (margin != <span style="color:#0000ff">null</span>)</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Margin = (<span style="color:#2b91af">Thickness</span>)margin;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">else</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clipRect.Y -= 12;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clipRect.Height += 24;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">object</span> margin = Resources[<span style="color:#a31515">"PhoneVerticalMargin"</span>];</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">if</span> (margin != <span style="color:#0000ff">null</span>)</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Margin = (<span style="color:#2b91af">Thickness</span>)margin;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">this</span>.Clip = <span style="color:#0000ff">new</span> <span style="color:#2b91af">RectangleGeometry</span>() { Rect = clipRect };</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li style="background: #f3f3f3">}</li>
</ol></div>
</div>
</div>
<p>It just has to set the margins and clip correctly, but the values depend on the value of Slider.Orientation. If your application was going to use Sliders with only one orientation, you could simplify the code-behind and the template, but you&rsquo;d still need the code-behind for the clip.</p>
<p>You can download a sample project that contains both horizontal and vertical Sliders, with the default and modified templates. Here&rsquo;s what it looks like:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/84/77/metablogapi/1854.image_54C0270F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-84-77-metablogapi/1854.image_5F00_54C0270F.png"><img height="710" width="470" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/84/77/metablogapi/5460.image_thumb_60756E41.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-84-77-metablogapi/5460.image_5F00_thumb_5F00_60756E41.png" alt="image" border="0" title="image" style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" /></a> </p>
<p>You really have to try this on an actual Phone to appreciate how hard it can be to use the default Slider. The emulator makes it easy&mdash;we have all been trained to use a relatively high-precision mouse to hit small targets on the screen, and the invisible Thumb is quite easy to hit when using the emulator and mouse.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/07/11/87/SliderApp.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-07-11-87/SliderApp.zip">SliderApp.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Panorama Tricks – Using XAML for your Background</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/panorama-tricks-using-xaml-for-your-background</link>
      <pubDate>Mon, 20 Sep 2010 11:35:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2010/09/20/panorama-tricks-using-xaml-for-your-background/</guid>
      <description><![CDATA[If you are doing Windows Phone 7 development, chances are that you are either using or have...]]></description>
      <content:encoded><![CDATA[<p>If you are doing Windows Phone 7 development, chances are that you are either using or have considered using the Panorama. To make a truly glorious Panorama application, to immerse the user in the experience, or for branding purposes, many applications pay a lot of attention to the background. The Panorama has a Background property of type Brush. Although this is most often used with an ImageBrush, it can also be a SolidColorBrush or a BradientBrush. Using gradients is not recommended, unless you are a fan of color banding. It would be nice if the ImageBrush could be used with a WriteableBitmap, but that doesn&rsquo;t work. But there is something better&hellip;</p>
<h2>Unlocking Panorama.Background to allow arbitrary content</h2>
<p>If you examine Panorama.UpdateBackground using <a target="_blank" href="https://www.red-gate.com/products/reflector/">Reflector</a>, you can see that the background ContentPresenter&rsquo;s Height is always set to the viewport&rsquo;s height. It handles a Background that is set to a SolidColorBrush by setting width of the background&rsquo;s ContentPresenter to the viewport width; if it is a GradientBrush, it sets the width to the width of the items; for ImageBrush&nbsp;it does some magic to wait for the image to be loaded, and then sets the background&rsquo;s width to the pixel width of the image. It also sets a property ominously called &ldquo;IsStatic&rdquo;. Keen observers will also be able to see why WriteableBitmaps can&rsquo;t be used as the ImageSource of your ImageBrush. But you don&rsquo;t really want that anyway, because the perf is not good, and anything you can do with a WriteableBitmap, by definition you can do with XAML.</p>
<p>If you want to be able to put arbitrary XAML in the background, you need to somehow do two things: </p>
<ol>
<li>set the width of the background&rsquo;s ContentPresenter </li>
<li>set IsStatic to false </li>
</ol>
<p>You can get this done in code, but it is a bit of a pain, and frankly, a little sketchy. Fortunately, there&rsquo;s an easier way to do this. Remember the good old days of getting stuff to go where you want it in HTML by using 1 x 1 pixel transparent GIFs? Well, I don&rsquo;t propose doing anything as old-school-hacky as that. No, this method uses a <em>modern</em> 1 x N transparent PNG (where N is the desired width of your background.) OK, I guess this is a little on the sketchy side, too, but like I said, it has the virtue of being easy.</p>
<p>The attached solution includes &ldquo;dummy.png&rdquo;, an 800 x 1 transparent PNG that I created using <a target="_blank" href="https://www.getpaint.net/">Paint.NET</a>. It is included in the project, and the build action is set to &ldquo;Resource&rdquo;. In the main page&rsquo;s XAML, the Panorama.Background is set to an ImageBrush that has dummy.png as its ImageSource. The other thing that we have to do is to re-template the Panorama, to include our new spiffy XAML background. Here&rsquo;s what the page looks like:</p>
<div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:824f98ea-b2d2-4a4b-ba94-4a31ec50bc3b" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">phone</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationPage</span> </li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Class</span><span style="color:#0000ff">="PanoramaXamlBackground.MainPage"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">="https://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">x</span><span style="color:#0000ff">="https://schemas.microsoft.com/winfx/2006/xaml"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">phone</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">shell</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">d</span><span style="color:#0000ff">="https://schemas.microsoft.com/expression/blend/2008"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">mc</span><span style="color:#0000ff">="https://schemas.openxmlformats.org/markup-compatibility/2006"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">controls</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">controlsPrimitives</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> mc</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Ignorable</span><span style="color:#0000ff">="d"</span><span style="color:#ff0000"> d</span><span style="color:#0000ff">:</span><span style="color:#ff0000">DesignWidth</span><span style="color:#0000ff">="480"</span><span style="color:#ff0000"> d</span><span style="color:#0000ff">:</span><span style="color:#ff0000">DesignHeight</span><span style="color:#0000ff">="800"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> FontFamily</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneFontFamilyNormal}</span><span style="color:#0000ff">"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> FontSize</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneFontSizeNormal}</span><span style="color:#0000ff">"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> Foreground</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneForegroundBrush}</span><span style="color:#0000ff">"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> SupportedOrientations</span><span style="color:#0000ff">="Portrait"</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">="Portrait"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> shell</span><span style="color:#0000ff">:</span><span style="color:#ff0000">SystemTray.IsVisible</span><span style="color:#0000ff">="False"&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">phone</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationPage.Resources</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ControlTemplate</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Key</span><span style="color:#0000ff">="panoramaTemplate"</span><span style="color:#ff0000"> TargetType</span><span style="color:#0000ff">="controls:Panorama"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid.RowDefinitions</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="auto"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="*"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid.RowDefinitions</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controlsPrimitives</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningBackgroundLayer</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="BackgroundLayer"</span><span style="color:#ff0000"> Grid.RowSpan</span><span style="color:#0000ff">="2"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Border</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="background"</span><span style="color:#ff0000"> CacheMode</span><span style="color:#0000ff">="BitmapCache"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#ff0000"> Background</span><span style="color:#0000ff">="Transparent"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="400"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="200"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="Blue"</span><span style="color:#ff0000"> Opacity</span><span style="color:#0000ff">=".5"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"</span><span style="color:#ff0000"> VerticalAlignment</span><span style="color:#0000ff">="Top"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="32"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="300"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="600"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="Green"</span><span style="color:#ff0000"> Opacity</span><span style="color:#0000ff">=".5"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"</span><span style="color:#ff0000"> VerticalAlignment</span><span style="color:#0000ff">="Top"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="300,128"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Rectangle</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="600"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="100"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="Red"</span><span style="color:#ff0000"> Opacity</span><span style="color:#0000ff">=".5"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"</span><span style="color:#ff0000"> VerticalAlignment</span><span style="color:#0000ff">="Top"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="200,500,0,0"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Ellipse</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="indicator"</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">="50"</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="50"</span><span style="color:#ff0000"> Fill</span><span style="color:#0000ff">="Orange"</span><span style="color:#ff0000"> Opacity</span><span style="color:#0000ff">=".5"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"</span><span style="color:#ff0000"> VerticalAlignment</span><span style="color:#0000ff">="Bottom"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="16"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Ellipse.Triggers</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">EventTrigger</span><span style="color:#ff0000"> RoutedEvent</span><span style="color:#0000ff">="Ellipse.Loaded"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">BeginStoryboard</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Storyboard</span><span style="color:#ff0000"> Storyboard.TargetName</span><span style="color:#0000ff">="indicator"</span><span style="color:#ff0000"> Storyboard.TargetProperty</span><span style="color:#0000ff">="Opacity"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">DoubleAnimation</span><span style="color:#ff0000"> To</span><span style="color:#0000ff">="0"</span><span style="color:#ff0000"> AutoReverse</span><span style="color:#0000ff">="True"</span><span style="color:#ff0000"> RepeatBehavior</span><span style="color:#0000ff">="Forever"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Storyboard</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">BeginStoryboard</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">EventTrigger</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Ellipse.Triggers</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Ellipse</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Border</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">controlsPrimitives</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningBackgroundLayer</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controlsPrimitives</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningTitleLayer</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="TitleLayer"</span><span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">="0"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"</span> <span style="color:#ff0000">Margin</span><span style="color:#0000ff">="10,-76,0,9"</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> Content</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> Title}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> ContentTemplate</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> TitleTemplate}</span><span style="color:#0000ff">"</span> </li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> FontSize</span><span style="color:#0000ff">="187"</span><span style="color:#ff0000"> FontFamily</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneFontFamilyLight}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> CacheMode</span><span style="color:#0000ff">="BitmapCache"/&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controlsPrimitives</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningLayer</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="ItemsLayer"</span><span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">="1"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ItemsPresenter</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="items"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">controlsPrimitives</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningLayer</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ControlTemplate</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">phone</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationPage.Resources</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="LayoutRoot"&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">Panorama</span><span style="color:#ff0000"> Template</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> panoramaTemplate}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Title</span><span style="color:#0000ff">="xaml background"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">Panorama.Background</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ImageBrush</span><span style="color:#ff0000"> ImageSource</span><span style="color:#0000ff">="dummy.png"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">Panorama.Background</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">="home"/&gt;</span><span style="color:#a31515"></span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">="item 1"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">="item 2"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">Panorama</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span></li>
<li style="background: #f3f3f3"><span style="color:#a31515"></span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">phone</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationPage</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</div>
</div>
<p>You can see the Panorama&rsquo;s Background being set to dummy.PNG (line 64). The new background is set in lines 29-44. Although this doesn't need it, not having any colors near the edges, you can also apply <a target="_blank" href="https://blogs.msdn.com/b/devdave/archive/2010/09/17/panorama-tricks-how-to-eliminate-blending-seams.aspx" title="a margin to prevent seaming">a margin to prevent seaming</a>. Here there is a reward for the keen observer. You will notice that there is a subtle animation on the Ellipse. Yes, this is a Panorama with an animated background. But please, if you&rsquo;re going to travel down that path, keep it <strong>subtle</strong>, and watch that frame rate counter. And beware of wrapping artifacts. The Panorama is not designed to have a dynamic background. And keep both light and dark themes in mind.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/06/51/86/PanoramaXamlBackground.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-06-51-86/PanoramaXamlBackground.zip">PanoramaXamlBackground.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Panorama Tricks – Using WrapPanel in wide PanoramaItems</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/panorama-tricks-using-wrappanel-in-wide-panoramaitems</link>
      <pubDate>Fri, 17 Sep 2010 23:57:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2010/09/17/panorama-tricks-using-wrappanel-in-wide-panoramaitems/</guid>
      <description><![CDATA[The Silverlight for Windows Phone Toolkit also includes the WrapPanel from the Silverlight Tookit....]]></description>
      <content:encoded><![CDATA[<p>The <a href="https://silverlight.codeplex.com/">Silverlight for Windows Phone Toolkit</a> also includes the WrapPanel from the Silverlight Tookit. It is ideal for displaying content in wide PanoramaItems. The sample application that ships with the Silverlight for Windows Phone Toolkit source includes an example of this.</p>
<p>Since the subject has come up a few times, here&rsquo;s how you do it:</p>
<ol>
<li>Give your PanaramaItem a horizontal orientation. </li>
<li>Make the WrapPanel the child of the PanormaItem, and set its orientation to vertical. </li>
</ol>
<p>Here&rsquo;s a snippet that does just that:</p>
<div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0119fe17-7844-44d9-9f5e-862200cebc74" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto"><ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">="vertical"</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">="Horizontal"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#008000">&lt;!-- This WrapPanel will fill columns first --&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">toolkit</span><span style="color:#0000ff">:</span><span style="color:#a31515">WrapPanel</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="verticalWrapPanel"</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">="Vertical"/&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</div>
</div>
<p>It is a little confusing, because they both have Orientation properties. The PanoramaItem&rsquo;s Orientation usage is like StackPanel&rsquo;s&mdash;the Orientation refers to the direction that is measured at infinity, or in other words, that&rsquo;s the direction that grows.</p>
<p>For WrapPanel, the semantics are different. The Orientation refers to the direction that the WrapPanel will fill first, in other words, it starts at the top left of the WrapPanel, then the next items fill in vertically until the first column is full.</p>
<p>This will look like this:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/84/77/metablogapi/7723.image_601C8D65.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-84-77-metablogapi/7723.image_5F00_601C8D65.png"><img height="405" width="247" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/84/77/metablogapi/0207.image_thumb_44978B62.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-84-77-metablogapi/0207.image_5F00_thumb_5F00_44978B62.png" alt="image" border="0" title="image" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" /></a>&nbsp;</p>
<p>This may not be the look that you desire, however. You may wish rows to be filled first, but using as few columns as possible. The first thing that you might try is to change the Orientation of the WrapPanel to Horizontal, like this:</p>
<div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a737e3b1-93d8-41e3-878a-ce14d267d699" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; overflow: auto"><ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="horizontalWrapPanelItem"</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">="horizontal"</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">="Horizontal"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#008000">&lt;!-- This WrapPanel will fill rows first, but we will use </span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">code-behind to make it take as few columns as possible --&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">toolkit</span><span style="color:#0000ff">:</span><span style="color:#a31515">WrapPanel</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="horizontalWrapPanel"</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">="Horizontal"</span><span style="color:#ff0000"> VerticalAlignment</span><span style="color:#0000ff">="Top"/&gt;</span></li>
<li><span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">controls</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</div>
<p>However, since this means that the WrapPanel will extend horizontally first (filling columns before rows) and the PanoramaItem lets its content extend horizontally indefinitely, the items all wind up in a single row. Time to break out some code.</p>
<p>Here&rsquo;s how this example makes it so that the WrapPanel lays its items out horizontally, but taking as few columns as possible, so the look is nice and full. First, here&rsquo;s what it looks like:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/84/77/metablogapi/6558.image_6F6FEF74.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-84-77-metablogapi/6558.image_5F00_6F6FEF74.png"><img height="406" width="246" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/84/77/metablogapi/4428.image_thumb_2F39D5FA.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-84-77-metablogapi/4428.image_5F00_thumb_5F00_2F39D5FA.png" alt="image" border="0" title="image" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" /></a> </p>
<p>And here&rsquo;s the guts of code-behind that does it:</p>
<div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e716d4a1-78bd-4dba-9420-3886d9274942" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#0000ff">private</span> <span style="color:#0000ff">void</span> AdjustHorizontalWrapPanelSize()</li>
<li style="background: #f3f3f3">{</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// The goal here is to configure the WrapPanel to lay the items out in rows, while</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// taking as few columns as possible. </span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">int</span> columnsRequired = <span style="color:#2b91af">Math</span>.Max(ColumnsPerPage, (<span style="color:#0000ff">int</span>) <span style="color:#2b91af">Math</span>.Ceiling((<span style="color:#0000ff">double</span>) horizontalWrapPanel.Children.Count / (<span style="color:#0000ff">double</span>) RowsPerPage));</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;horizontalWrapPanel.Width = columnsRequired * TileDimensionWithMargins;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;horizontalWrapPanel.Height = RowsPerPage * TileDimensionWithMargins;</li>
<li style="background: #f3f3f3">}</li>
</ol></div>
</div>
</div>
<p>In this case &ldquo;Page&rdquo; refers to the size of a single, vertically-oriented PanoramaItem. The attached project puts it all together.</p>
</div>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/06/43/95/PanoramaWrapPanel.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-06-43-95/PanoramaWrapPanel.zip">PanoramaWrapPanel.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Panorama Tricks – How to eliminate blending seams in the background</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/panorama-tricks-how-to-eliminate-blending-seams-in-the-background</link>
      <pubDate>Fri, 17 Sep 2010 16:16:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2010/09/17/panorama-tricks-how-to-eliminate-blending-seams-in-the-background/</guid>
      <description><![CDATA[If your Windows Phone 7 application includes a Panorama with a background, you may have seen...]]></description>
      <content:encoded><![CDATA[<p>If your Windows Phone 7 application includes a Panorama with a background, you may have seen seams&mdash;one pixel wide lines darker than the background image&rsquo;s color&mdash;where the background loops around and the right edge meets the left edge, or vice versa. This happens when background is being animated, during panning, flicking, etc., and the background doesn&rsquo;t happen to be drawn on a whole pixel boundary. </p>
<p>I had a heck of a time trying to get a screen shot of a Panorama with this artifact, since that means I&rsquo;d need to take a screen shot of the emulator while panning, during a flick, etc. (Actually, I gave up almost instantly.) I was going to draw a picture with Paint, but I think everybody can imagine what a vertical line that goes from the top to the bottom of a Panorama looks like. I bet you can even imagine it flashing while you pan. So let&rsquo;s move on.</p>
<p>The trick to getting rid of that line is to overlap the edges of the background. And the way to do <em>that</em> is to retemplate the Panorama to use some negative Margin.</p>
<p>Here&rsquo;s what that XAML looks like:</p>
<div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:44d457d8-f2df-4ec4-94c2-46948acb1842" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto"><ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">phone</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationPage</span> </li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Class</span><span style="color:#0000ff">="SeamlessPanorama.MainPage"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">="https://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">x</span><span style="color:#0000ff">="https://schemas.microsoft.com/winfx/2006/xaml"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">phone</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">shell</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">d</span><span style="color:#0000ff">="https://schemas.microsoft.com/expression/blend/2008"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">mc</span><span style="color:#0000ff">="https://schemas.openxmlformats.org/markup-compatibility/2006"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">ctl</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">ctlp</span><span style="color:#0000ff">="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> mc</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Ignorable</span><span style="color:#0000ff">="d"</span><span style="color:#ff0000"> d</span><span style="color:#0000ff">:</span><span style="color:#ff0000">DesignWidth</span><span style="color:#0000ff">="480"</span><span style="color:#ff0000"> d</span><span style="color:#0000ff">:</span><span style="color:#ff0000">DesignHeight</span><span style="color:#0000ff">="768"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> FontFamily</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneFontFamilyNormal}</span><span style="color:#0000ff">"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> FontSize</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneFontSizeNormal}</span><span style="color:#0000ff">"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> Foreground</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneForegroundBrush}</span><span style="color:#0000ff">"</span></li>
<li>&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> SupportedOrientations</span><span style="color:#0000ff">="Portrait"</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">="Portrait"</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> shell</span><span style="color:#0000ff">:</span><span style="color:#ff0000">SystemTray.IsVisible</span><span style="color:#0000ff">="True"&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">phone</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationPage.Resources</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ControlTemplate</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Key</span><span style="color:#0000ff">="panoramaTemplate"</span><span style="color:#ff0000"> TargetType</span><span style="color:#0000ff">="ctl:Panorama"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid.RowDefinitions</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="auto"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">="*"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid.RowDefinitions</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#008000">&lt;!-- The use of the margin on the Border will prevent rendering artifacts (dark vertical lines). --&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ctlp</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningBackgroundLayer</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="BackgroundLayer"</span><span style="color:#ff0000"> Grid.RowSpan</span><span style="color:#0000ff">="2"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Border</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="background"</span><span style="color:#ff0000"> Background</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> Background}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> CacheMode</span><span style="color:#0000ff">="BitmapCache"</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">="-1,0"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ctlp</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningBackgroundLayer</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ctlp</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningTitleLayer</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="TitleLayer"</span><span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">="0"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"</span> <span style="color:#ff0000">Margin</span><span style="color:#0000ff">="10,-76,0,9"</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> Content</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> Title}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> ContentTemplate</span><span style="color:#0000ff">="{</span><span style="color:#a31515">TemplateBinding</span><span style="color:#ff0000"> TitleTemplate}</span><span style="color:#0000ff">"</span> </li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#ff0000"> FontSize</span><span style="color:#0000ff">="187"</span><span style="color:#ff0000"> FontFamily</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> PhoneFontFamilyLight}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> CacheMode</span><span style="color:#0000ff">="BitmapCache"/&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ctlp</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningLayer</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="ItemsLayer"</span><span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">="1"</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">="Left"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ItemsPresenter</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="items"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ctlp</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanningLayer</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ControlTemplate</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">phone</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationPage.Resources</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">="LayoutRoot"&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ctl</span><span style="color:#0000ff">:</span><span style="color:#a31515">Panorama</span><span style="color:#ff0000"> Template</span><span style="color:#0000ff">="{</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> panoramaTemplate}</span><span style="color:#0000ff">"</span><span style="color:#ff0000"> Title</span><span style="color:#0000ff">="background image"&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ctl</span><span style="color:#0000ff">:</span><span style="color:#a31515">Panorama.Background</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ImageBrush</span><span style="color:#ff0000"> ImageSource</span><span style="color:#0000ff">="BK.jpg"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ctl</span><span style="color:#0000ff">:</span><span style="color:#a31515">Panorama.Background</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ctl</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">="item 0"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ctl</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">="item 1"/&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ctl</span><span style="color:#0000ff">:</span><span style="color:#a31515">PanoramaItem</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">="item 2"/&gt;</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ctl</span><span style="color:#0000ff">:</span><span style="color:#a31515">Panorama</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">phone</span><span style="color:#0000ff">:</span><span style="color:#a31515">PhoneApplicationPage</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</div>
</div>
<p>Notice the Margin added to the Border named &ldquo;background&rdquo; (line 29). That&rsquo;s the only change in the Panorama template.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/06/43/00/SeamlessPanorama.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-06-43-00/SeamlessPanorama.zip">SeamlessPanorama.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Customizing a ToolTip</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/customizing-a-tooltip</link>
      <pubDate>Sat, 18 Oct 2008 14:06:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2008/10/18/customizing-a-tooltip/</guid>
      <description><![CDATA[(Special thanks to Andre Michaud and Mike Russell who showed me how to do this.)
ToolTips are quite...]]></description>
      <content:encoded><![CDATA[<P><EM>(Special thanks to Andre Michaud and Mike Russell who showed me how to do this.)</EM></P>
<P>ToolTips are quite useful for for displaying helpful information when the user hovers over a control. The way that ToolTips are usually used is by setting the ToolTipService.ToolTip property to some text. This will display the text in a rather bland rectangle, without wrapping. Here are some ways to make your ToolTips more useful and nicer looking.</P>
<P>ToolTip are typically defined like this:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">TextBox </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="20" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100" </SPAN><SPAN style="COLOR: red">ToolTipService.ToolTip</SPAN><SPAN style="COLOR: blue">="Some helpful text"/&gt;
</SPAN></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>
<P>The standard ToolTip looks like this:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_6.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_6.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_6.png"><IMG border=0 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_2.png" width=213 height=67 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_2.png"></A> </P>
<P>ToolTipService.ToolTip is an attached property that defines the Content of the ToolTip. It will get put into a ContentPresenter. In this case, since it is a string, the ContentPresenter will create a TextBlock for it. The TextBlock does not wrap, however, so if you have too much text, it just looks silly. But knowing that the ToolTipService.ToolTip defines the Content of the ToolTip, you can add your own UIElements, and not rely on the ContentPresenter to do it for you.</P>
<P>Here's some XAML that makes a ToolTip that can wrap text. It also modifies some of the font properties:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">TextBox </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="20" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ToolTipService.ToolTip</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">MaxWidth</SPAN><SPAN style="COLOR: blue">="150" 
                   </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="This is a longer string of text. It is even in a different font. Aren't ToolTips exciting?" 
                   </SPAN><SPAN style="COLOR: red">FontFamily</SPAN><SPAN style="COLOR: blue">="Georgia" </SPAN><SPAN style="COLOR: red">FontSize</SPAN><SPAN style="COLOR: blue">="14" </SPAN><SPAN style="COLOR: red">TextWrapping</SPAN><SPAN style="COLOR: blue">="Wrap"/&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">ToolTipService.ToolTip</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">TextBox</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>
<P>This will show a ToolTip that is a little more interesting. </P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_8.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_8.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_8.png"><IMG border=0 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_3.png" width=221 height=107 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_3.png"></A> </P>
<P>Because you can set the Content property to anything that you want, you can do this:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">TextBox </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="20" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ToolTipService.ToolTip</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="CadetBlue"&gt;
                &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Some sort of title" </SPAN><SPAN style="COLOR: red">TextAlignment</SPAN><SPAN style="COLOR: blue">="Center"/&gt;
            &lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">MaxWidth</SPAN><SPAN style="COLOR: blue">="150" 
               </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="This is a longer string of text. It is even in a different font. Aren't ToolTips exciting?" 
               </SPAN><SPAN style="COLOR: red">FontFamily</SPAN><SPAN style="COLOR: blue">="Georgia" </SPAN><SPAN style="COLOR: red">FontSize</SPAN><SPAN style="COLOR: blue">="14" </SPAN><SPAN style="COLOR: red">TextWrapping</SPAN><SPAN style="COLOR: blue">="Wrap"/&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">ToolTipService.ToolTip</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">TextBox</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>This looks like this: 
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_10.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_10.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_10.png"><IMG border=0 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_4.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_4.png" width=211 height=117 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_4.png"></A> </P>
<P>Note that the Content of the ToolTip can't be interacted with, so you can't put a Button (for example) in the ToolTip and expect the user to be able to interact with it, or for it to get the focus.</P>
<P>But this is still kind of a boring ToolTip: a plain-looking rectangle. But it is possible to make that look nicer, too. </P>
<P>You can retemplate the ToolTip to give it new visuals. Here's an example:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_12.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_12.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_12.png"><IMG border=0 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_5.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_5.png" width=233 height=113 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_5.png"></A> </P>
<P>The XAML is below. You'll note that I rearranged things a little bit: I put a ToolTip element under the ToolTipService.ToolTip element. I made the ToolTip.Content just a simple TextBlock again, and set the ToolTip's Template property to a fancy new Template which is defined in the page resources.</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">UserControl </SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">Class</SPAN><SPAN style="COLOR: blue">="ToolTipTest.Page"
    </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">="https://schemas.microsoft.com/winfx/2006/xaml" 
    </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="400" </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="300"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">UserControl.Resources</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">ControlTemplate </SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">Key</SPAN><SPAN style="COLOR: blue">="ToolTipTemplate"&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">BorderBrush</SPAN><SPAN style="COLOR: blue">="Black" </SPAN><SPAN style="COLOR: red">BorderThickness</SPAN><SPAN style="COLOR: blue">="4" </SPAN><SPAN style="COLOR: red">CornerRadius</SPAN><SPAN style="COLOR: blue">="8" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="PaleGoldenrod" </SPAN><SPAN style="COLOR: red">MaxWidth</SPAN><SPAN style="COLOR: blue">="200"&gt;
                &lt;</SPAN><SPAN style="COLOR: #a31515">Grid</SPAN><SPAN style="COLOR: blue">&gt;
                    &lt;</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
                        &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="auto"/&gt;
                        &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="*"/&gt;
                    &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
                    &lt;</SPAN><SPAN style="COLOR: #a31515">Grid </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"&gt;
                        &lt;</SPAN><SPAN style="COLOR: #a31515">Ellipse </SPAN><SPAN style="COLOR: red">Fill</SPAN><SPAN style="COLOR: blue">="Black" </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="52" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="52"/&gt;
                        &lt;</SPAN><SPAN style="COLOR: #a31515">Ellipse </SPAN><SPAN style="COLOR: red">Stroke</SPAN><SPAN style="COLOR: blue">="White" </SPAN><SPAN style="COLOR: red">StrokeThickness</SPAN><SPAN style="COLOR: blue">="4" </SPAN><SPAN style="COLOR: red">Fill</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="50" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="50"/&gt;
                        &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="i" </SPAN><SPAN style="COLOR: red">FontStyle</SPAN><SPAN style="COLOR: blue">="italic" </SPAN><SPAN style="COLOR: red">FontSize</SPAN><SPAN style="COLOR: blue">="40" </SPAN><SPAN style="COLOR: red">FontFamily</SPAN><SPAN style="COLOR: blue">="Georgia" 
                                               </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">Foreground</SPAN><SPAN style="COLOR: blue">="White"/&gt;

                    &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid</SPAN><SPAN style="COLOR: blue">&gt;
                    &lt;</SPAN><SPAN style="COLOR: #a31515">ContentPresenter </SPAN><SPAN style="COLOR: red">Grid.Column</SPAN><SPAN style="COLOR: blue">="1"
                                        </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="{</SPAN><SPAN style="COLOR: #a31515">TemplateBinding </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">}"
                                        </SPAN><SPAN style="COLOR: red">ContentTemplate</SPAN><SPAN style="COLOR: blue">="{</SPAN><SPAN style="COLOR: #a31515">TemplateBinding </SPAN><SPAN style="COLOR: red">ContentTemplate</SPAN><SPAN style="COLOR: blue">}"
                                        </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="{</SPAN><SPAN style="COLOR: #a31515">TemplateBinding </SPAN><SPAN style="COLOR: red">Padding</SPAN><SPAN style="COLOR: blue">}" 
                                        </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center"/&gt;
                &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid</SPAN><SPAN style="COLOR: blue">&gt;
            &lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">ControlTemplate</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">UserControl.Resources</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Grid </SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">Name</SPAN><SPAN style="COLOR: blue">="LayoutRoot" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Gainsboro"&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">TextBox </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="20" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">ToolTipService.ToolTip</SPAN><SPAN style="COLOR: blue">&gt;
                &lt;</SPAN><SPAN style="COLOR: #a31515">ToolTip </SPAN><SPAN style="COLOR: red">Template</SPAN><SPAN style="COLOR: blue">="{</SPAN><SPAN style="COLOR: #a31515">StaticResource </SPAN><SPAN style="COLOR: red">ToolTipTemplate</SPAN><SPAN style="COLOR: blue">}"&gt;
                    &lt;</SPAN><SPAN style="COLOR: #a31515">ToolTip.Content</SPAN><SPAN style="COLOR: blue">&gt;
                        &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock 
                           </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="This is a longer string of text." 
                           </SPAN><SPAN style="COLOR: red">FontFamily</SPAN><SPAN style="COLOR: blue">="Georgia" </SPAN><SPAN style="COLOR: red">FontSize</SPAN><SPAN style="COLOR: blue">="14" </SPAN><SPAN style="COLOR: red">TextWrapping</SPAN><SPAN style="COLOR: blue">="Wrap"/&gt;
                    &lt;/</SPAN><SPAN style="COLOR: #a31515">ToolTip.Content</SPAN><SPAN style="COLOR: blue">&gt;
                &lt;/</SPAN><SPAN style="COLOR: #a31515">ToolTip</SPAN><SPAN style="COLOR: blue">&gt;
            &lt;/</SPAN><SPAN style="COLOR: #a31515">ToolTipService.ToolTip</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">TextBox</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">UserControl</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>]]></content:encoded>
    </item>
    <item>
      <title>Control Lifecycle</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/control-lifecycle</link>
      <pubDate>Sat, 11 Oct 2008 13:28:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2008/10/11/control-lifecycle/</guid>
      <description><![CDATA[What happens when you create a Control? When do overrides get called and events get raised? When do...]]></description>
      <content:encoded><![CDATA[<P>What happens when you create a Control? When do overrides get called and events get raised? When do styles get applied?</P>
<P>In response to <A href="https://silverlight.net/forums/t/34070.aspx" mce_href="https://silverlight.net/forums/t/34070.aspx">this thread</A> on silverlight.net, I've whipped this simple table up. There are some subtle differences between instantiating a control in XAML, and instantiating it via code that I've called out, but most of the lifecycle is the same.</P>
<TABLE border=1 cellSpacing=0 cellPadding=2 width=540>
<TBODY>
<TR>
<TD vAlign=top width=131><STRONG>Action</STRONG></TD>
<TD vAlign=top width=205><STRONG>Control instantiated in XAML</STRONG></TD>
<TD vAlign=top width=202><STRONG>Control instantiated in code</STRONG></TD></TR>
<TR>
<TD vAlign=top width=130>Control ctor</TD>
<TD vAlign=top width=202>As soon as begin tag is parsed. </TD>
<TD vAlign=top width=202>When you call it.</TD></TR>
<TR>
<TD vAlign=top width=130>Explicit Style applied</TD>
<TD vAlign=top width=199>If the Style property is set in XAML, it will be applied as soon as the end tag is parsed.</TD>
<TD vAlign=top width=202>As soon as Style property is set.</TD></TR>
<TR>
<TD vAlign=top width=129>Built-in Style (from generic.xaml) applied</TD>
<TD vAlign=top width=198>As soon as the end tag is parsed, after the explicit Style (if any) has been applied. Will not override explicit Style.</TD>
<TD vAlign=top width=202>When the control enters the tree. Will not override explicit Style.</TD></TR>
<TR>
<TD vAlign=top width=128>Properties set</TD>
<TD vAlign=top width=197>When the attributes are parsed.</TD>
<TD vAlign=top width=202>When you set them.</TD></TR>
<TR>
<TD vAlign=top width=128>Loaded event</TD>
<TD vAlign=top width=196>Posted when the element is been added to the tree. Fired before the next frame. Happens before layout.</TD>
<TD vAlign=top width=202>Same.</TD></TR>
<TR>
<TD vAlign=top width=128>Template applied (i.e. control's visual are created from the Template)</TD>
<TD vAlign=top width=195>In the Measure pass of layout. The Template property will be applied if the control has no visual tree. The control starts life with no visual tree, and the visual tree will be cleared when the Template property is set. You can also call ApplyTemplate yourself.</TD>
<TD vAlign=top width=202>Same.</TD></TR>
<TR>
<TD vAlign=top width=129>OnApplyTemplate called</TD>
<TD vAlign=top width=194>Whenever the Template is applied. It is not necessary to call the base OnApplyTemplate for the Template to be applied, but inherited types might be relying on it for their implementations.</TD>
<TD vAlign=top width=202>Same.</TD></TR>
<TR>
<TD vAlign=top width=129>Visuals first available</TD>
<TD vAlign=top width=194>In OnApplyTemplate. Use GetTemplateChild.</TD>
<TD vAlign=top width=202>Same.</TD></TR>
<TR>
<TD vAlign=top width=129>MeasureOverride called</TD>
<TD vAlign=top width=198>In the Measure pass of layout. If the Template was expanded during this Measure pass, MeasureOverride will be called after the Template has been expanded.</TD>
<TD vAlign=top width=202>Same.</TD></TR>
<TR>
<TD vAlign=top width=129>ArrangeOverride called</TD>
<TD vAlign=top width=198>In the Arrange pass of layout, which occurs after the Measure pass.</TD>
<TD vAlign=top width=202>Same.</TD></TR>
<TR>
<TD vAlign=top width=129>SizeChanged event</TD>
<TD vAlign=top width=198>After the Measure and Arrange passes have completed.</TD>
<TD vAlign=top width=202>Same.</TD></TR>
<TR>
<TD vAlign=top width=129>LayoutUpdated event</TD>
<TD vAlign=top width=198>After SizeChanged events have fired.</TD>
<TD vAlign=top width=202>Same.</TD></TR></TBODY></TABLE>]]></content:encoded>
    </item>
    <item>
      <title>Retemplating a Standard Control (Including VisualStateManager Stuff)</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/retemplating-a-standard-control-including-visualstatemanager-stuff</link>
      <pubDate>Sun, 27 Jul 2008 13:16:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2008/07/27/retemplating-a-standard-control-including-visualstatemanager-stuff/</guid>
      <description><![CDATA[This example demonstrates how to give a Button new visuals and visual state by re-templating. It...]]></description>
      <content:encoded><![CDATA[<p><em>This example demonstrates how to give a Button new visuals and visual state by re-templating. It also includes what to do with all of the existing VisualStateManager stuff, but first it discusses various ways of modifying existing controls.</em></p>  <p>There are a few different ways of modifying an existing Control, with varying degrees of depth and difficulty. Let's take a quick look at them.</p>  <p><strong>Simple tweaks to a few controls</strong></p>  <p>It is possible to modify the properties of a control to change its appearance. You will be constrained by the existing visual design, but you will be able to tweak things a bit. This is as simple as changing the Background and font properties on a Button:</p>  <pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Button </span><span style="color: red">Content</span><span style="color: blue">=&quot;Button&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Green&quot; </span><span style="color: red">FontFamily</span><span style="color: blue">=&quot;Verdana&quot; </span><span style="color: red">FontSize</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;30&quot;/&gt;</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_2.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_2.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_2.png"><img height="31" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb.png" width="100" border="0" mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb.png" /></a> </p>

<p>This is fine if you don't have to do it very often. But imagine if you have set the FontFamily and FontSize of all of the Buttons on your page, and you want to change them. It would be nice not to have to change them everywhere.</p>

<p><strong>Common value for a property used in multiple controls</strong></p>

<p>You can use application-wide values to centralize the control of your common parameters. One way to do that is to use resources. I have added the &quot;commonFontSize&quot; resource to my application's Resources section:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Application </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot; 
             </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">sys</span><span style="color: blue">=&quot;clr-namespace:System;assembly=mscorlib&quot;
             </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;RetemplatedButtonApp.App&quot;&gt;
    &lt;</span><span style="color: #a31515">Application.Resources</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">sys</span><span style="color: blue">:</span><span style="color: #a31515">Double </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;commonFontSize&quot;&gt;</span><span style="color: #a31515">20</span><span style="color: blue">&lt;/</span><span style="color: #a31515">sys</span><span style="color: blue">:</span><span style="color: #a31515">Double</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">Application.Resources</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Application</span><span style="color: blue">&gt;</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>The FontSize property is of type Double, so that's what I've created. I can use it like this:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Button </span><span style="color: red">Content</span><span style="color: blue">=&quot;Button&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Green&quot; </span><span style="color: red">FontFamily</span><span style="color: blue">=&quot;Verdana&quot; </span><span style="color: red">FontSize</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">commonFontSize</span><span style="color: blue">}&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;30&quot;/&gt;</span></pre>

<p><a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>The Button will look the same. The StaticResource reference will look for a resource named &quot;commonFontSize&quot; and attempt to set the FontSize property to it. Notice how the &quot;sys&quot; xmlns prefix was added so that an object of type Double could be created.</p>

<p><strong>Common values for lots of properties on lots of controls</strong></p>

<p>Let's say that you want all of the Buttons in your app to have the same look, and there are lots of properties that you want to set. Setting them all to their values is a maintenance nightmare, and even using resources to centralize the actual values is painful, because you have to set a bunch of properties on each Button.</p>

<p>One way to make this easy is to use Styles. This centralizes not only the values but setting the properties. Here's an example of a Style that can be applied to Borders:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Application </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot; 
</span><span style="color: blue">             </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;RetemplatedButtonApp.App&quot;&gt;
    &lt;</span><span style="color: #a31515">Application.Resources</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Style </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;commonBorderStyle&quot; </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;Border&quot;&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;Margin&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;2&quot;/&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;BorderThickness&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;4&quot;/&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;CornerRadius&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;4&quot;/&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;BorderBrush&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;Black&quot;/&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;Background&quot;&gt;
                &lt;</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">&gt;
                    &lt;</span><span style="color: #a31515">LinearGradientBrush </span><span style="color: red">StartPoint</span><span style="color: blue">=&quot;0.7,0&quot; </span><span style="color: red">EndPoint</span><span style="color: blue">=&quot;0.7,1&quot;&gt;
                        &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;White&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;0&quot; /&gt;
                        &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;Red&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;0.35&quot; /&gt;
                        &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;Blue&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;0.35&quot; /&gt;
                        &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;White&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;1&quot; /&gt;
                    &lt;/</span><span style="color: #a31515">LinearGradientBrush</span><span style="color: blue">&gt;
                &lt;/</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">&gt;
            &lt;/</span><span style="color: #a31515">Setter</span><span style="color: blue">&gt;
        &lt;/</span><span style="color: #a31515">Style</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">Application.Resources</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Application</span><span style="color: blue">&gt;
</span></pre>

<p>To use this style, it must be set in each Border:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Border </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">commonBorderStyle</span><span style="color: blue">}&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;50&quot;/&gt;</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>This produces this Border that is so lovely that it will undoubtedly soon be seen in all of the coolest Silverlight apps. Well, maybe not, but it was a useful example.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_4.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_4.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_4.png"><img height="51" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_1.png" width="100" border="0" mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_1.png" /></a> </p>

<p>Note that for properties that have types that can be set with a simple string value converter, the Value is set as an attribute. For other properties, the property element syntax can be used. The Background property is an example of this, because a LinearGradientBrush can't be defined with a string, the way a SolidColorBrush can be (see the BorderBrush property in just above the Background.) </p>

<p>Your Style could also use Resources:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Application </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot; 
</span><span style="color: blue">             </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;RetemplatedButtonApp.App&quot;&gt;
    &lt;</span><span style="color: #a31515">Application.Resources</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">LinearGradientBrush </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;bkBrush&quot; </span><span style="color: red">StartPoint</span><span style="color: blue">=&quot;0.7,0&quot; </span><span style="color: red">EndPoint</span><span style="color: blue">=&quot;0.7,1&quot;&gt;
            &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;White&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;0&quot; /&gt;
            &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;Red&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;0.35&quot; /&gt;
            &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;Blue&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;0.35&quot; /&gt;
            &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;White&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;1&quot; /&gt;
        &lt;/</span><span style="color: #a31515">LinearGradientBrush</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Style </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;commonBorderStyle&quot; </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;Border&quot;&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;Margin&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;2&quot;/&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;BorderThickness&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;4&quot;/&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;CornerRadius&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;4&quot;/&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;BorderBrush&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;Black&quot;/&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;Background&quot; </span><span style="color: red">Value</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">bkBrush</span><span style="color: blue">}&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Style</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">Application.Resources</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Application</span><span style="color: blue">&gt;
</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p><strong>Subclassing a control</strong></p>

<p>It is easy to subclass controls in Silverlight. Let's say that you want to keep a control the way it is, but add some additional PME (properties, methods and events) to it. For example, if you wanted to associate some data with a RadioButton, that was different from its Content, you could just use the Tag property. But if you wanted strongly-typed data, you could some properties.</p>

<p>Here's the code for a simple RadioButton subclass:</p>

<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Windows;
<span style="color: blue">using </span>System.Windows.Controls;

<span style="color: blue">namespace </span>RetemplatedButtonApp
{
    <span style="color: blue">public class </span><span style="color: #2b91af">MyRadioButton </span>: <span style="color: #2b91af">RadioButton
    </span>{
        <span style="color: blue">public </span>MyRadioButton()
        {
            FontFamily = <span style="color: blue">new </span>System.Windows.Media.<span style="color: #2b91af">FontFamily</span>(<span style="color: #a31515">&quot;Verdana&quot;</span>);
            FontSize = 20;
        }

        <span style="color: blue">public int </span>Count { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
    }
}</pre>

<p><a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>Note that this example sets some properties in the constructor. This is another way to set the properties of your elements, but if all you want to do is set some properties the same, styling is a better option. When you set properties like this, they can't be styled, because a locally-set value will override a styled value.</p>

<p>To use this in XAML, you have to add an xmlns prefix for the namespace, and then use that prefix to instantiate the element:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">UserControl </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;RetemplatedButtonApp.Page&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot; 
</span><span style="color: blue">    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">local</span><span style="color: blue">=&quot;clr-namespace:RetemplatedButtonApp&quot;&gt;
</span><span style="color: blue">    &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LayoutRoot&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;White&quot;&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">CornerRadius</span><span style="color: blue">=&quot;8&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">Padding</span><span style="color: blue">=&quot;8&quot;&gt;
            &lt;</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;
                &lt;</span><span style="color: #a31515">local</span><span style="color: blue">:</span><span style="color: #a31515">MyRadioButton </span><span style="color: red">Content</span><span style="color: blue">=&quot;Once&quot; </span><span style="color: red">Count</span><span style="color: blue">=&quot;1&quot;/&gt;
                &lt;</span><span style="color: #a31515">local</span><span style="color: blue">:</span><span style="color: #a31515">MyRadioButton </span><span style="color: red">Content</span><span style="color: blue">=&quot;Twice&quot; </span><span style="color: red">Count</span><span style="color: blue">=&quot;2&quot;/&gt;
                &lt;</span><span style="color: #a31515">local</span><span style="color: blue">:</span><span style="color: #a31515">MyRadioButton </span><span style="color: red">Content</span><span style="color: blue">=&quot;Three times&quot; </span><span style="color: red">Count</span><span style="color: blue">=&quot;3&quot;/&gt;
            &lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
</span><span style="color: green">    </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">UserControl</span><span style="color: blue">&gt;
</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>This produces a Border with custom RadioButtons like this:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_8.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_8.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_8.png"><img height="120" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_3.png" width="164" border="0" mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_3.png" /></a> </p>

<p><strong>Subclassing with re-templating</strong></p>

<p>The most complete overhaul of a control is to subclass it and re-template it. The re-templating is generally done by adding a generic.xaml file to your project, and putting a new default style in it. You will also need to define a DefaultStyleKey in your ctor. I won't do a full example of this, but here are the steps to ensure that your control will be templated with your new visuals. Note that putting a Style and ControlTemplate in generic.xaml doesn't do you any good unless you also subclass. This topic deserves a post by itself, but briefly, here are the steps:</p>

<ol>
  <li>Create the file generic.xaml in your project. </li>

  <li>Make sure that its Build Action is set to &quot;Resource&quot;. Nothing else will work. </li>

  <li>The root element of generic.xaml is a ResourceDictionary. It should have xmlns prefixes for all of the namespaces of the controls you are subclassing and retemplating. </li>

  <li>The children of the ResourceDictionary are Styles. Make sure that there is a Style with a TargetType set to the type of your subclassed control. You'll have to put the appropriate xmlns prefix on the type. </li>

  <li>One of the Setters in the Style should be a ControlTemplate. You'll have to set the TargetType on that, too. </li>

  <li>In your subclassed control's ctor, set the DefaultStyleKey to your subclassed type, otherwise it will get the built in style from the base class.</li>
</ol>

<p><strong>Re-templating without subclassing</strong></p>

<p>If you want to overhaul the visuals of a control, and give it a new appearance when it changes state, you can retemplate without subclassing. In this example, we'll build a new ControlTemplate for a button. I want a bold Button with a circular border that I can put Paths into. I also want it to grow when the mouse is over it. But in all other respects, I want it to be an ordinary Button. This is how I envision it in use, as the button in the upper-right:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_10.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_10.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_10.png"><img height="45" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_4.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_4.png" width="105" border="0" mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_4.png" /></a> </p>

<p>The first thing that I will do is create a project, and put a Button in it. Here's what the XAML will start off like:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">UserControl </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;EllipseButton.Page&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot;&gt;
    &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LayoutRoot&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;White&quot;&gt;
        &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Width</span><span style="color: blue">=&quot;40&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;40&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">UserControl</span><span style="color: blue">&gt;
</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>It doesn't look very elliptical yet:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_12.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_12.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_12.png"><img height="40" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_5.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_5.png" width="40" border="0" mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_5.png" /></a> </p>

<p>The next thing to do is get the built-in Style from generic.xaml. I used <a href="https://www.aisto.com/roeder/dotnet/" mce_href="https://www.aisto.com/roeder/dotnet/">Reflector</a> [note: this link was dead when I tried it, but hopefully it is a temporary glitch], but David Anson also has a <a href="https://blogs.msdn.com/delay/archive/2008/07/20/maintaining-access-to-silverlight-2-s-generic-xaml-resources-silverlightdefaultstylebrowser-updated-for-build-2-0-30523-8-and-beyond.aspx" mce_href="https://blogs.msdn.com/delay/archive/2008/07/20/maintaining-access-to-silverlight-2-s-generic-xaml-resources-silverlightdefaultstylebrowser-updated-for-build-2-0-30523-8-and-beyond.aspx">utility</a> that you can use. Take the built-in style for your control, and add it to your XAML in your page's Resources. Make your existing Button use the new Style. I also added the xmlns prefix for &quot;vsm&quot;. I'm omitting the contents of the Style of the template because it is pretty long, but here's the rest of it:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">UserControl </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;EllipseButton.Page&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">vsm</span><span style="color: blue">=&quot;clr-namespace:System.Windows;assembly=System.Windows&quot;&gt;
    &lt;</span><span style="color: #a31515">UserControl.Resources</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Style </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;EllipseButtonStyle&quot; </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;Button&quot;&gt;<br />            </span><span style="color: green">&lt;!-- contents not shown --&gt;</span><span style="color: blue">
</span><span style="color: blue">        &lt;/</span><span style="color: #a31515">Style</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">UserControl.Resources</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LayoutRoot&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;White&quot;&gt;
        &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">EllipseButtonStyle</span><span style="color: blue">}&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;40&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;40&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">UserControl</span><span style="color: blue">&gt;
</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>If you have done your typing and pasting correctly, you should get the exact same appearance when you run your app.</p>

<p>The next thing to do is to get rid of just about everything except for the root Grid, the VisualStateManager elements (get rid of the Storyboards) and the ContentPresenter. Your XAML will now look like this:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">UserControl </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;EllipseButton.Page&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">vsm</span><span style="color: blue">=&quot;clr-namespace:System.Windows;assembly=System.Windows&quot;&gt;
    &lt;</span><span style="color: #a31515">UserControl.Resources</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Style </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;EllipseButtonStyle&quot; </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;Button&quot;&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;Template&quot;&gt;
                &lt;</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">&gt;
                    &lt;</span><span style="color: #a31515">ControlTemplate </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;Button&quot;&gt;
                        &lt;</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
                            &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateManager.VisualStateGroups</span><span style="color: blue">&gt;
                                &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;CommonStates&quot;&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup.Transitions</span><span style="color: blue">&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup.Transitions</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Normal&quot; /&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;MouseOver&quot;&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Pressed&quot;&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Disabled&quot;&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup</span><span style="color: blue">&gt;
                                &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;FocusStates&quot;&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Focused&quot;&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Unfocused&quot;&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup</span><span style="color: blue">&gt;
                            &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateManager.VisualStateGroups</span><span style="color: blue">&gt;

                            &lt;</span><span style="color: #a31515">ContentPresenter
                                  </span><span style="color: red">Content</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Content</span><span style="color: blue">}&quot;
                                  </span><span style="color: red">ContentTemplate</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">ContentTemplate</span><span style="color: blue">}&quot;
                                  </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">}&quot;
                                  </span><span style="color: red">Padding</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Padding</span><span style="color: blue">}&quot;
                                  </span><span style="color: red">TextAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextAlignment</span><span style="color: blue">}&quot;
                                  </span><span style="color: red">TextDecorations</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextDecorations</span><span style="color: blue">}&quot;
                                  </span><span style="color: red">TextWrapping</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextWrapping</span><span style="color: blue">}&quot;
                                  </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">}&quot;
                                  </span><span style="color: red">Margin</span><span style="color: blue">=&quot;4,5,4,4&quot;/&gt;
                        &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
                    &lt;/</span><span style="color: #a31515">ControlTemplate</span><span style="color: blue">&gt;
                &lt;/</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">&gt;
            &lt;/</span><span style="color: #a31515">Setter</span><span style="color: blue">&gt;
        &lt;/</span><span style="color: #a31515">Style</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">UserControl.Resources</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LayoutRoot&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;White&quot;&gt;
        &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">EllipseButtonStyle</span><span style="color: blue">}&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;40&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;40&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">UserControl</span><span style="color: blue">&gt;
</span></pre>

<p>If you try to run your app now, you will get nothing on the screen, although if you give the Button some Content, you will see it. This isn't a very useful Button. If you click on the Content, the Click event will be raised, but the Button itself has no visuals, and it there is no visual response to user actions.</p>

<p>Let's leave the VisualStateManager stuff alone for right now, since we really need to do the visuals first. We'll add this Ellipse just before the ContentPresenter, so it will be drawn behind the ContentPresenter:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Ellipse </span><span style="color: red">Fill</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Background</span><span style="color: blue">}&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Foreground</span><span style="color: blue">}&quot; </span><span style="color: red">StrokeThickness</span><span style="color: blue">=&quot;2&quot;/&gt;
</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>Let's also add an Ellipse after the ContentPresenter, so that it will be drawn on top. This will be used to wash the colors out when the Button is disabled, but we'll give it an Opacity of 0 for now:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Ellipse </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;disabledEllipse&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;White&quot; </span><span style="color: red">Opacity</span><span style="color: blue">=&quot;0&quot;/&gt;</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>Let's also change the Button to give it some Content and a Background color:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Button </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">EllipseButtonStyle</span><span style="color: blue">}&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;40&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;40&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;Hello&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;#4b2&quot;/&gt;</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>If you don't want to hardcode values (such as colors) in your control, it is important that you use TemplateBindings wherever it is appropriate. In the Ellipse that we added, I've made sure that its Stroke and Fill will be set to whatever values are set on the control. Controls with hardcoded values are not as flexible and useful as controls that use TemplateBindings and properties to control appearance and/or behavior. If I wanted to be consistent with that principle, I might subclass Button so that I could also bind the Ellipse's StrokeThickness, but I don't want to subclass for this example. </p>

<p>Here's what it looks like now:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_14.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_14.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_14.png"><img height="41" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_6.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_6.png" width="41" border="0" mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_6.png" /></a> </p>

<p>Now we're looking elliptical. You can see the Button, and it raises the Click event when you click on it, but it always looks the same. Time to start plugging StoryBoards into the VisualStates.</p>

<p>If you look at the VisualStateGroups and VisualStates, you can see how Button is organized. Internally, Button keeps track of a bunch of state, and then figures out which VisualState in each VisualStateGroup it should be in, and calls VisualStateManager.GoToState for each state. By putting Storyboards in the VisualStates, we can make this Button start to react to input.</p>

<p>The first VisualStateGroup is the &quot;CommonStates&quot; group; the first state in that is &quot;Normal&quot;. By convention, the &quot;Normal&quot; is what the control will look like if it is enabled but is not being interacted with by the user. Its appearance is assumed to be the appearance as specified by the template XAML, so we have already defined the &quot;Normal&quot; state. Because of the way VisualStateManager uses the animation system, we don't need to specify any Storyboards for the &quot;Normal&quot; state.</p>

<p>The VisualStates Storyboards represent the steady state animations of the particular state. Usually, there aren't any steady state animations once a control is in a particular state, so all of the animations have their Duration properties set to 0. We want the control to expand when the user moves the mouse over it, so add a ScaleTransform to the root Grid, set the Grid's RenderTransformOrigin to .5,.5:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Grid </span><span style="color: red">RenderTransformOrigin</span><span style="color: blue">=&quot;.5,.5&quot;&gt;
    &lt;</span><span style="color: #a31515">Grid.RenderTransform</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">ScaleTransform </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;zoom&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Grid.RenderTransform</span><span style="color: blue">&gt;
</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>and add a StoryBoard to the &quot;MouseOver&quot; state:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;MouseOver&quot;&gt;
    &lt;</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;zoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleX&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
        &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;zoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleY&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;</span></pre>

<p><a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>Now, when you run it, when you move the mouse over the button, it grows. When you click on it, it goes back down to its original size. This works really well if you don't move the mouse between pressing the button and releasing it, you can just keep clicking and everything is fine, but things get finicky if you move the mouse (after mouse down but before mouse up) into the region that is in the expanded size, but outside of the original size. You can't just keep clicking. That might be OK, but let's try to make things a bit nicer. What we want to do is to define the &quot;Pressed&quot; state. The Storyboards for the individual VisualStates should have no relation to each other. In other words, all other states can be ignored, and all you have to do is to add animations to set the values relative to the XAML in the template (which as you may remember is considered to be the &quot;Normal&quot; state.)</p>

<p>So copy the Storyboard that you added to the &quot;MouseOver&quot; state and paste it into the &quot;Pressed&quot; state. Now, when you click on the Button, it does not shrink, but neither is there any indication that something is happening. So let's add another ScaleTransform, to the ContentPresenter this time, and give it a RenderTransformOrigin, too (try leaving the RenderTransformOrigin off and seeing what happens):</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">ContentPresenter
        </span><span style="color: red">Content</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Content</span><span style="color: blue">}&quot;
        </span><span style="color: red">ContentTemplate</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">ContentTemplate</span><span style="color: blue">}&quot;
        </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">}&quot;
        </span><span style="color: red">Padding</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Padding</span><span style="color: blue">}&quot;
        </span><span style="color: red">TextAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextAlignment</span><span style="color: blue">}&quot;
        </span><span style="color: red">TextDecorations</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextDecorations</span><span style="color: blue">}&quot;
        </span><span style="color: red">TextWrapping</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextWrapping</span><span style="color: blue">}&quot;
        </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">}&quot;
        </span><span style="color: red">Margin</span><span style="color: blue">=&quot;4,5,4,4&quot;
        </span><span style="color: red">RenderTransformOrigin</span><span style="color: blue">=&quot;.5,.5&quot;&gt;
    &lt;</span><span style="color: #a31515">ContentPresenter.RenderTransform</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">ScaleTransform </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;contentZoom&quot;/&gt;
    &lt;/</span><span style="color: #a31515">ContentPresenter.RenderTransform</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">ContentPresenter</span><span style="color: blue">&gt;</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p><a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>And let's add some more animations to the &quot;MouseOver&quot; state:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Pressed&quot;&gt;
    &lt;</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;zoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleX&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
        &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;zoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleY&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
        &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;.5&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;contentZoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleX&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
        &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;.5&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;contentZoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleY&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>Since we are doubling the size of the Button's visuals when we animate the &quot;zoom&quot; transform, if we halve them in the &quot;Pressed&quot; state by animating the &quot;contentZoom&quot; ScaleTransform, the Content will go back to its normal size and we'll get a nice press effect.</p>

<p>Let's also add a Storyboard for the &quot;Disabled&quot; state:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Disabled&quot;&gt;
    &lt;</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;.4&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;disabledEllipse&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;Opacity&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>For the focus visuals, let's insert another Ellipse immediately before the ContentPresenter (so that it will not be drawn over the Content). It has a RadialGradient to give the Button a little glow when it is focused:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Ellipse </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;focusEllipse&quot; </span><span style="color: red">Opacity</span><span style="color: blue">=&quot;0&quot;&gt;
    &lt;</span><span style="color: #a31515">Ellipse.Fill</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">RadialGradientBrush </span><span style="color: red">Center</span><span style="color: blue">=&quot;0.5,0.4&quot; </span><span style="color: red">GradientOrigin</span><span style="color: blue">=&quot;0.25,0.4&quot;&gt;
            &lt;</span><span style="color: #a31515">RadialGradientBrush.GradientStops</span><span style="color: blue">&gt;
                &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;White&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;0.0&quot; /&gt;
                &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;1&quot; /&gt;
            &lt;/</span><span style="color: #a31515">RadialGradientBrush.GradientStops</span><span style="color: blue">&gt;
        &lt;/</span><span style="color: #a31515">RadialGradientBrush</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">Ellipse.Fill</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Ellipse</span><span style="color: blue">&gt;</span></pre>

<p>Animate it in the &quot;Focused&quot; state just like the &quot;Disabled&quot; state:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Focused&quot;&gt;
    &lt;</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;.4&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;focusEllipse&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;Opacity&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;</span></pre>

<p><a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>We don't need to do anything in the &quot;Unfocused&quot; state, because the Opacity of the &quot;focusEllipse&quot; is set to 0 in the XAML.</p>

<p>So now we have a Button that does all the right things: it has nice mouse over and click effects, and can respond to being disabled and focused. The only problem is that the effects are rather jarring--they simply jump to their values. We should smooth things out. We can do this by adding a default VisualTransition in the CommonStates, like this:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;CommonStates&quot;&gt;
    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup.Transitions</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">VisualTransition </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0:0:0.1&quot;/&gt;
    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup.Transitions</span><span style="color: blue">&gt;</span></pre>

<p><a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>This means that all transitions will take 0.1 seconds, which is quick enough to be responsive, but still smooth. Add a similar VisualTransition to the &quot;FocusState&quot; VisualStateGroup, and the focus visuals will also be smooth.</p>

<p>Here's our final XAML:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">UserControl </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;EllipseButton.Page&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">vsm</span><span style="color: blue">=&quot;clr-namespace:System.Windows;assembly=System.Windows&quot;&gt;
    &lt;</span><span style="color: #a31515">UserControl.Resources</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Style </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;EllipseButtonStyle&quot; </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;Button&quot;&gt;
            &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&quot;Template&quot;&gt;
                &lt;</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">&gt;
                    &lt;</span><span style="color: #a31515">ControlTemplate </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;Button&quot;&gt;
                        &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">RenderTransformOrigin</span><span style="color: blue">=&quot;.5,.5&quot;&gt;
                            &lt;</span><span style="color: #a31515">Grid.RenderTransform</span><span style="color: blue">&gt;
                                &lt;</span><span style="color: #a31515">ScaleTransform </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;zoom&quot;/&gt;
                            &lt;/</span><span style="color: #a31515">Grid.RenderTransform</span><span style="color: blue">&gt;
                            &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateManager.VisualStateGroups</span><span style="color: blue">&gt;
                                &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;CommonStates&quot;&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup.Transitions</span><span style="color: blue">&gt;
                                        &lt;</span><span style="color: #a31515">VisualTransition </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0:0:0.1&quot;/&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup.Transitions</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Normal&quot; /&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;MouseOver&quot;&gt;
                                        &lt;</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
                                            &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;zoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleX&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
                                            &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;zoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleY&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
                                        &lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Pressed&quot;&gt;
                                        &lt;</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
                                            &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;zoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleX&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
                                            &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;zoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleY&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
                                            &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;.5&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;contentZoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleX&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
                                            &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;.5&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;contentZoom&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;ScaleY&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
                                        &lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Disabled&quot;&gt;
                                        &lt;</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
                                            &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;.4&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;disabledEllipse&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;Opacity&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
                                        &lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup</span><span style="color: blue">&gt;
                                &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;FocusStates&quot;&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup.Transitions</span><span style="color: blue">&gt;
                                        &lt;</span><span style="color: #a31515">VisualTransition </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0:0:0.1&quot;/&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup.Transitions</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Focused&quot;&gt;
                                        &lt;</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
                                            &lt;</span><span style="color: #a31515">DoubleAnimation </span><span style="color: red">To</span><span style="color: blue">=&quot;.4&quot; </span><span style="color: red">Storyboard.TargetName</span><span style="color: blue">=&quot;focusEllipse&quot; </span><span style="color: red">Storyboard.TargetProperty</span><span style="color: blue">=&quot;Opacity&quot; </span><span style="color: red">Duration</span><span style="color: blue">=&quot;0&quot;/&gt;
                                        &lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Unfocused&quot;&gt;
                                    &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualState</span><span style="color: blue">&gt;
                                &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateGroup</span><span style="color: blue">&gt;
                            &lt;/</span><span style="color: #a31515">vsm</span><span style="color: blue">:</span><span style="color: #a31515">VisualStateManager.VisualStateGroups</span><span style="color: blue">&gt;

                            &lt;</span><span style="color: #a31515">Ellipse </span><span style="color: red">Fill</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Background</span><span style="color: blue">}&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Foreground</span><span style="color: blue">}&quot; </span><span style="color: red">StrokeThickness</span><span style="color: blue">=&quot;2&quot;/&gt;

                            &lt;</span><span style="color: #a31515">Ellipse </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;focusEllipse&quot; </span><span style="color: red">Opacity</span><span style="color: blue">=&quot;0&quot;&gt;
                                &lt;</span><span style="color: #a31515">Ellipse.Fill</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">RadialGradientBrush </span><span style="color: red">Center</span><span style="color: blue">=&quot;0.5,0.4&quot; </span><span style="color: red">GradientOrigin</span><span style="color: blue">=&quot;0.25,0.4&quot;&gt;
                                        &lt;</span><span style="color: #a31515">RadialGradientBrush.GradientStops</span><span style="color: blue">&gt;
                                            &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;White&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;0.0&quot; /&gt;
                                            &lt;</span><span style="color: #a31515">GradientStop </span><span style="color: red">Color</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Offset</span><span style="color: blue">=&quot;1&quot; /&gt;
                                        &lt;/</span><span style="color: #a31515">RadialGradientBrush.GradientStops</span><span style="color: blue">&gt;
                                    &lt;/</span><span style="color: #a31515">RadialGradientBrush</span><span style="color: blue">&gt;
                                &lt;/</span><span style="color: #a31515">Ellipse.Fill</span><span style="color: blue">&gt;
                            &lt;/</span><span style="color: #a31515">Ellipse</span><span style="color: blue">&gt;

                            &lt;</span><span style="color: #a31515">ContentPresenter
                                    </span><span style="color: red">Content</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Content</span><span style="color: blue">}&quot;
                                    </span><span style="color: red">ContentTemplate</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">ContentTemplate</span><span style="color: blue">}&quot;
                                    </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">}&quot;
                                    </span><span style="color: red">Padding</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Padding</span><span style="color: blue">}&quot;
                                    </span><span style="color: red">TextAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextAlignment</span><span style="color: blue">}&quot;
                                    </span><span style="color: red">TextDecorations</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextDecorations</span><span style="color: blue">}&quot;
                                    </span><span style="color: red">TextWrapping</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">TextWrapping</span><span style="color: blue">}&quot;
                                    </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">}&quot;
                                    </span><span style="color: red">Margin</span><span style="color: blue">=&quot;4,5,4,4&quot;
                                    </span><span style="color: red">RenderTransformOrigin</span><span style="color: blue">=&quot;.5,.5&quot;&gt;
                                &lt;</span><span style="color: #a31515">ContentPresenter.RenderTransform</span><span style="color: blue">&gt;
                                    &lt;</span><span style="color: #a31515">ScaleTransform </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;contentZoom&quot;/&gt;
                                &lt;/</span><span style="color: #a31515">ContentPresenter.RenderTransform</span><span style="color: blue">&gt;
                            &lt;/</span><span style="color: #a31515">ContentPresenter</span><span style="color: blue">&gt;
                            
                            &lt;</span><span style="color: #a31515">Ellipse </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;disabledEllipse&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;White&quot; </span><span style="color: red">Opacity</span><span style="color: blue">=&quot;0&quot;/&gt;
                        
                        &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
                    &lt;/</span><span style="color: #a31515">ControlTemplate</span><span style="color: blue">&gt;
                &lt;/</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">&gt;
            &lt;/</span><span style="color: #a31515">Setter</span><span style="color: blue">&gt;
        &lt;/</span><span style="color: #a31515">Style</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">UserControl.Resources</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LayoutRoot&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;White&quot;&gt;
        &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">EllipseButtonStyle</span><span style="color: blue">}&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;40&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;40&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;Hello&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;#4b2&quot; </span><span style="color: red">Click</span><span style="color: blue">=&quot;Button_Click&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">UserControl</span><span style="color: blue">&gt;
</span></pre>
<a href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></a>

<p>Here's how the focused Button looks now (unfocused, it looks the same as above):</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_16.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_16.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_16.png"><img height="41" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_7.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_7.png" width="41" border="0" mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/RetemplatingaStandardControlIncludingVis_128EF/image_thumb_7.png" /></a> </p>

<p>So here's basically what to do:</p>

<ol>
  <li>Create a project with an instance of the control you want to retemplate </li>

  <li>Copy over the built-in style from generic.xaml </li>

  <li>Remove most of the visuals and all of the Storyboards from the ControlTemplate </li>

  <li>Add visuals </li>

  <li>Add Storyboards to the VisualStates</li>
</ol>

<p>Now that you have a Style with this ControlTemplate, you can put it in your Application.Resource section for use throughout your application, or you could create a subclass for this control and put the Style in the generic.xaml of the control's assembly.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/08/77/97/00/EllipseButton.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-08-77-97-00/EllipseButton.zip">EllipseButton.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Silverlight Layout Fundamentals Part 2 - Layout Containers</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/silverlight-layout-fundamentals-part-2-layout-containers</link>
      <pubDate>Sat, 26 Jul 2008 10:21:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2008/07/26/silverlight-layout-fundamentals-part-2-layout-containers/</guid>
      <description><![CDATA[In Layout Fundamentals Part 1, I started slowly, and demonstrated the need for a layout system. I...]]></description>
      <content:encoded><![CDATA[<P><EM>In <A title="Layout Fundamentals Part 1" href="https://blogs.msdn.com/devdave/archive/2008/07/19/silverlight-layout-fundamentals-part-1-what-is-layout.aspx" mce_href="https://blogs.msdn.com/devdave/archive/2008/07/19/silverlight-layout-fundamentals-part-1-what-is-layout.aspx">Layout Fundamentals Part 1</A>, I started slowly, and demonstrated the need for a layout system. I touched on what it can do for you, and layout containers and properties. This post covers the layout containers and some layout concepts in a bit more detail. I will touch on some properties that affect layout; those will be examined in more depth in Part 3.</EM></P>
<H2>Canvas</H2>
<P>Canvas, the most basic layout container, was present in Silverlight 1.0. It <A title="Why I Don't Like Canvas" href="https://blogs.msdn.com/devdave/archive/2008/05/21/why-i-don-t-like-canvas.aspx" mce_href="https://blogs.msdn.com/devdave/archive/2008/05/21/why-i-don-t-like-canvas.aspx">should not be used</A> in most layout scenarios, as for the most part, it makes you do everything yourself. It lets its children be as big as they want to be, and positions them according to the Canvas.Left and Canvas.Top attached properties. It is "boundless" and does not clip by default. In <A title="Layout Fundamentals Part 1" href="https://blogs.msdn.com/devdave/archive/2008/07/19/silverlight-layout-fundamentals-part-1-what-is-layout.aspx" mce_href="https://blogs.msdn.com/devdave/archive/2008/07/19/silverlight-layout-fundamentals-part-1-what-is-layout.aspx">Layout Fundamentals Part 1</A>, the first examples showed how much "fun" it can be to position elements on a Canvas.</P>
<H2>Border</H2>
<P>Border is a very simple layout container. It does not derive from Panel, and can have only one child, which is centered by default. In addition to the Background property, Border has the BorderBrush, BorderThickness, CornerRadius, and Padding properties.</P>
<P>BorderBrush specifies the brush that will be used to draw the border of the Border. This is analogous to the Stroke property on a Rectangle. BorderThickness determines how many pixels thick each side of the Border will be, and CornerRadius determines the curve on each corner. The Padding property is used to put space between the border and the content. Note that the CornerRadius is used for rendering only. Only the BorderThickness property is used for layout calculations. This means that although it is possible to make a Border that looks like a circle, it is also possible to have the content overlapping the rounded corners of the border.</P>
<P>This XAML:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="100" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="150" </SPAN><SPAN style="COLOR: red">BorderBrush</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">BorderThickness</SPAN><SPAN style="COLOR: blue">="12,4" </SPAN><SPAN style="COLOR: red">CornerRadius</SPAN><SPAN style="COLOR: blue">="12,4,12,4" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightBlue"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Fancy Border" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P>produces a fancy Border like this:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_2.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_2.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_2.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=115 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb.png" width=163 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb.png"></A> </P>
<P>I said that the Border centers its children by default, but it isn't really the Border that does that, but rather the default values for HorizontalAlignment and VerticalAlignment on its child that do the centering. You'll notice that I specified the alignment of the TextBlock. TextBlock is special; it will take up all the space that is given to it, and render itself in the top-left, unless explicitly told to do otherwise. Also note that I specified the Width and Height of the Border. That is always an option, but you can let the Border figure out for itself how big it should be. In this case, it would first determine how big its child (the TextBlock) is, then add the Padding and BorderThickness properties.</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">BorderBrush</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">BorderThickness</SPAN><SPAN style="COLOR: blue">="12,4" </SPAN><SPAN style="COLOR: red">CornerRadius</SPAN><SPAN style="COLOR: blue">="12,4,12,4" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightBlue"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Fancy Border" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_4.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_4.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_4.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=31 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_1.png" width=116 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_1.png"></A> </P>
<P>The Border is just a bit too tight around the text, so let's add some Padding:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">BorderBrush</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">BorderThickness</SPAN><SPAN style="COLOR: blue">="12,4" </SPAN><SPAN style="COLOR: red">CornerRadius</SPAN><SPAN style="COLOR: blue">="12,4,12,4" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightBlue" </SPAN><SPAN style="COLOR: red">Padding</SPAN><SPAN style="COLOR: blue">="4"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Fancy Border" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_6.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_6.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_6.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=39 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_2.png" width=124 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_2.png"></A> </P>
<P>The Padding property is used in addition to the Margin property, which will be discussed below. If we put a Margin on the TextBlock, then we get this:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">BorderBrush</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">BorderThickness</SPAN><SPAN style="COLOR: blue">="12,4" </SPAN><SPAN style="COLOR: red">CornerRadius</SPAN><SPAN style="COLOR: blue">="12,4,12,4" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightBlue" </SPAN><SPAN style="COLOR: red">Padding</SPAN><SPAN style="COLOR: blue">="4"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Fancy Border" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="8"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_10.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_10.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_10.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=55 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_4.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_4.png" width=140 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_4.png"></A> </P>
<P>Now there are 12 pixels between the TextBlock and the inside of the Border. It doesn't really matter how many of those pixels are the Border's Padding, or the TextBlock's Margin.</P>
<P>And now, I have a confession to make. I've been cheating. All of the XAML that I've been using actually includes a UserControl and a Canvas:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">UserControl </SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">Class</SPAN><SPAN style="COLOR: blue">="LayoutPt2.Page"
    </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">=<A href="https://schemas.microsoft.com/winfx/2006/xaml" mce_href="https://schemas.microsoft.com/winfx/2006/xaml">https://schemas.microsoft.com/winfx/2006/xaml</A></SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Canvas</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">BorderBrush</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">BorderThickness</SPAN><SPAN style="COLOR: blue">="12,4" </SPAN><SPAN style="COLOR: red">CornerRadius</SPAN><SPAN style="COLOR: blue">="12,4,12,4" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightBlue" </SPAN><SPAN style="COLOR: red">Padding</SPAN><SPAN style="COLOR: blue">="4"&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Fancy Border" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="8"/&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">Canvas</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">UserControl</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>This is because if the Border was the child of the UserControl instead of the Canvas, it would take up the entire available space, which in this case would be the plugin space, because the default value for the HorizontalAlignment and VerticalAlignment are Stretch, which will cause the element to take up all of the available space. Often, this is exactly what you want, but for this example, I wanted to show what the Border would look like if it was not doing that. Here's what things would looks like without the Canvas:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">UserControl </SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">Class</SPAN><SPAN style="COLOR: blue">="LayoutPt1.Page"
    </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">=<A href="https://schemas.microsoft.com/winfx/2006/xaml" mce_href="https://schemas.microsoft.com/winfx/2006/xaml">https://schemas.microsoft.com/winfx/2006/xaml</A></SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">BorderBrush</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">BorderThickness</SPAN><SPAN style="COLOR: blue">="12,4" </SPAN><SPAN style="COLOR: red">CornerRadius</SPAN><SPAN style="COLOR: blue">="12,4,12,4" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightBlue" </SPAN><SPAN style="COLOR: red">Padding</SPAN><SPAN style="COLOR: blue">="4"&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Fancy Border" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="8"/&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">UserControl</SPAN><SPAN style="COLOR: blue">&gt;
</SPAN></PRE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_12.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_12.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_12.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=225 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_5.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_5.png" width=308 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_5.png"></A> </P>
<P>This fill behavior is typical, and is the result of an element being given more space than it actually needs. Unless the width and height have been set or constrained (e.g. by the MaxWidth and/or MaxHeight properties) or the HorizontalAlignment and/or VerticalAlignments set to a value other then Stretch, most elements will expand to fill the space assigned to them. The Margin and Padding properties have an effect on the minimum size only.</P>
<P>If an element in a layout container requires more space than is given to it, it is automatically clipped. Here's some XAML that specified the width of the Border, to make it narrower than the text requires:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Canvas</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Border </SPAN><SPAN style="COLOR: red">BorderBrush</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100" </SPAN><SPAN style="COLOR: red">BorderThickness</SPAN><SPAN style="COLOR: blue">="12,4" </SPAN><SPAN style="COLOR: red">CornerRadius</SPAN><SPAN style="COLOR: blue">="12,4,12,4" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightBlue" </SPAN><SPAN style="COLOR: red">Padding</SPAN><SPAN style="COLOR: blue">="4"&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Fancy Border" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="8"/&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">Border</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Canvas</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>And here's how that looks:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_8.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_8.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_8.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=55 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_3.png" width=100 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_3.png"></A> </P>
<P>You can see that the text does not go all the way up to the edge. That is because of the Margin and Padding. Those properties are applied before the content is clipped.</P>
<H2>StackPanel</H2>
<P>The StackPanel will place its children in either a column (default) or row. This is controlled by the Orientation property. A vertical StackPanel can have its width and height specified; if the width is not specified, it will be as wide as its widest child (or it will stretch to fit <EM>its</EM> parent), if the height is not specified it will take up as much space vertically as is required to fit all of its children. An unconstrained horizontal StackPanel will be as wide as necessary to hold all of its children, and as tall as the tallest child. Here is some XAML for a vertical StackPanel with its Width specified:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Aquamarine" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="150"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=100" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="auto" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=auto" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="200" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=200" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P>This looks like:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_14.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_14.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_14.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=90 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_6.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_6.png" width=151 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_6.png"></A> </P>
<P>The StackPanel has its Width set to 150. The first Button, which has its Width set to 100, is centered. The second button, which has its width set to "auto" (which is the same as <EM>not</EM> setting it) expands to fill the width of the StackPanel. The third Button, which has a Width of 200, is clipped, and is not centered. Note that all Buttons, whether they fit, were stretched to fill the StackPanel, or clipped, have their Margin property applied. If the alignment properties of the StackPanel are set to "Stretch", and the width is unconstrained, what happens? Here the XAML:</P>
<P><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">UserControl </SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">Class</SPAN><SPAN style="COLOR: blue">="LayoutPt1.Page" <BR>&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">="https://schemas.microsoft.com/winfx/2006/xaml/presentation" <BR>&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">="https://schemas.microsoft.com/winfx/2006/xaml"</SPAN><SPAN style="COLOR: red">Loaded</SPAN><SPAN style="COLOR: blue">="UserControl_Loaded"&gt; <BR>&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Aquamarine"</SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Stretch"</SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Stretch"&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #a31515">Button</SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"</SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=100"</SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #a31515">Button</SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="auto"</SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=auto"</SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #a31515">Button</SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="200"</SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=200"</SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt; <BR>&nbsp;&nbsp;&nbsp; &lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt; <BR>&lt;/</SPAN><SPAN style="COLOR: #a31515">UserControl</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P>
<P>Here's the result:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_18.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_18.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_18.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=237 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_8.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_8.png" width=331 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_8.png"></A> </P>
<P>The StackPanel fills up the entire plugin space. The Buttons with their widths specified are centered; the Button with its Width set to "auto" is stretched fill the entire width. The bottom of the StackPanel is empty. There is no way to get the items in a vertical StackPanel to build from the bottom of the StackPanel; likewise a horizontal StackPanel's items will always be on the left. The VerticalAlignment property of a vertical StackPanel and the HorizontalAlighnment of a horizontal StackPanel are ignored. However, the HorizontalAlignment of an element in a vertical StackPanel, and the VerticalAlignment of an element in a horizontal StackPanel, will be honored. Here an example:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Aquamarine" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Stretch" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Stretch"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=100" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Left"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="auto" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=auto" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="200" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Width=200" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Right"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>
<P>Here's what that looks like:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_20.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_20.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_20.png"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=233 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_9.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_9.png" width=272 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_9.png"></A> </P>
<P>To emphasize the point about nested layout containers, here are some horizontal StackPanels inside of a vertical StackPanel:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Gray" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Center" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Orientation</SPAN><SPAN style="COLOR: blue">="Horizontal" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Red" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="A"/&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="B"/&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="C"/&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Orientation</SPAN><SPAN style="COLOR: blue">="Horizontal" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="White" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="D"/&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="E"/&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="F"/&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Orientation</SPAN><SPAN style="COLOR: blue">="Horizontal" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Blue" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="G"/&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="H"/&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="30" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="I"/&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>
<P>This looks like:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_22.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_22.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_22.png"><IMG height=102 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_10.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_10.png" width=106 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_10.png"></A></P>
<H2><STRONG>Grid</STRONG></H2>
<P>The Grid is the most powerful layout container provided in Silverlight 2. It can have multiple children, and acts rather like a spreadsheet. The cells are not explicitly defined; you specify the rows and columns, and those define the cells. A row is the same height and a column is the same width across the entire Grid, but elements can be made to span multiple cells. Cells can contain more than one item.</P>
<P>The placement of an element in the Grid is specified using attached DependencyProperties that are set on the children of the Grid: Grid.Row, Grid.Column, Grid.RowSpan and Grid.ColumnSpan.</P>
<P>The size of rows and columns may be specified exactly, set to "auto", or use "star-sizing". If a row or column is set to "auto", it will be just as tall or wide as its tallest or widest child. Star-sizing is very powerful but a bit more complicated, so it will be discussed below.</P>
<P>Let's just launch right into it, and bring back the example from the first post in this series. I've modified it a little bit to make it more interesting.</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">UserControl </SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">Class</SPAN><SPAN style="COLOR: blue">="LayoutPt1.Page"
    </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    </SPAN><SPAN style="COLOR: red">xmlns</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: red">x</SPAN><SPAN style="COLOR: blue">="https://schemas.microsoft.com/winfx/2006/xaml" </SPAN><SPAN style="COLOR: red">Loaded</SPAN><SPAN style="COLOR: blue">="UserControl_Loaded"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Grid </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Beige"&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Grid.RowDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">RowDefinition </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="auto"/&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">RowDefinition </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="*"/&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">RowDefinition </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="auto"/&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.RowDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"/&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="*"/&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;

        &lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Grid.Row</SPAN><SPAN style="COLOR: blue">="0" </SPAN><SPAN style="COLOR: red">Grid.Column</SPAN><SPAN style="COLOR: blue">="1" </SPAN><SPAN style="COLOR: red">Orientation</SPAN><SPAN style="COLOR: blue">="Horizontal" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Coral"&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="New" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="50" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Left"/&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Open" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="50" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;

        &lt;</SPAN><SPAN style="COLOR: #a31515">Grid </SPAN><SPAN style="COLOR: red">Grid.Row</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">Grid.Column</SPAN><SPAN style="COLOR: blue">="1" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="CornflowerBlue"&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
                &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="*"/&gt;
                &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="auto"/&gt;
            &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">TextBlock </SPAN><SPAN style="COLOR: red">Grid.Column</SPAN><SPAN style="COLOR: blue">="0" </SPAN><SPAN style="COLOR: red">Text</SPAN><SPAN style="COLOR: blue">="Status text" </SPAN><SPAN style="COLOR: red">VerticalAlignment</SPAN><SPAN style="COLOR: blue">="Center"/&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Grid.Column</SPAN><SPAN style="COLOR: blue">="1" </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Help" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="50" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2"/&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid</SPAN><SPAN style="COLOR: blue">&gt;

        &lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Grid.Row</SPAN><SPAN style="COLOR: blue">="0" </SPAN><SPAN style="COLOR: red">Grid.Column</SPAN><SPAN style="COLOR: blue">="0" </SPAN><SPAN style="COLOR: red">Grid.RowSpan</SPAN><SPAN style="COLOR: blue">="3" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightGreen"&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Command 1" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Left"/&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Command 2" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Left"/&gt;
            &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Command 3" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Left"/&gt;
        &lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">UserControl</SPAN><SPAN style="COLOR: blue">&gt;
</SPAN></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>
<P>This looks like:</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_24.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_24.png" mce_href="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_24.png"><IMG height=95 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_11.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_11.png" width=272 border=0 mce_src="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/LayoutFundamentalsPart2LayoutContainersa_8A63/image_thumb_11.png"></A> </P>
<P>Let's examine the XAML. There are two Grids, and two StackPanels. The first Grid, the "outer" one, has a RowDefinition section like this:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Grid.RowDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">RowDefinition </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="auto"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">RowDefinition </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="*"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">RowDefinition </SPAN><SPAN style="COLOR: red">Height</SPAN><SPAN style="COLOR: blue">="auto"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.RowDefinitions</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>This means that this Grid has three rows. These are numbered starting from 0, but in the definitions section, the number is implicit. The first definition is row 0, the next is row 1, etc. The only attribute a row has is its height. This is controlled by its Height, MinHeight and MaxHeight properties. When the Height is set to "auto", the row will only be as tall is it has to be to contain its children or to make an orderly Grid. The second Row has a size of "<STRONG>*</STRONG>". This means that the row will take up all left-over space. So if the Height of the Grid ends up being 100, and the first and last rows each take up 25, then the second row will be 50 high. It gets a little more complicated when more than one row or column is star-sized. The only item of note in the ColumnDefinition section is that the first column has a fixed size of 100.</P>
<P>The elements are placed in the <STRONG>Grid cells</STRONG> using the Grid.Row and <STRONG>Grid.Column</STRONG> properties.</P>
<P><STRONG>Star-sizing</STRONG> in a Grid is a very powerful way of allocating relative amounts of space. The algorithm is pretty complicated (it has to deal with auto- and star-sized rows and columns, spanning, etc.) but the principle is simple: whatever space is left over from fixed- and auto-sized columns is allocated to all of the columns with star-sizing, according to the proportion of stars. Let's consider these ColumnDefinitions:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Grid </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="Beige" </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="300"&gt;
</SPAN><SPAN style="COLOR: blue">    &lt;</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"/&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="*"/&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>
<P>The Grid has a width of 300. Column 0 has a width of 100, and there is one star-sized column, so the star-sized column gets all of the space left over (200). If the definitions looked like this:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="*"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="*"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>Then columns 1 and 2 would gets widths of 100 each. But with these definitions:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="*"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="3*"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>the space is allocated differently. The total of the multipliers on the stars is 4 (the 1 on "*" is implicit.) So each star is now width 4 / 200 = 50. Column 1 will be 1 * 50 wide and column 2 will be 3 * 50 wide. Real numbers can also be used:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="100"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">=".5*"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">ColumnDefinition </SPAN><SPAN style="COLOR: red">Width</SPAN><SPAN style="COLOR: blue">="1.5*"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">Grid.ColumnDefinitions</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>This ends up allocating the same amount of space in the previous example, because I chose nice numbers. The sum of the star multipliers is 2, so each star is worth 100 (in case you had forgotten the Grid is 300 wide, and the first column is 100 wide, so 200 will be divided up among the star-sized columns.) Column 1 is therefore .5 * 100 = 50 wide, and column 2 is 1.5 * 100 = 150 wide.</P>
<P><STRONG>Column </STRONG>and <STRONG>row spanning </STRONG>are controlled by the Grid.ColumnSpan and Grid.RowSpan properties. When one of these is set on the child of a Grid, it will cover more than one column or row. In the example above, the StackPanel has a Grid.RowSpan of 3:</P><PRE class=code><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">StackPanel </SPAN><SPAN style="COLOR: red">Grid.Row</SPAN><SPAN style="COLOR: blue">="0" </SPAN><SPAN style="COLOR: red">Grid.Column</SPAN><SPAN style="COLOR: blue">="0" </SPAN><SPAN style="COLOR: red">Grid.RowSpan</SPAN><SPAN style="COLOR: blue">="3" </SPAN><SPAN style="COLOR: red">Background</SPAN><SPAN style="COLOR: blue">="LightGreen"&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Command 1" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Left"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Command 2" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Left"/&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">Button </SPAN><SPAN style="COLOR: red">Content</SPAN><SPAN style="COLOR: blue">="Command 3" </SPAN><SPAN style="COLOR: red">Margin</SPAN><SPAN style="COLOR: blue">="2" </SPAN><SPAN style="COLOR: red">HorizontalAlignment</SPAN><SPAN style="COLOR: blue">="Left"/&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">StackPanel</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE>
<P>This causes the StackPanel to cover all three rows of the Grid, starting from the row specified by its Grid.Row property.</P>]]></content:encoded>
    </item>
    <item>
      <title>Silverlight Layout Fundamentals Part 1 - What is Layout?</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/silverlight-layout-fundamentals-part-1-what-is-layout</link>
      <pubDate>Sun, 20 Jul 2008 00:43:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2008/07/20/silverlight-layout-fundamentals-part-1-what-is-layout/</guid>
      <description><![CDATA[This is the first part of a series of articles on Silverlight 2's layout system. I'm going to start...]]></description>
      <content:encoded><![CDATA[<p><em>This is the first part of a series of articles on Silverlight 2's layout system. I'm going to start off slowly, and demonstrate the need for a layout system, then explain some more about what &quot;layout&quot; actually is and what the Silverlight 2 layout system can do.</em></p>  <p>Silverlight 1.0 did not have layout functionality. Silverlight 2 does. But why is that a big deal? And what does &quot;layout&quot; mean, anyway? In generic terms, when you &quot;lay something out&quot; you are positioning things in a space. You could lay out a garden, a housing development, a grocery store, anything where you have some space to fill up, and things to fill it up with. This obviously includes placing visual elements on a computer screen. </p>  <p>In the first examples below, we'll ignore the fact that Silverlight 2 has a layout system, and do all of our layout the hard way.</p>  <p><strong>Putting a button on the screen</strong></p>  <p>Let's take the simple case of wanting to make a button by putting a TextBlock inside of a Rectangle in the top-left corner of the area occupied by the Silverlight plugin. (Let's ignore the fact that Silverlight 2 has a Button, so you wouldn't really need to make your own.)</p>  <p>Let's start with the Rectangle:</p>  <pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">UserControl </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;LayoutPt1.Page&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=<a href="https://schemas.microsoft.com/winfx/2006/xaml">https://schemas.microsoft.com/winfx/2006/xaml</a></span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
&lt;/</span><span style="color: #a31515">UserControl</span><span style="color: blue">&gt;
</span></pre>
<a href="https://11011.net/software/vspaste"></a>

<p><a href="https://11011.net/software/vspaste"></a>So far, so good. (Note: I will not include the UserControl in subsequent examples, but it is still there.) Now, let's put the TextBlock in:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;Open&quot;/&gt;
&lt;/</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;</span></pre>

<p><a href="https://11011.net/software/vspaste"></a>But this doesn't look so good. The text isn't in the right spot:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_4.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_4.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="20" alt="Rectangle and TextBlock #1" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_1.png" width="100" border="0" /></a> </p>

<p>But how do you know where to put it? One way to do it would be use trial and error, and change the Canvas.Top and Canvas.Left properties of the TextBlock until it looks OK. But it seems like maybe this wonderful computer thingy could do that for you. Of course it can, but it will take some code.</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;button&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;buttonText&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Open&quot;/&gt;
&lt;/</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;</span></pre>

<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Windows;
<span style="color: blue">using </span>System.Windows.Controls;
<span style="color: blue">using </span>System.Windows.Shapes;

<span style="color: blue">namespace </span>LayoutPt1
{
    <span style="color: blue">public partial class </span><span style="color: #2b91af">Page </span>: <span style="color: #2b91af">UserControl
    </span>{
        <span style="color: blue">public </span>Page()
        {
            InitializeComponent();
        }

        <span style="color: blue">private void </span>UserControl_Loaded(<span style="color: blue">object </span>sender, <span style="color: #2b91af">RoutedEventArgs </span>e)
        {
            <span style="color: #2b91af">Canvas</span>.SetLeft(buttonText, (button.Width - buttonText.ActualWidth) / 2);
            <span style="color: #2b91af">Canvas</span>.SetTop(buttonText, (button.Height - buttonText.ActualHeight) / 2);
        }
    }
}</pre>
<a href="https://11011.net/software/vspaste"></a>

<p>(Note: In subsequent examples, I am only going to include the interesting bits of the code rather than the entire UserControl subclass file.) The text inside of the Rectangle looks better, but there is still something wrong. The whole thing is slammed up in the corner of the browser:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_6.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_6.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="30" alt="Rectangle and TextBlock #2" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_2.png" width="107" border="0" /></a> </p>

<p>It would look nicer with some more room, so let's change the XAML.</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;button&quot; </span><span style="color: red">Canvas.Left</span><span style="color: blue">=&quot;8&quot; </span><span style="color: red">Canvas.Top</span><span style="color: blue">=&quot;8&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; 
               </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;buttonText&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Open&quot;/&gt;
&lt;/</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;</span></pre>

<p>Oops. That doesn't look so good:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_8.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_8.png"><img height="35" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_3.png" width="115" border="0" /></a> </p>

<p>Looks like we should change the code to account for the fact the the Rectangle is no longer at 0,0.</p>

<pre class="code"><span style="color: #2b91af">Canvas</span>.SetLeft(buttonText, <span style="color: #2b91af">Canvas</span>.GetLeft(button) + (button.Width - buttonText.ActualWidth) / 2);
<span style="color: #2b91af">Canvas</span>.SetTop(buttonText, <span style="color: #2b91af">Canvas</span>.GetTop(button) + (button.Height - buttonText.ActualHeight) / 2);</pre>

<p>Much better:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_12.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_12.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="42" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_5.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_5.png" width="121" border="0" /></a> </p>

<p>So now, we have some XAML and some code that will center a TextBlock inside of a Rectangle at 8,8.</p>

<p><strong>Adding more buttons</strong></p>

<p>Now that we have one button on the screen, let's add another. Where should we put it? Well, we forgot some white space around the button last time, so let's not forget it this time. The first button is at 8,8 and it is 100 wide and 20 high, and if we want a space of four pixels between the buttons for the margin, we should put the next button at 8 + 20 + 4 = 32. We should be able to copy, paste and modify our code to center the text.</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;button1&quot; </span><span style="color: red">Canvas.Left</span><span style="color: blue">=&quot;8&quot; </span><span style="color: red">Canvas.Top</span><span style="color: blue">=&quot;8&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; 
               </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;buttonText1&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Open&quot;/&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;button2&quot; </span><span style="color: red">Canvas.Left</span><span style="color: blue">=&quot;8&quot; </span><span style="color: red">Canvas.Top</span><span style="color: blue">=&quot;32&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; 
               </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;buttonText2&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Save&quot;/&gt;
&lt;/</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;</span></pre>
<a href="https://11011.net/software/vspaste"></a>

<pre class="code"><span style="color: #2b91af">Canvas</span>.SetLeft(buttonText1, <span style="color: #2b91af">Canvas</span>.GetLeft(button1) + (button1.Width - buttonText2.ActualWidth) / 2);
<span style="color: #2b91af">Canvas</span>.SetTop(buttonText1, <span style="color: #2b91af">Canvas</span>.GetTop(button1) + (button1.Height - buttonText2.ActualHeight) / 2);
<span style="color: #2b91af">Canvas</span>.SetLeft(buttonText2, <span style="color: #2b91af">Canvas</span>.GetLeft(button2) + (button2.Width - buttonText2.ActualWidth) / 2);
<span style="color: #2b91af">Canvas</span>.SetTop(buttonText2, <span style="color: #2b91af">Canvas</span>.GetTop(button2) + (button2.Height - buttonText2.ActualHeight) / 2);</pre>

<p>Hah. Got it right the first try:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_14.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_14.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="60" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_6.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_6.png" width="116" border="0" /></a> </p>

<p><strong>Now it gets complicated</strong></p>

<p>But now, let's add some more buttons, which should be just like adding the &quot;Save&quot; button. But by the way, we want a &quot;New&quot; button to be on top, so we have to move everything down. And we also want our little stack of buttons in the bottom-right corner instead of the top left. We could do that by changing all of the Canvas.Left and Canvas.Top values. A little laborious, but not too bad. But what if we wanted to change the plugin size? Well, we could type in the numbers again. But what it the plugin was sized not absolutely, but as a percentage of the browser size, and we wanted our buttons to always be in the bottom right as the user resized the browser? Then we'd have to&#160; do this:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;button0&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;buttonText0&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;New&quot;/&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;button1&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;buttonText1&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Open&quot;/&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;button2&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;buttonText2&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Save&quot;/&gt;
    &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;button3&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Stroke</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">Fill</span><span style="color: blue">=&quot;Beige&quot;/&gt;
    &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;buttonText3&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Save as...&quot;/&gt;
&lt;/</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;</span></pre>

<pre class="code"><span style="color: blue">void </span>Content_Resized(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
{
    <span style="color: blue">const double </span>bigMargin = 8;
    <span style="color: blue">const double </span>smallMargin = 4;

    <span style="color: blue">double </span>right = <span style="color: #2b91af">Application</span>.Current.Host.Content.ActualWidth - bigMargin;
    <span style="color: blue">if </span>(right &lt; 0) <span style="color: blue">return</span>;

    <span style="color: blue">double </span>bottom = <span style="color: #2b91af">Application</span>.Current.Host.Content.ActualHeight - bigMargin;

    PositionButton(button3, buttonText3, smallMargin, right, <span style="color: blue">ref </span>bottom);
    PositionButton(button2, buttonText2, smallMargin, right, <span style="color: blue">ref </span>bottom);
    PositionButton(button1, buttonText1, smallMargin, right, <span style="color: blue">ref </span>bottom);
    PositionButton(button0, buttonText0, smallMargin, right, <span style="color: blue">ref </span>bottom);
}

<span style="color: blue">private void </span>PositionButton(<span style="color: #2b91af">Rectangle </span>r, <span style="color: #2b91af">TextBlock </span>t, <span style="color: blue">double </span>margin, <span style="color: blue">double </span>right, <span style="color: blue">ref double </span>bottom)
{
    <span style="color: blue">double </span>left = right - r.Width;
    <span style="color: blue">double </span>top = bottom - r.Height;

    <span style="color: #2b91af">Canvas</span>.SetLeft(r, left);
    <span style="color: #2b91af">Canvas</span>.SetTop(r, top);
    <span style="color: #2b91af">Canvas</span>.SetLeft(t, left + (r.Width - t.ActualWidth) / 2);
    <span style="color: #2b91af">Canvas</span>.SetTop(t, top + (r.Height - t.ActualHeight) / 2);

    bottom -= r.Height + margin;
}</pre>

<p>And it looks wonderful, and moves when the browser changes size:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_16.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_16.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="114" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_7.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_7.png" width="120" border="0" /></a> </p>

<p>But it was painful, and it was a lot of code to write just to move put four buttons where we wanted them. And even though things are nicely factored for putting a stack of buttons in the bottom right, imagine a screen full of buttons and such. And while you are designing, you'd add and remove elements, try different elements, move elements, etc. so you'd constantly be changing code to move things around. Yuck.</p>

<p><strong>Layout to the rescue</strong></p>

<p>So if you had never really thought about it before, it is easy to see why something that would do all of the dirty work for you would be nice.</p>

<p>That &quot;something&quot; in Silverlight 2 is the layout system. Silverlight 2 adds layout container elements. These layout container elements define how their children will be sized and positioned. A simple and very useful layout container is the Border element, which is similar to a Rectangle in many ways, but it has a single child that it centers inside of it by default.</p>

<p>This XAML will put our single &quot;button&quot; in the right spot in the upper left like we did above, but no code is necessary (obviously Silverlight is working away behind the scenes, but that's it):</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;8&quot;&gt;
        &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;New&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
</span><span style="color: blue">&lt;/</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;</span></pre>

<p>Another simple layout container is the StackPanel. By default, this puts its children in a vertical stack, just like we did. Here's what that XAML looks like, again without having to write any code:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">StackPanel </span><span style="color: red">Margin</span><span style="color: blue">=&quot;6&quot;&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;New&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;Open&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;Save&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;Save as...&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Canvas</span><span style="color: blue">&gt;</span></pre>

<p><a href="https://11011.net/software/vspaste"></a>This looks exactly the same as our upper-left button stack. There are some more attributes in the XAML, but that's a small price to pay. The XAML for the bottom-right stack of buttons looks like this:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">StackPanel </span><span style="color: red">Margin</span><span style="color: blue">=&quot;6&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Right&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Bottom&quot;&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;New&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;Open&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;Save&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Border </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;Black&quot; </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot; </span><span style="color: red">Height</span><span style="color: blue">=&quot;20&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;100&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">=&quot;Save as...&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Center&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;</span></pre>
<a href="https://11011.net/software/vspaste"></a>

<p>By replacing the Canvas (which doesn't really participate in layout) with a Border, and setting the horizontal and vertical alignments on the StackPanel, we now have a stack of buttons in the bottom-right of the plugin, that will automatically reposition itself if the plugin changes size. Did I mention that this example contains no code?</p>

<p><strong>What does the Silverlight 2 layout system do?</strong></p>

<p>The Silverlight 2 layout system has two main tasks:</p>

<ol>
  <li>Figure out how big elements are</li>

  <li>Figure out where to put them</li>
</ol>

<p>To do this, it relies on the fact that all elements that can have children know how to position their children. It introduces layout elements that have specific positioning behavior:</p>

<p>The <strong>Border</strong> has one child, that is centered by default.</p>

<p>The <strong>StackPanel</strong> can have any number of children, and arranges them in either a column (the default) or a row.</p>

<p>The <strong>Grid</strong> can have any number of children, and it arranges them sort of like a spreadsheet does. You can define rows and columns, and specify which rows and columns your elements can go into.</p>

<p>It is also possible to define your own layout containers, but that is an advanced topic.</p>

<p>Silverlight 2 also has a number of properties that layout uses, such as <strong>Margin</strong>, <strong>HorizontalAlignment</strong>, <strong>VerticalAlignment</strong>, <strong>MinWidth</strong>, <strong>MaxWidth</strong>, <strong>MinHeight</strong>, <strong>MaxHeight</strong>, etc.</p>

<p>The power of layout is demonstrated when you put layout containers inside of layout containers. For the next example, let's say that you want your Silverlight 2 app to look like a Windows app, with a row of buttons across the top, a line for status information on the bottom, and a row of buttons down the left side.</p>

<p>This could be done a number of ways, but when you start dividing the screen into rows and columns, a Grid is the natural way to think of things. I'll dive into the Grid more in subsequent posts. This is how your app would look (and I'm going to use real Buttons this time):</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_18.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_18.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="268" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_8.png" original-url="https://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/SilverlightLayoutFundamentalsWhatisLayou_10B8F/image_thumb_8.png" width="349" border="0" /></a> </p>

<p>This is the XAML:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">UserControl </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;LayoutPt1.Page&quot;
    </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
    </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot; </span><span style="color: red">Loaded</span><span style="color: blue">=&quot;UserControl_Loaded&quot;&gt;
    &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">Background</span><span style="color: blue">=&quot;Beige&quot;&gt;
        &lt;</span><span style="color: #a31515">Grid.RowDefinitions</span><span style="color: blue">&gt;
            &lt;</span><span style="color: #a31515">RowDefinition </span><span style="color: red">Height</span><span style="color: blue">=&quot;auto&quot;/&gt;
            &lt;</span><span style="color: #a31515">RowDefinition </span><span style="color: red">Height</span><span style="color: blue">=&quot;*&quot;/&gt;
            &lt;</span><span style="color: #a31515">RowDefinition </span><span style="color: red">Height</span><span style="color: blue">=&quot;auto&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Grid.RowDefinitions</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">Grid.ColumnDefinitions</span><span style="color: blue">&gt;
            &lt;</span><span style="color: #a31515">ColumnDefinition </span><span style="color: red">Width</span><span style="color: blue">=&quot;auto&quot;/&gt;
            &lt;</span><span style="color: #a31515">ColumnDefinition </span><span style="color: red">Width</span><span style="color: blue">=&quot;*&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Grid.ColumnDefinitions</span><span style="color: blue">&gt;
        
        &lt;</span><span style="color: #a31515">StackPanel </span><span style="color: red">Grid.Row</span><span style="color: blue">=&quot;0&quot; </span><span style="color: red">Grid.Column</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Orientation</span><span style="color: blue">=&quot;Horizontal&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;Coral&quot;&gt;
            &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Content</span><span style="color: blue">=&quot;New&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;50&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Left&quot;/&gt;
            &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Content</span><span style="color: blue">=&quot;Open&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;50&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;/&gt;
        &lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;
     
        &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">Grid.Row</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Grid.Column</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;CornflowerBlue&quot;&gt;
            &lt;</span><span style="color: #a31515">Grid.ColumnDefinitions</span><span style="color: blue">&gt;
                &lt;</span><span style="color: #a31515">ColumnDefinition </span><span style="color: red">Width</span><span style="color: blue">=&quot;*&quot;/&gt;
                &lt;</span><span style="color: #a31515">ColumnDefinition </span><span style="color: red">Width</span><span style="color: blue">=&quot;auto&quot;/&gt;
            &lt;/</span><span style="color: #a31515">Grid.ColumnDefinitions</span><span style="color: blue">&gt;
            &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">Grid.Column</span><span style="color: blue">=&quot;0&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Status text&quot; </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;Center&quot;/&gt;
            &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Grid.Column</span><span style="color: blue">=&quot;1&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;Help&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;50&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot;/&gt;
        &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;

        &lt;</span><span style="color: #a31515">StackPanel </span><span style="color: red">Grid.Row</span><span style="color: blue">=&quot;0&quot; </span><span style="color: red">Grid.Column</span><span style="color: blue">=&quot;0&quot; </span><span style="color: red">Grid.RowSpan</span><span style="color: blue">=&quot;3&quot; </span><span style="color: red">Background</span><span style="color: blue">=&quot;LightGreen&quot;&gt;
            &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Content</span><span style="color: blue">=&quot;Command 1&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;80&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Left&quot;/&gt;
            &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Content</span><span style="color: blue">=&quot;Command 2&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;80&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Left&quot;/&gt;
            &lt;</span><span style="color: #a31515">Button </span><span style="color: red">Content</span><span style="color: blue">=&quot;Command 3&quot; </span><span style="color: red">Margin</span><span style="color: blue">=&quot;2&quot; </span><span style="color: red">Width</span><span style="color: blue">=&quot;80&quot; </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;Left&quot;/&gt;
        &lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;

    &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">UserControl</span><span style="color: blue">&gt;
</span></pre>

<p><a href="https://11011.net/software/vspaste">&#160;</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Layout Transitions - An Animatable WrapPanel</title>
      <link>https://docs.microsoft.com/archive/blogs/devdave/layout-transitions-an-animatable-wrappanel</link>
      <pubDate>Thu, 17 Jul 2008 11:37:00 GMT</pubDate>
      <dc:creator><![CDATA[Dave Relyea - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devdave/2008/07/17/layout-transitions-an-animatable-wrappanel/</guid>
      <description><![CDATA[&nbsp;
I've been playing around with RenderTransforms and decorators and such to make layout...]]></description>
      <content:encoded><![CDATA[<P>&nbsp;<A href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/08/74/20/79/AnimatingWrapPanel.jpg" original-url="https://blogs.msdn.com/photos/devdave/images/8742079/original.aspx" target=_blank mce_href="https://blogs.msdn.com/photos/devdave/images/8742079/original.aspx"><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/08/74/20/79/AnimatingWrapPanel.jpg" original-url="https://blogs.msdn.com/photos/devdave/images/8742079/500x316.aspx" border=0 mce_src="https://blogs.msdn.com/photos/devdave/images/8742079/500x316.aspx"></A><A href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com//devdave/8742079.aspx" original-url="https://blogs.msdn.com/photos/devdave/picture8742079.aspx" target=_blank mce_href="https://blogs.msdn.com/photos/devdave/picture8742079.aspx"></A></P>
<P>I've been playing around with RenderTransforms and decorators and such to make layout transitions,&nbsp;but for this WrapPanel, my goal was to introduce no additional UI elements, animations&nbsp;or transforms. I also wanted to use some easing equations to do some cool transitions, and separate that logic from the WrapPanel. I wanted the elements the be "live" while they were on the screen, and I wanted them to enter the screen in a nice fashion. I also wanted each element to animate individually. One of my earlier versions of this kept track of a single starting time for all animations, and it wasn't cool enough. Sometimes, it is important to be cool.</P>
<P><STRONG>WrapPanels</STRONG></P>
<P>A WrapPanel is a layout container that places its&nbsp;elements&nbsp;in rows. It fills up one row, then moves on to the next one. The logic isn't all that tough. What I wanted to do was to make the items move smoothly when the WrapPanel was resized, and also enter the WrapPanel from the upper left and move to their new position.</P>
<P>Below are some of the interesting bits of the panel.</P>
<P><STRONG>Using a zero-duration Storyboard to simulate a per-frame callback</STRONG></P>
<P>Not using animations was one of my requirements, since I wanted to use something other than linear interpolation. The AnimateableWrapPanel uses a zero-duration Storyboard to simulate a per-frame callback.&nbsp;Here's how that is done. In the constructor,&nbsp;an empty&nbsp;Storyboard is created and started.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">public</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> AnimatedWrapPanel()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// This sets up the per-frame callback that we use for animation.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>_tick = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Storyboard</SPAN>();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>_tick.Duration = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Duration</SPAN>(<SPAN style="COLOR: #2b91af">TimeSpan</SPAN>.Zero);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>_tick.Completed += Tick;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>_tick.Begin();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</SPAN></P>
<P>The Tick method&nbsp;does whatever I want to do each frame, and restarts the Storyboard.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&lt;summary&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> This tells the layout system to call Arrange on the Panel if there are any elements that<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> must be moved.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&lt;/summary&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">private</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <SPAN style="COLOR: blue">void</SPAN> Tick(<SPAN style="COLOR: blue">object</SPAN> sender, <SPAN style="COLOR: #2b91af">EventArgs</SPAN> e)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// If there are still elements to be animated, make sure that ArrangeOverride will<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// get called. Note that the InvalidateArrange may already have been called due to<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// other operations, but calling it again does not hurt, and all of the work will<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// be done in ArrangeOverride regardless of where the invalidation came from.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (_animatingElements &gt; 0)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>InvalidateArrange();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// Restart the storyboard so we get called back on the next frame.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>_tick.Begin();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</SPAN></P>
<P>This technique does not guarantee smooth animations. It is possible to overload the panel with too many elements for the framewrate to animate 100% smoothly, or maybe the rest of the app&nbsp;is doing so much work that the framerate slows down,&nbsp;but since I use the elapsed time to figure out where to put the elements, the animations will take the same amount of time on all machines. If there is too much going on in the panel and the app, on a low-end machine, the animation might be choppy, but will still finish in the specified time, or one frame longer if the timing is just off.</P>
<P><STRONG>Using&nbsp;layout to "animate" the elements</STRONG></P>
<P>I'm a little conflicted about this technique, but I have seen other people use it, so I thought I'd try it. It is a two stage process. The MeasureOverride call figures out where everything should go, and is the only place where the animations are started. This works because MeasureOverride will be called if the AnimatedWrapPanel changes size, or any of its children change size, or children are added or removed. So size changes, adding items etc. kicks off the animations. In ArrangeOverride, any element that is not where it is supposed to be is moved in that direction according to how much it should be done, and the interpolations. Here's what the ArrangeOverride looks like:</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&lt;summary&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> A "normal" ArrangeOverride would just put things where they belong. What this one does<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> is to move the children towards their destinations according to the virtual animation<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> data that has been attached to each element. When they get there, the virtual animation<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> is turned off.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&lt;/summary&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">protected</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <SPAN style="COLOR: blue">override</SPAN> <SPAN style="COLOR: #2b91af">Size</SPAN> ArrangeOverride(<SPAN style="COLOR: #2b91af">Size</SPAN> finalSize)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">DateTime</SPAN> now = <SPAN style="COLOR: #2b91af">DateTime</SPAN>.Now;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">foreach</SPAN> (<SPAN style="COLOR: #2b91af">UIElement</SPAN> child <SPAN style="COLOR: blue">in</SPAN> Children)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">AnimatedWrapPanelAttachedData</SPAN> data = GetAnimatedWrapPanelAttachedData(child);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">TimeSpan</SPAN> elapsed = data.GetElapsed(now);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (elapsed &lt; Duration || data.TargetPosition != data.CurrentPosition)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// The virtual animation is not done yet, so figure out how far along it is...<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">double</SPAN> progress = (Duration.TimeSpan != <SPAN style="COLOR: #2b91af">TimeSpan</SPAN>.Zero) ? <SPAN style="COLOR: #2b91af">Math</SPAN>.Min(elapsed.TotalMilliseconds / Duration.TimeSpan.TotalMilliseconds, 1.0) : 1;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// ...and what the next position is.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">Point</SPAN> newPosition = BlendPoint(_interpolation, data.StartPosition, data.TargetPosition, progress);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>child.Arrange(<SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Rect</SPAN>(newPosition.X, newPosition.Y, child.DesiredSize.Width, _rowHeights[data.Row]));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data.CurrentPosition = newPosition;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">else<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// This element is not animating, but it might have become invalid on its own, so it still<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// needs to be arranged. The layout system will do as little as possible.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>child.Arrange(<SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Rect</SPAN>(data.CurrentPosition.X, data.CurrentPosition.Y, child.DesiredSize.Width, _rowHeights[data.Row]));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (data.IsAnimating)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>--_animatingElements;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// This is the only place where IsAnimating is set to false. This turns off the virtual animation.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data.IsAnimating = <SPAN style="COLOR: blue">false</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> finalSize;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</SPAN></P>
<P mce_keep="true"><STRONG>Attached&nbsp;property bag</STRONG></P>
<P mce_keep="true">Rather than have a bunch of hash tables or something in the&nbsp;panel itself, I wanted to keep all of the state that I needed on the elements, which sounded like a job for attached DependencyProperties. However, I got tired of creating and modifying them as I changed my mind, and decided that it would be easier at design-time and more efficient at run-time if I had a single attached property that was actually a class that had a bunch of properties--an attached property bag. This would be efficient because I always used all of the properties for each element.</P>
<P><STRONG>Interpolations using easing equations</STRONG></P>
<P mce_keep="true">Rather then hard-coding animations into the panel, or using a simple linear interpolation, I wanted to use pluggable interpolations. The interpolations take a double that indicates progress, where zero is "just starting" and one is "completed". They return a number (alpha) where zero refers to the start position, and one refers to the end position, although the number may be less than zero or greater than one. The general equation is:</P>
<P mce_keep="true">alpha = fn(progress)</P>
<P mce_keep="true">The linear interpolation is the simplest: it just gives returns the progress, i.e. alpha = progress.</P>
<P mce_keep="true">In practice, the interpolations are used to blend the starting and target positions. Here's how the intermediate points are arrived at:</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&lt;summary&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> Given an interpolation, the starting and ending positions and a number from 0-1 that represents how<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> far along the virtual animation is, calculate the new position.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">///</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&lt;/summary&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">Point</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> BlendPoint(<SPAN style="COLOR: #2b91af">Interpolation</SPAN> interpolation, <SPAN style="COLOR: #2b91af">Point</SPAN> from, <SPAN style="COLOR: #2b91af">Point</SPAN> to, <SPAN style="COLOR: blue">double</SPAN> progress)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">Point</SPAN> p = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Point</SPAN>();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">double</SPAN> alpha = interpolation.GetAlpha(progress);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>p.X = from.X + alpha * (to.X - from.X);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>p.Y = from.Y + alpha * (to.Y - from.Y);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> p;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</SPAN></P>
<P mce_keep="true">I used&nbsp;some standard interpolations, but it is possibly and easy to define your own, and then just plug them into the panel. I set up the interpolations with some default values that I thought looked nice, but it is possible to get quite creative.&nbsp;</P>
<P mce_keep="true"><STRONG>Using the demo app</STRONG></P>
<P mce_keep="true">This should be pretty self-explanatory, but you can add pretty, randomly-colored Rectangles, text and image thumbnails. Clicking on a Rectangle deletes it from the panel. You can also change the size of all of the children, select the duration of the animations, and the interpolation that will be used. Resize the browser to watch the UI move around. I had wanted to have UI to modify the interpolation parameters, but at some point, you have to stop polishing and move one. Shipping is the art of stopping. So that bit of UI is left as an exercise for the developer.</P>
<P mce_keep="true"><STRONG>Update:</STRONG></P>
<P mce_keep="true"><A class="" href="https://scorbs.com/" target=_blank mce_href="https://scorbs.com">Karen Corby</A>&nbsp;has posted a live version of my sample app, and a version of her FlickrViewr that she modified to use the AnimatingWrapPanel, <A class="" href="https://scorbs.com/2008/07/17/flickrviewr-using-devdaves-animatingwrappanel/" target=_blank mce_href="https://scorbs.com/2008/07/17/flickrviewr-using-devdaves-animatingwrappanel/">here</A>. I love how the images come in as they are downloaded.</P>
<P mce_keep="true">&nbsp;</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/08/74/20/93/AnimatingWrapPanelApp.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-08-74-20-93/AnimatingWrapPanelApp.zip">AnimatingWrapPanelApp.zip</a></p>]]></content:encoded>
    </item>
  </channel>
</rss>