<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>DevDave - Dave Relyea's Silverlight Blog : ControlTemplate</title><link>http://blogs.msdn.com/devdave/archive/tags/ControlTemplate/default.aspx</link><description>Tags: ControlTemplate</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Customizing a ToolTip</title><link>http://blogs.msdn.com/devdave/archive/2008/10/18/customizing-a-tooltip.aspx</link><pubDate>Sat, 18 Oct 2008 21:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9005166</guid><dc:creator>Dave Relyea</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/devdave/comments/9005166.aspx</comments><wfw:commentRss>http://blogs.msdn.com/devdave/commentrss.aspx?PostID=9005166</wfw:commentRss><description>&lt;P&gt;&lt;EM&gt;(Special thanks to Andre Michaud and Mike Russell who showed me how to do this.)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;ToolTip are typically defined like this:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="20" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ToolTipService.ToolTip&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Some helpful text"/&amp;gt;
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The standard ToolTip looks like this:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_6.png"&gt;&lt;IMG border=0 alt=image src="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_2.png" width=213 height=67 mce_src="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Here's some XAML that makes a ToolTip that can wrap text. It also modifies some of the font properties:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="20" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100"&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTipService.ToolTip&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MaxWidth&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="150" 
                   &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="This is a longer string of text. It is even in a different font. Aren't ToolTips exciting?" 
                   &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Georgia" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="14" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;TextWrapping&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Wrap"/&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTipService.ToolTip&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;This will show a ToolTip that is a little more interesting. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_8.png" mce_href="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_8.png"&gt;&lt;IMG border=0 alt=image src="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_3.png" width=221 height=107 mce_src="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_3.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Because you can set the Content property to anything that you want, you can do this:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="20" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100"&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTipService.ToolTip&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="CadetBlue"&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Some sort of title" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;TextAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center"/&amp;gt;
            &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MaxWidth&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="150" 
               &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="This is a longer string of text. It is even in a different font. Aren't ToolTips exciting?" 
               &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Georgia" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="14" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;TextWrapping&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Wrap"/&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTipService.ToolTip&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;This looks like this: 
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_10.png" mce_href="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_10.png"&gt;&lt;IMG border=0 alt=image src="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_4.png" width=211 height=117 mce_src="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_4.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;But this is still kind of a boring ToolTip: a plain-looking rectangle. But it is possible to make that look nicer, too. &lt;/P&gt;
&lt;P&gt;You can retemplate the ToolTip to give it new visuals. Here's an example:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_12.png" mce_href="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_12.png"&gt;&lt;IMG border=0 alt=image src="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_5.png" width=233 height=113 mce_src="http://blogs.msdn.com/blogfiles/devdave/WindowsLiveWriter/CustomizingaToolTip_9C10/image_thumb_5.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ToolTipTest.Page"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml" 
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="400" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ToolTipTemplate"&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;BorderBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Black" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;CornerRadius&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="8" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="PaleGoldenrod" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MaxWidth&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="200"&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid.ColumnDefinitions&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ColumnDefinition &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="auto"/&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ColumnDefinition &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="*"/&amp;gt;
                    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid.ColumnDefinitions&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="2"&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Ellipse &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Fill&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Black" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="52" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="52"/&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Ellipse &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Stroke&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="White" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StrokeThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Fill&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Blue" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="50" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="50"/&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="i" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="italic" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="40" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Georgia" 
                                               &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Foreground&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="White"/&amp;gt;

                    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentPresenter &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Grid.Column&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1"
                                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TemplateBinding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"
                                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TemplateBinding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"
                                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TemplateBinding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Padding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}" 
                                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Center"/&amp;gt;
                &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ControlTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="LayoutRoot" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Background&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Gainsboro"&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="20" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100"&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTipService.ToolTip&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTip &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Template&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ToolTipTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTip.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock 
                           &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="This is a longer string of text." 
                           &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontFamily&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Georgia" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;FontSize&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="14" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;TextWrapping&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Wrap"/&amp;gt;
                    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTip.Content&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTip&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ToolTipService.ToolTip&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9005166" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/devdave/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category><category domain="http://blogs.msdn.com/devdave/archive/tags/ControlTemplate/default.aspx">ControlTemplate</category><category domain="http://blogs.msdn.com/devdave/archive/tags/ToolTip/default.aspx">ToolTip</category></item><item><title>Control Lifecycle</title><link>http://blogs.msdn.com/devdave/archive/2008/10/11/control-lifecycle.aspx</link><pubDate>Sat, 11 Oct 2008 20:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8996162</guid><dc:creator>Dave Relyea</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/devdave/comments/8996162.aspx</comments><wfw:commentRss>http://blogs.msdn.com/devdave/commentrss.aspx?PostID=8996162</wfw:commentRss><description>&lt;P&gt;What happens when you create a Control? When do overrides get called and events get raised? When do styles get applied?&lt;/P&gt;
&lt;P&gt;In response to &lt;A href="http://silverlight.net/forums/t/34070.aspx" mce_href="http://silverlight.net/forums/t/34070.aspx"&gt;this thread&lt;/A&gt; 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.&lt;/P&gt;
&lt;TABLE border=1 cellSpacing=0 cellPadding=2 width=540&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=131&gt;&lt;STRONG&gt;Action&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=205&gt;&lt;STRONG&gt;Control instantiated in XAML&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;&lt;STRONG&gt;Control instantiated in code&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=130&gt;Control ctor&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;As soon as begin tag is parsed. &lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;When you call it.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=130&gt;Explicit Style applied&lt;/TD&gt;
&lt;TD vAlign=top width=199&gt;If the Style property is set in XAML, it will be applied as soon as the end tag is parsed.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;As soon as Style property is set.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=129&gt;Built-in Style (from generic.xaml) applied&lt;/TD&gt;
&lt;TD vAlign=top width=198&gt;As soon as the end tag is parsed, after the explicit Style (if any) has been applied. Will not override explicit Style.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;When the control enters the tree. Will not override explicit Style.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=128&gt;Properties set&lt;/TD&gt;
&lt;TD vAlign=top width=197&gt;When the attributes are parsed.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;When you set them.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=128&gt;Loaded event&lt;/TD&gt;
&lt;TD vAlign=top width=196&gt;Posted when the element is been added to the tree. Fired before the next frame. Happens before layout.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;Same.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=128&gt;Template applied (i.e. control's visual are created from the Template)&lt;/TD&gt;
&lt;TD vAlign=top width=195&gt;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.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;Same.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=129&gt;OnApplyTemplate called&lt;/TD&gt;
&lt;TD vAlign=top width=194&gt;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.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;Same.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=129&gt;Visuals first available&lt;/TD&gt;
&lt;TD vAlign=top width=194&gt;In OnApplyTemplate. Use GetTemplateChild.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;Same.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=129&gt;MeasureOverride called&lt;/TD&gt;
&lt;TD vAlign=top width=198&gt;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.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;Same.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=129&gt;ArrangeOverride called&lt;/TD&gt;
&lt;TD vAlign=top width=198&gt;In the Arrange pass of layout, which occurs after the Measure pass.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;Same.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=129&gt;SizeChanged event&lt;/TD&gt;
&lt;TD vAlign=top width=198&gt;After the Measure and Arrange passes have completed.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;Same.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=129&gt;LayoutUpdated event&lt;/TD&gt;
&lt;TD vAlign=top width=198&gt;After SizeChanged events have fired.&lt;/TD&gt;
&lt;TD vAlign=top width=202&gt;Same.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8996162" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/devdave/archive/tags/Layout/default.aspx">Layout</category><category domain="http://blogs.msdn.com/devdave/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category><category domain="http://blogs.msdn.com/devdave/archive/tags/SizeChanged/default.aspx">SizeChanged</category><category domain="http://blogs.msdn.com/devdave/archive/tags/LayoutUpdated/default.aspx">LayoutUpdated</category><category domain="http://blogs.msdn.com/devdave/archive/tags/Layout+events/default.aspx">Layout events</category><category domain="http://blogs.msdn.com/devdave/archive/tags/Property+system/default.aspx">Property system</category><category domain="http://blogs.msdn.com/devdave/archive/tags/ControlTemplate/default.aspx">ControlTemplate</category><category domain="http://blogs.msdn.com/devdave/archive/tags/Styles/default.aspx">Styles</category></item></channel></rss>