<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blog.avanadeadvisor.com/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>Bryant's Avanade Blog</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/default.aspx</link><description>My Avanade Blog</description><dc:language>en-US</dc:language><generator>CommunityServer 2.0 (Build: 60217.2664)</generator><item><title>Idle Timeouts in RIA Services Authentication</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/10/28/14665.aspx</link><pubDate>Wed, 28 Oct 2009 11:12:08 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:14665</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/14665.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=14665</wfw:commentRss><description>&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://bryantlikes.com/"&gt;My DasBlog&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://bryantlikes.com/IdleTimeoutsInRIAServicesAuthentication.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt;&lt;p&gt;A &lt;a href="http://forums.silverlight.net/forums/t/138752.aspx"&gt;question came up in the Silverlight Forums&lt;/a&gt; about how to timeout a user when using &lt;a href="http://code.msdn.microsoft.com/RiaServices"&gt;.NET RIA Services&lt;/a&gt;. Since I have implemented this before I thought I would share an approach I used. There might be a better way that is more integrated with the ASP.Net security, but for now this works.&lt;/p&gt;  &lt;p&gt;To start with, you'll need &lt;a href="http://brad_abrams.members.winisp.net/Projects/Silverlight3RTM/MyApp.LiveSite.zip"&gt;the Sample Application&lt;/a&gt; that &lt;a href="http://blogs.msdn.com/brada/archive/2009/10/27/index-for-business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update.aspx"&gt;Brad Abram has been building and blogging about&lt;/a&gt; and you might want to read through &lt;a href="http://blogs.msdn.com/brada/archive/2009/07/22/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-6-poco-and-authentication-provider.aspx"&gt;this post on Authentication in RIA Services&lt;/a&gt; before going any further. Once you have that and can build/run it on your machine you can continue on.&lt;/p&gt;  &lt;p&gt;The security in Brad's example uses a simple membership provider that is using RIA Services FormsAuthentication since it takes a username and password to log in. For our example we will extend the FormsAuthentication and add a timeout to it. Below is my implementation of the FormsWithTimeoutAuthentication class:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span&gt;namespace &lt;/span&gt;MyApp
{
    &lt;span&gt;public class &lt;/span&gt;&lt;span&gt;FormsWithTimeoutAuthentication &lt;/span&gt;: &lt;span&gt;FormsAuthentication
    &lt;/span&gt;{
        &lt;span&gt;private &lt;/span&gt;&lt;span&gt;DispatcherTimer &lt;/span&gt;idleTimer;
        &lt;span&gt;private int &lt;/span&gt;minutesIdle;
        &lt;span&gt;private bool &lt;/span&gt;idle;
        &lt;span&gt;private bool &lt;/span&gt;attached = &lt;span&gt;false&lt;/span&gt;;

        &lt;span&gt;public &lt;/span&gt;FormsWithTimeoutAuthentication()
            : &lt;span&gt;this&lt;/span&gt;(20)
        { }

        &lt;span&gt;public &lt;/span&gt;FormsWithTimeoutAuthentication(&lt;span&gt;int &lt;/span&gt;idleMinutes)
        {
            IdleMinutesBeforeTimeout = idleMinutes;
            idleTimer = &lt;span&gt;new &lt;/span&gt;&lt;span&gt;DispatcherTimer&lt;/span&gt;();
            idleTimer.Interval = &lt;span&gt;TimeSpan&lt;/span&gt;.FromMinutes(1);
            idleTimer.Tick += &lt;span&gt;new &lt;/span&gt;&lt;span&gt;EventHandler&lt;/span&gt;(idleTimer_Tick);
        }

        &lt;span&gt;public int &lt;/span&gt;IdleMinutesBeforeTimeout
        {
            &lt;span&gt;get&lt;/span&gt;;
            &lt;span&gt;set&lt;/span&gt;;
        }

        &lt;span&gt;protected override &lt;/span&gt;&lt;span&gt;LoginResult &lt;/span&gt;EndLogin(&lt;span&gt;IAsyncResult &lt;/span&gt;asyncResult)
        {
            &lt;span&gt;var &lt;/span&gt;result = &lt;span&gt;base&lt;/span&gt;.EndLogin(asyncResult);

            &lt;span&gt;if &lt;/span&gt;(result.LoginSuccess == &lt;span&gt;true&lt;/span&gt;)
            {
                &lt;span&gt;if &lt;/span&gt;(!attached) AttachEvents();
                minutesIdle = 0;
                idleTimer.Start();
            }

            &lt;span&gt;return &lt;/span&gt;result;
        }

        &lt;span&gt;protected override &lt;/span&gt;&lt;span&gt;LogoutResult &lt;/span&gt;EndLogout(&lt;span&gt;IAsyncResult &lt;/span&gt;asyncResult)
        {
            idleTimer.Stop();

            &lt;span&gt;return base&lt;/span&gt;.EndLogout(asyncResult);
        }

        &lt;span&gt;private void &lt;/span&gt;AttachEvents()
        {
            attached = &lt;span&gt;true&lt;/span&gt;;
            &lt;span&gt;Application&lt;/span&gt;.Current.RootVisual.MouseMove += &lt;span&gt;new &lt;/span&gt;&lt;span&gt;MouseEventHandler&lt;/span&gt;(RootVisual_MouseMove);
            &lt;span&gt;Application&lt;/span&gt;.Current.RootVisual.KeyDown += &lt;span&gt;new &lt;/span&gt;&lt;span&gt;KeyEventHandler&lt;/span&gt;(RootVisual_KeyDown);
        }

        &lt;span&gt;private void &lt;/span&gt;RootVisual_KeyDown(&lt;span&gt;object &lt;/span&gt;sender, &lt;span&gt;KeyEventArgs &lt;/span&gt;e)
        {
            idle = &lt;span&gt;false&lt;/span&gt;;
        }

        &lt;span&gt;private void &lt;/span&gt;RootVisual_MouseMove(&lt;span&gt;object &lt;/span&gt;sender, &lt;span&gt;MouseEventArgs &lt;/span&gt;e)
        {
            idle = &lt;span&gt;false&lt;/span&gt;;
        }

        &lt;span&gt;private void &lt;/span&gt;idleTimer_Tick(&lt;span&gt;object &lt;/span&gt;sender, &lt;span&gt;EventArgs &lt;/span&gt;e)
        {
            &lt;span&gt;if &lt;/span&gt;(idle == &lt;span&gt;true&lt;/span&gt;)
            {
                minutesIdle += idleTimer.Interval.Minutes;
                &lt;span&gt;if &lt;/span&gt;(minutesIdle &amp;gt;= IdleMinutesBeforeTimeout)
                {
                    Logout();
                }
            }
            &lt;span&gt;else
            &lt;/span&gt;{
                minutesIdle = 0;
            }
            idle = &lt;span&gt;true&lt;/span&gt;;
        }
    }
}&lt;/pre&gt;

&lt;p&gt;All this class does is add a timer that fires once a minute. If the user has either moved the mouse or hit a key in that minute then they stay logged in. If the user hasn't, then a minute of idle time is added to the idle minute count until the timeout limit is reached. Once that happens the user gets logged out. &lt;/p&gt;

&lt;p&gt;Note that the events are attached to the root visual and don't get attached until the user logs in. This is because the Authentication is created prior to the RootVisual being set. &lt;/p&gt;

&lt;p&gt;Simply add this code to the sample project (linked above) and then change the authentication service in the App.xaml as follows:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Application   
  &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Class&lt;/span&gt;&lt;span&gt;=&amp;quot;MyApp.App&amp;quot;
  &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
  &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
  &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;app&lt;/span&gt;&lt;span&gt;=&amp;quot;clr-namespace:MyApp&amp;quot;
  &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;appsvc&lt;/span&gt;&lt;span&gt;=&amp;quot;clr-namespace:System.Windows.Ria.ApplicationServices;assembly=System.Windows.Ria&amp;quot;  
    &amp;gt;

    &amp;lt;&lt;/span&gt;&lt;span&gt;Application.Resources&lt;/span&gt;&lt;span&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span&gt;ResourceDictionary&lt;/span&gt;&lt;span&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span&gt;ResourceDictionary.MergedDictionaries&lt;/span&gt;&lt;span&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span&gt;ResourceDictionary &lt;/span&gt;&lt;span&gt;Source&lt;/span&gt;&lt;span&gt;=&amp;quot;Assets/Styles.xaml&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span&gt;ResourceDictionary.MergedDictionaries&lt;/span&gt;&lt;span&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span&gt;ResourceDictionary&lt;/span&gt;&lt;span&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span&gt;Application.Resources&lt;/span&gt;&lt;span&gt;&amp;gt;


    &amp;lt;&lt;/span&gt;&lt;span&gt;Application.ApplicationLifetimeObjects&lt;/span&gt;&lt;span&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span&gt;app&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;RiaContext&lt;/span&gt;&lt;span&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span&gt;app&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;RiaContext.Authentication&lt;/span&gt;&lt;span&gt;&amp;gt;
                &lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;span&gt;app&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;FormsWithTimeoutAuthentication &lt;/span&gt;&lt;span&gt;IdleMinutesBeforeTimeout&lt;/span&gt;&lt;/strong&gt;&lt;span&gt;&lt;strong&gt;=&amp;quot;2&amp;quot;/&amp;gt;
&lt;/strong&gt;                &lt;/span&gt;&lt;span&gt;&amp;lt;!--&amp;lt;appsvc:WindowsAuthentication/&amp;gt;--&amp;gt;
            &lt;/span&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;app&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;RiaContext.Authentication&lt;/span&gt;&lt;span&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span&gt;app&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;RiaContext&lt;/span&gt;&lt;span&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span&gt;Application.ApplicationLifetimeObjects&lt;/span&gt;&lt;span&gt;&amp;gt;

&amp;lt;/&lt;/span&gt;&lt;span&gt;Application&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Here I've set the IdleMinutesBeforeTimeout to 2 minutes so that it is easy to test. &lt;/p&gt;

&lt;p&gt;Once you've modified the application, when you run it you will get logged out after the number of minutes you specify in the timeout. There are lots of enhancements that could be made to this simple approach, but this works for most situations.&lt;/p&gt;&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=14665" width="1" height="1"&gt;</description></item><item><title>Silverlight MVP</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/10/19/14637.aspx</link><pubDate>Mon, 19 Oct 2009 09:10:38 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:14637</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/14637.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=14637</wfw:commentRss><description>&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://bryantlikes.com/"&gt;My DasBlog&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://bryantlikes.com/SilverlightMVP.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt;&lt;p&gt;On October 1st I was honored to receive the &lt;a href="https://mvp.support.microsoft.com/"&gt;Microsoft Most Valuable Professional Award&lt;/a&gt; for &lt;a href="http://www.microsoft.com/silverlight"&gt;Silverlight&lt;/a&gt;. I am very excited that I received this award and look forward to continuing my contributions to the &lt;a href="http://silverlight.net/community"&gt;Silverlight Community&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;img src="http://files.bryantlikes.com/Images/mvp.png" /&gt;&lt;/p&gt;  &lt;p&gt;I wasn't the only one to receive this honor as &lt;a href="http://timheuer.com/blog/archive/2009/10/01/new-silverlight-mvp-announcement-october-2009.aspx"&gt;Tim Heuer blogged here&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;As of today (01 OCT 2009) we welcome some new folks to the Silverlight group:&lt;/p&gt;    &lt;ul&gt;     &lt;li&gt;&lt;a href="http://www.cynergysystems.com/blogs/blogs/rick.barraza/"&gt;Rick Barraza&lt;/a&gt; (&lt;a href="http://twitter.com/rickbarraza"&gt;@rickbarraza&lt;/a&gt;)- wicked interactive design/developer with kung-fu XAML skillz &lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.sqlxml.org/BryantLikes"&gt;Bryant Likes&lt;/a&gt; (&lt;a href="http://twitter.com/bryantlikes"&gt;@bryantlikes&lt;/a&gt;)- great contributor to the Silverlight Forums helping others solve their problems! &lt;/li&gt;      &lt;li&gt;&lt;a href="http://85turns.com"&gt;Corey Schuman&lt;/a&gt; (&lt;a href="http://twitter.com/cschuman"&gt;@cschuman&lt;/a&gt;)- UX design/developer in Atlanta doing a bunch of great Silverlight community work &lt;/li&gt;      &lt;li&gt;&lt;a href="http://www.davidezordan.net/blog/"&gt;Davide Zordan&lt;/a&gt; (&lt;a href="http://twitter.com/davidezordan"&gt;@davidezordan&lt;/a&gt;)- over the pond in Italy spreading the Silverlight love! &lt;/li&gt;      &lt;li&gt;&lt;a href="http://www.designwithsilverlight.com/"&gt;Jeff Paries&lt;/a&gt; - Silverlight animation wizard - &lt;a href="http://tinyurl.com/sl3animation"&gt;get his book&lt;/a&gt;! &lt;/li&gt;      &lt;li&gt;&lt;a href="http://nerdplusart.com"&gt;Robby Ingebretsen&lt;/a&gt; (&lt;a href="http://twitter.com/ingebretsen"&gt;@ingebretsen&lt;/a&gt;)- another kung-fu XAML/Blend ninja &lt;/li&gt;      &lt;li&gt;Ambrose Little (&lt;a href="http://twitter.com/AmbroseLittle"&gt;@ambroselittle&lt;/a&gt;)- co-author of &lt;a href="http://tinyurl.com/sl3progref"&gt;Silverlight 3 Programmer Reference&lt;/a&gt; and the man behind &lt;a href="http://quince.infragistics.com"&gt;Quince&lt;/a&gt; (no &lt;a href="http://twitter.com/ambrosesbeard"&gt;@ambrosesbeard&lt;/a&gt; was not awarded) &lt;/li&gt;      &lt;li&gt;&lt;a href="http://www.cnblogs.com/terrylee"&gt;Huijun Li&lt;/a&gt; - helping spread the Silverlight in China overseas! &lt;/li&gt;   &lt;/ul&gt; &lt;/blockquote&gt;  &lt;p&gt;I'm very excited to be a part of the &lt;a href="https://mvp.support.microsoft.com/communities/mvp.aspx?product=1&amp;amp;competency=Silverlight"&gt;Silverlight MVPs group&lt;/a&gt; and look forward to working with them all.&lt;/p&gt;&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=14637" width="1" height="1"&gt;</description></item><item><title>Migrated from Community Server to DasBlog</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/10/17/14630.aspx</link><pubDate>Sat, 17 Oct 2009 13:31:55 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:14630</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/14630.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=14630</wfw:commentRss><description>&lt;p&gt;Just a quick note that I’ve moved my blog from here to &lt;a href="http://bryantlikes.com"&gt;http://bryantlikes.com&lt;/a&gt;. All the posts here should automatically redirect you to the new blog and the feeds should all migrate automatically. See you at my new site!&lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=14630" width="1" height="1"&gt;</description></item><item><title>Behaviors vs Subclassing in Silverlight</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/09/30/14550.aspx</link><pubDate>Wed, 30 Sep 2009 13:42:54 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:14550</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/14550.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=14550</wfw:commentRss><description>&lt;p&gt;As a Silverlight developer, when you want to add functionality to an existing control, you have two main options as I see it (if you want to get reuse from your code). You can either subclass the control or, as of Silverlight 3,&amp;#160; you can write a behavior for it. For example, one of the requests for the current Silverlight application that I’ve been working on was to have the TextBox select all the text when you tabbed to it or clicked in it. We can easily add this functionality using both of the above methods:&lt;/p&gt;  &lt;p&gt;Here is how this could be done using subclassing:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SelectAllTextBox : TextBox 
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; SelectAllTextBox()
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.GotFocus += &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedEventHandler(TextBox_GotFocus);
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; TextBox_GotFocus(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.SelectAll();
    }
}&lt;/pre&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;And here is how you would write this as a behavior:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SelectAllBehavior : Behavior&amp;lt;TextBox&amp;gt;
{
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnAttached()
    {
        &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnAttached();
        AssociatedObject.GotFocus += &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedEventHandler(AssociatedObject_GotFocus);
    }

    &lt;span class="kwrd"&gt;void&lt;/span&gt; AssociatedObject_GotFocus(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
    {
        ((TextBox)sender).SelectAll();
    }
}&lt;/pre&gt;

&lt;p&gt;The behavior has one more line of code and the added requirement of adding a reference to System.Windows.Interactivity.dll from the Blend 3 SDK. The bigger difference is how the code looks in our view when we add the control to it. &lt;/p&gt;

&lt;p&gt;The subclassed control looks like (where ctrls is the controls namespace of our subclassed control):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;ctrls&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;SelectAllTextBox &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&amp;quot;{&lt;/span&gt;&lt;span&gt;Binding &lt;/span&gt;&lt;span&gt;MyText&lt;/span&gt;&lt;span&gt;}&amp;quot; /&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;And the behavior looks like (where i is the System.Windows.Interactivity namespace and b is our behavior’s namespace):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;TextBox &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&amp;quot;{&lt;/span&gt;&lt;span&gt;Binding &lt;/span&gt;&lt;span&gt;MyText&lt;/span&gt;&lt;span&gt;}&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Interaction.Behaviors&lt;/span&gt;&lt;span&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span&gt;b&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;SelectAllBehavior &lt;/span&gt;&lt;span&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Interaction.Behaviors&lt;/span&gt;&lt;span&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span&gt;TextBox&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Obviously the behavior is more verbose in this case than the subclassed approach.&lt;/p&gt;

&lt;p&gt;Since both of these approaches work, which is the better approach? I think the subclassing is the easier approach, but I think the behavior would be the recommended approach. The reason is that I can build my SelectAll behavior today and then down the road build a different behavior and then selectively apply them to my TextBoxes as appropriate. However, if use the subclass approach I would automatically get the new behavior on all my controls which might not be what I wanted. It also means that if someone builds a better TextBox that I want to use that I would have to try to subclass that control, but with the behavior I could just apply it to the new control. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;A couple of quick updates. First, &lt;a href="http://twitter.com/a7an/status/4501862233"&gt;Alan Le pointed out&lt;/a&gt; that it depends on reuse. Obviously if you had to add the behavior to 20 TextBoxes it would take more time to use the behavior. However, Blend makes this a lot easier. Secondly, Brian mentioned in the comments that you could also use an attached property to do this so I thought I would quickly show what that might look like.&lt;/p&gt;

&lt;p&gt;The code for the attached property would be:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TextBoxProperties
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty SelectAllProperty =
        DependencyProperty.RegisterAttached(&lt;span class="str"&gt;&amp;quot;SelectAll&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;bool&lt;/span&gt;), 
        &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TextBoxProperties), &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyMetadata(&lt;span class="kwrd"&gt;false&lt;/span&gt;, OnSelectAllChanged));

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetSelectAll(DependencyObject o, &lt;span class="kwrd"&gt;bool&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)
    {
        o.SetValue(SelectAllProperty, &lt;span class="kwrd"&gt;value&lt;/span&gt;);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; GetSelectAll(DependencyObject o)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)o.GetValue(SelectAllProperty);
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnSelectAllChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; ((&lt;span class="kwrd"&gt;bool&lt;/span&gt;)e.NewValue == &lt;span class="kwrd"&gt;true&lt;/span&gt;)
        {
            ((TextBox)d).GotFocus += &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedEventHandler(TextBoxProperties_GotFocus);
        }
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; TextBoxProperties_GotFocus(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
    {
        ((TextBox)sender).SelectAll();
    }
}&lt;/pre&gt;

&lt;p&gt;And the Xaml would look like:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;TextBox &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&amp;quot;{&lt;/span&gt;&lt;span&gt;Binding &lt;/span&gt;&lt;span&gt;MyText&lt;/span&gt;&lt;span&gt;}&amp;quot; ctrls:TextBoxProperties.SelectAll=&lt;span&gt;&amp;quot;true&lt;/span&gt;&lt;span&gt;&amp;quot; /&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;I still think the Behavior is the best method to use since (at least in this case) we are just trying to add a behavior to the TextBox, not add significant functionality. The attached property also doesn’t feel right to me, but it does work just fine. Ultimately it comes down to preference and what method you like to use. :)&lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=14550" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category></item><item><title>A “Default Command” for Silverlight</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/09/28/14548.aspx</link><pubDate>Mon, 28 Sep 2009 19:23:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:14548</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/14548.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=14548</wfw:commentRss><description>&lt;p&gt;The current Silverlight application that I&amp;rsquo;m building has a Login view. One of the things that bugged me when I started using the application is that you would have to click the Login button after typing your password. I wanted to duplicate the default button behavior of HTML forms where when you hit the enter key it would trigger the default button on the form. I did some googling on the subject and came across &lt;a href="http://www.cauldwell.net/patrick/blog/ALdquodefaultButtonrdquoInSilverlight.aspx"&gt;this post by Patrick Cauldwell&lt;/a&gt; which is one way to solve the problem. However, in my case I had a username Textbox, a password Passwordbox, and a company Combobox and didn&amp;rsquo;t want to specify the button for each control. &lt;/p&gt;
&lt;p&gt;So I create a simple solution of creating a content control that attaches to all the KeyUp events of all the child FrameworkElements in the content. To do this I used the FindChildren&amp;lt;T&amp;gt; extension method from the &lt;a href="http://www.avanade.com"&gt;Avanade Silverlight Accelerator&lt;/a&gt; which is a toolkit we use internally at Avanade to speed up Silverlight development. The ContentControl exposes a DefaultCommand property which you then bind to the ICommand property on your ViewModel. &lt;/p&gt;
&lt;p&gt;Below is a trimmed down example of the Login view. I&amp;rsquo;m using a variant of the RelayCommand/DelegateCommand as the LoginCommand here (see &lt;a href="http://blog.galasoft.ch/archive/2009/09/26/using-relaycommands-in-silverlight-and-wpf.aspx"&gt;Laurent&amp;rsquo;s post on the RelayCommand&lt;/a&gt; for a good overview of Commands in Silverlight). &lt;/p&gt;
&lt;pre class="code"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;ctrls&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;FormControl &lt;/span&gt;&lt;span&gt;DefaultCommand&lt;/span&gt;&lt;span&gt;="{&lt;/span&gt;&lt;span&gt;Binding &lt;/span&gt;&lt;span&gt;LoginCommand&lt;/span&gt;&lt;span&gt;}"&amp;gt;&lt;/span&gt;&lt;span&gt;   
&lt;/span&gt;&lt;span&gt;  &amp;lt;&lt;/span&gt;&lt;span&gt;TextBox &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;="{&lt;/span&gt;&lt;span&gt;Binding &lt;/span&gt;&lt;span&gt;Username&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;Mode&lt;/span&gt;&lt;span&gt;=TwoWay}" &lt;/span&gt;&lt;span&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span&gt;PasswordBox &lt;/span&gt;&lt;span&gt;Password&lt;/span&gt;&lt;span&gt;="{&lt;/span&gt;&lt;span&gt;Binding &lt;/span&gt;&lt;span&gt;Password&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;Mode&lt;/span&gt;&lt;span&gt;=TwoWay}" &lt;/span&gt;&lt;span&gt;/&amp;gt;
&lt;/span&gt;&lt;span&gt;  &amp;lt;&lt;/span&gt;&lt;span&gt;Button &lt;/span&gt;&lt;span&gt;IsEnabled&lt;/span&gt;&lt;span&gt;="{&lt;/span&gt;&lt;span&gt;Binding &lt;/span&gt;&lt;span&gt;LoginEnabled&lt;/span&gt;&lt;span&gt;}" 
          &lt;/span&gt;&lt;span&gt;cmds&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;ButtonClickCommand.Command&lt;/span&gt;&lt;span&gt;="{&lt;/span&gt;&lt;span&gt;Binding &lt;/span&gt;&lt;span&gt;LoginCommand&lt;/span&gt;&lt;span&gt;}" 
          &lt;/span&gt;&lt;span&gt;Content&lt;/span&gt;&lt;span&gt;="Login" /&amp;gt;
&lt;/span&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;ctrls&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;FormControl&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;There are many other things you could add to this but this is all the functionality that I needed and I decided to keep it simple. Download the class file (plus the extension method) below. Let me know if you find it useful!&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:8bbfa932-331f-42e7-9bad-0990c0879062"&gt;
&lt;div&gt;&lt;a target="_self" href="http://files.bryantlikes.com/Code/FormControl.cs"&gt;FormControl.cs&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=14548" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1118.aspx">Avanade</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category></item><item><title>Faking the Initialized Event in Silverlight</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/03/24/13251.aspx</link><pubDate>Tue, 24 Mar 2009 22:24:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:13251</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/13251.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=13251</wfw:commentRss><description>&lt;p&gt;This is another nugget of gold gleaned from the &lt;a href="http://videos.visitmix.com/MIX09/06W"&gt;Climbing Mt Avalon workshop&lt;/a&gt;, although I believe this one came from &lt;a href="http://twitter.com/JonathanRuss"&gt;Jonathan Russ&lt;/a&gt;. He was talking about a bunch of threading tricks in WPF and showed how if you wanted to run some code after everything was initialized you could use the BeginInvoke method of the Dispatcher object. Since there are many places in my code where I want to execute something when the control loads, but only once (since the loaded event gets fired whenever the object gets re-added to the visual tree) I end up writing a lot of code like:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Page : UserControl
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; initialized = &lt;span class="kwrd"&gt;false&lt;/span&gt;;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Page()
    {
        InitializeComponent();
        Loaded += &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedEventHandler(Page_Loaded);
    }

    &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Loaded(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!initialized)
        {
            &lt;span class="rem"&gt;// do some initialization work&lt;/span&gt;
            initialized = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        }
    }

}&lt;/pre&gt;
&lt;p&gt;This works, but it isn&amp;rsquo;t perfect and there seems to be a lot of issues with the &lt;a href="http://blogs.msdn.com/silverlight_sdk/archive/2008/10/24/loaded-event-timing-in-silverlight.aspx"&gt;timing&lt;/a&gt; &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.loaded(VS.95).aspx"&gt;of&lt;/a&gt; &lt;a href="http://silverlight.net/forums/p/40306/115105.aspx#115105"&gt;the&lt;/a&gt; &lt;a href="http://blogs.msdn.com/devdave/archive/2008/10/11/control-lifecycle.aspx"&gt;loaded event&lt;/a&gt;. So based on what Jonathan was saying, you could instead just put a call into BeginInvoke in the contructor like so:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Page : UserControl
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Page()
    {
        InitializeComponent();
        Dispatcher.BeginInvoke(Initialized);
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialized()
    {
        &lt;span class="rem"&gt;// do some initialization work&lt;/span&gt;
    }
}&lt;/pre&gt;
&lt;p&gt;

So what is this actually doing? BeginInvoke puts a message in the message pump that is running under the covers of everything (note: I&amp;rsquo;m not a C++ programming so I don&amp;rsquo;t really fully understand &lt;a href="http://en.wikipedia.org/wiki/Event_loop"&gt;message pumps&lt;/a&gt; so this is an over simplification). Because it is last in line in the queue of messages to process, it gets executed after all the other initialization code which has already lined up. If you debug this you will see it actually gets called after the Loaded event gets called. However, this code is the first thing to execute once everything has been loaded and setup which is usually when I want my code to execute. &lt;/p&gt;
&lt;p&gt;So this is a much better way to handle initialization code since you aren&amp;rsquo;t adding event handlers that really only need to fire once and it executes once everything is fully initialized.&lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=13251" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category></item><item><title>Animation Hack Using Attached Properties in Silverlight</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/03/23/13219.aspx</link><pubDate>Mon, 23 Mar 2009 20:27:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:13219</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/13219.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=13219</wfw:commentRss><description>&lt;p&gt;In &lt;a href="/bryantlikes/archive/2009/03/18/styling-hack-using-attached-properties-in-silverlight.aspx"&gt;my last post I blogged about using Attached Properties&lt;/a&gt; to get around the limitation that only Dependency Properties can be animated. One astute commented noted that he was guessing this could be applied to animations as well and the answer is yet it can. However, it requires one extra step that makes it a little less appealing. &lt;/p&gt;
&lt;p&gt;Also I mentioned in my last post, I got this idea from the Climbing Mt Avalon workshop at MIX which has &lt;a href="http://videos.visitmix.com/MIX09/06W"&gt;now been posted online&lt;/a&gt; and I would recommend watching if you&amp;rsquo;re doing Silverlight or WPF work. And now on to the code&amp;hellip;&lt;/p&gt;
&lt;p&gt;Typically if you want to animating something like the width of a grid in a column that isn&amp;rsquo;t animatable either because it isn&amp;rsquo;t a double, color, or another easily animatable type, then you would declare a dependency property on your own host class, usually a UserControl, and then animate that instead. A &lt;a href="http://programmerpayback.com/2008/11/08/animate-collapsing-a-grid-column-or-row-in-silverlight/"&gt;good example is this blog post&lt;/a&gt; on the subject which is what I&amp;rsquo;ve referred to many times. &lt;/p&gt;
&lt;p&gt;However, if we take the attached property route instead of putting the code in our user control, we could declare our own attached property to do the work for us. Here is a simple example:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span&gt;public static class &lt;/span&gt;&lt;span&gt;Attachments
&lt;/span&gt;{

    &lt;span&gt;public static readonly &lt;/span&gt;&lt;span&gt;DependencyProperty &lt;/span&gt;ColumnWidthProperty =
            &lt;span&gt;DependencyProperty&lt;/span&gt;.RegisterAttached(&lt;span&gt;"ColumnWidth"&lt;/span&gt;, 
            &lt;span&gt;typeof&lt;/span&gt;(&lt;span&gt;double&lt;/span&gt;), &lt;span&gt;typeof&lt;/span&gt;(&lt;span&gt;Attachments&lt;/span&gt;), 
            &lt;span&gt;new &lt;/span&gt;&lt;span&gt;PropertyMetadata&lt;/span&gt;(
                &lt;span&gt;new &lt;/span&gt;&lt;span&gt;PropertyChangedCallback&lt;/span&gt;(OnColumnWidthChanged)));

    &lt;span&gt;public static void &lt;/span&gt;SetColumnWidth(&lt;span&gt;DependencyObject &lt;/span&gt;o, &lt;span&gt;double &lt;/span&gt;value)
    {
        o.SetValue(ColumnWidthProperty, value);
    }

    &lt;span&gt;public static double &lt;/span&gt;GetColumnWidth(&lt;span&gt;DependencyObject &lt;/span&gt;o)
    {
        &lt;span&gt;return &lt;/span&gt;(&lt;span&gt;double&lt;/span&gt;)o.GetValue(ColumnWidthProperty);
    }

    &lt;span&gt;private static void &lt;/span&gt;OnColumnWidthChanged(&lt;span&gt;DependencyObject &lt;/span&gt;d, &lt;span&gt;DependencyPropertyChangedEventArgs &lt;/span&gt;e)
    {
        ((&lt;span&gt;ColumnDefinition&lt;/span&gt;)d).Width = &lt;span&gt;new &lt;/span&gt;&lt;span&gt;GridLength&lt;/span&gt;((&lt;span&gt;double&lt;/span&gt;)e.NewValue);
    }

}&lt;/pre&gt;
&lt;p&gt;Once we have this code we can now simply animate the attached property like so:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;UserControl &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Class&lt;/span&gt;&lt;span&gt;="SilverlightApplication1.MainPage"
    &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;="http://schemas.microsoft.com/winfx/2006/xaml"
    &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;local&lt;/span&gt;&lt;span&gt;="clr-namespace:SilverlightApplication1"
    &lt;/span&gt;&lt;span&gt;Width&lt;/span&gt;&lt;span&gt;="400" &lt;/span&gt;&lt;span&gt;Height&lt;/span&gt;&lt;span&gt;="300"&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span&gt;Grid &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;="LayoutRoot" &lt;/span&gt;&lt;span&gt;Background&lt;/span&gt;&lt;span&gt;="White"&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span&gt;Grid.Resources&lt;/span&gt;&lt;span&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span&gt;Storyboard &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;="expandBlue"&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span&gt;DoubleAnimation &lt;/span&gt;&lt;span&gt;Storyboard.TargetName&lt;/span&gt;&lt;span&gt;="blue"
                                 &lt;/span&gt;&lt;span&gt;To&lt;/span&gt;&lt;span&gt;="300" &lt;/span&gt;&lt;span&gt;Duration&lt;/span&gt;&lt;span&gt;="0:0:1" /&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span&gt;DoubleAnimation &lt;/span&gt;&lt;span&gt;Storyboard.TargetName&lt;/span&gt;&lt;span&gt;="red"
                                 &lt;/span&gt;&lt;span&gt;To&lt;/span&gt;&lt;span&gt;="100" &lt;/span&gt;&lt;span&gt;Duration&lt;/span&gt;&lt;span&gt;="0:0:1" /&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span&gt;Storyboard&lt;/span&gt;&lt;span&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span&gt;Storyboard &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;="expandRed"&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span&gt;DoubleAnimation &lt;/span&gt;&lt;span&gt;Storyboard.TargetName&lt;/span&gt;&lt;span&gt;="red"
                                 &lt;/span&gt;&lt;span&gt;To&lt;/span&gt;&lt;span&gt;="300" &lt;/span&gt;&lt;span&gt;Duration&lt;/span&gt;&lt;span&gt;="0:0:1" /&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span&gt;DoubleAnimation &lt;/span&gt;&lt;span&gt;Storyboard.TargetName&lt;/span&gt;&lt;span&gt;="blue"
                                 &lt;/span&gt;&lt;span&gt;To&lt;/span&gt;&lt;span&gt;="100" &lt;/span&gt;&lt;span&gt;Duration&lt;/span&gt;&lt;span&gt;="0:0:1" /&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span&gt;Storyboard&lt;/span&gt;&lt;span&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span&gt;Grid.Resources&lt;/span&gt;&lt;span&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span&gt;ColumnDefinition &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;="blue" &lt;/span&gt;&lt;span&gt;local&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Attachments.ColumnWidth&lt;/span&gt;&lt;span&gt;="200" /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span&gt;ColumnDefinition &lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;="red" &lt;/span&gt;&lt;span&gt;local&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;Attachments.ColumnWidth&lt;/span&gt;&lt;span&gt;="200"/&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span&gt;Rectangle &lt;/span&gt;&lt;span&gt;Grid.Column&lt;/span&gt;&lt;span&gt;="0" &lt;/span&gt;&lt;span&gt;Fill&lt;/span&gt;&lt;span&gt;="Blue" &lt;/span&gt;&lt;span&gt;MouseLeftButtonDown&lt;/span&gt;&lt;span&gt;="Blue_MouseLeftButtonDown" /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span&gt;Rectangle &lt;/span&gt;&lt;span&gt;Grid.Column&lt;/span&gt;&lt;span&gt;="1" &lt;/span&gt;&lt;span&gt;Fill&lt;/span&gt;&lt;span&gt;="Red" &lt;/span&gt;&lt;span&gt;MouseLeftButtonDown&lt;/span&gt;&lt;span&gt;="Red_MouseLeftButtonDown"/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span&gt;Grid&lt;/span&gt;&lt;span&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span&gt;UserControl&lt;/span&gt;&lt;span&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunately if you try the above code (after adding in the mouse event handlers) it won&amp;rsquo;t work. Why not? Well there seems to be an issue with animating custom attached properties when setting the target property directly in code (actually you&amp;rsquo;ll notice I left that out above. However, there is a way around it which I found over on &lt;a href="http://blogs.msdn.com/edmaia/archive/2008/10/16/animating-custom-attached-properties-in-sl2.aspx"&gt;Ed&amp;rsquo;s blog which is to set the target property in code&lt;/a&gt;. So here is the code behind with the work around:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span&gt;public partial class &lt;/span&gt;&lt;span&gt;MainPage &lt;/span&gt;: &lt;span&gt;UserControl
&lt;/span&gt;{
    &lt;span&gt;public &lt;/span&gt;MainPage()
    {
        InitializeComponent();
        &lt;span&gt;Storyboard&lt;/span&gt;.SetTargetProperty(expandBlue.Children[0], &lt;span&gt;new &lt;/span&gt;&lt;span&gt;PropertyPath&lt;/span&gt;(&lt;span&gt;Attachments&lt;/span&gt;.ColumnWidthProperty));
        &lt;span&gt;Storyboard&lt;/span&gt;.SetTargetProperty(expandBlue.Children[1], &lt;span&gt;new &lt;/span&gt;&lt;span&gt;PropertyPath&lt;/span&gt;(&lt;span&gt;Attachments&lt;/span&gt;.ColumnWidthProperty));
        &lt;span&gt;Storyboard&lt;/span&gt;.SetTargetProperty(expandRed.Children[0], &lt;span&gt;new &lt;/span&gt;&lt;span&gt;PropertyPath&lt;/span&gt;(&lt;span&gt;Attachments&lt;/span&gt;.ColumnWidthProperty));
        &lt;span&gt;Storyboard&lt;/span&gt;.SetTargetProperty(expandRed.Children[1], &lt;span&gt;new &lt;/span&gt;&lt;span&gt;PropertyPath&lt;/span&gt;(&lt;span&gt;Attachments&lt;/span&gt;.ColumnWidthProperty));
    }

    &lt;span&gt;private void &lt;/span&gt;Blue_MouseLeftButtonDown(&lt;span&gt;object &lt;/span&gt;sender, &lt;span&gt;MouseButtonEventArgs &lt;/span&gt;e)
    {
        expandBlue.Begin();
    }

    &lt;span&gt;private void &lt;/span&gt;Red_MouseLeftButtonDown(&lt;span&gt;object &lt;/span&gt;sender, &lt;span&gt;MouseButtonEventArgs &lt;/span&gt;e)
    {
        expandRed.Begin();
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Once we set the target property via code, then everything works great. However, that is a pain and makes things a lot less clean. But still I think this is a useful approach to animating the properties that are not easily animatable.&lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=13219" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1402.aspx">UX</category></item><item><title>Styling Hack Using Attached Properties in Silverlight</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/03/18/13086.aspx</link><pubDate>Wed, 18 Mar 2009 22:08:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:13086</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/13086.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=13086</wfw:commentRss><description>&lt;p&gt;I need to find the forum post where this question was asked, but I&amp;rsquo;ll have to do that later since I&amp;rsquo;m at MIX09 and searching the forums is low on my list. But I wanted to share a cool hack that I came across in the &lt;a href="http://live.visitmix.com/Agenda/Workshops.aspx#hiking-mt-avalon"&gt;Climbing Mt Avalon&lt;/a&gt; (it was definitely a climb, not a hike).&amp;nbsp; One of the many cool things that was shared was a tidbit by &lt;a href="http://blogs.msdn.com/jaimer/"&gt;Jaime Rodriguez&lt;/a&gt; about using Attached Properties. &lt;/p&gt;
&lt;p&gt;The question in the forums was how you can style the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.verticalscrollbarvisibility(vs.95).aspx"&gt;VerticalScrollBarVisibility&lt;/a&gt; property on a TextBox. The problem is that since this property isn&amp;rsquo;t a &lt;a href="http://msdn.microsoft.com/en-us/library/cc221408(VS.95).aspx"&gt;DependencyProperty&lt;/a&gt;&amp;nbsp; so it can&amp;rsquo;t be styled. You can test this out by trying the following Xaml:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet"&gt;
&lt;pre&gt;&lt;span id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;UserControl x:Class=&lt;span&gt;"Attachment.Page"&lt;/span&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum2"&gt;   2:&lt;/span&gt;     xmlns=&lt;span&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; &lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum3"&gt;   3:&lt;/span&gt;     xmlns:x=&lt;span&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum4"&gt;   4:&lt;/span&gt;     Width=&lt;span&gt;"400"&lt;/span&gt; Height=&lt;span&gt;"300"&lt;/span&gt;&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum5"&gt;   5:&lt;/span&gt;     &amp;lt;UserControl.Resources&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum6"&gt;   6:&lt;/span&gt;         &amp;lt;Style TargetType=&lt;span&gt;"TextBox"&lt;/span&gt; x:Key=&lt;span&gt;"test"&lt;/span&gt;&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum7"&gt;   7:&lt;/span&gt;             &amp;lt;Setter Property=&lt;span&gt;"FontSize"&lt;/span&gt; Value=&lt;span&gt;"24"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum8"&gt;   8:&lt;/span&gt;             &amp;lt;Setter Property=&lt;span&gt;"VerticalScrollBarVisibility"&lt;/span&gt; Value=&lt;span&gt;"Visible"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum9"&gt;   9:&lt;/span&gt;         &amp;lt;/Style&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum10"&gt;  10:&lt;/span&gt;     &amp;lt;/UserControl.Resources&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum11"&gt;  11:&lt;/span&gt;     &amp;lt;Grid x:Name=&lt;span&gt;"LayoutRoot"&lt;/span&gt; Background=&lt;span&gt;"White"&lt;/span&gt;&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum12"&gt;  12:&lt;/span&gt;      &amp;lt;TextBox Text=&lt;span&gt;"This is a test"&lt;/span&gt; Style=&lt;span&gt;"{StaticResource test}"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum13"&gt;  13:&lt;/span&gt;     &amp;lt;/Grid&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum14"&gt;  14:&lt;/span&gt; &amp;lt;/UserControl&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If you try to run this it will fail. So how can we set this property in style? Well, a trick you can use is to set your own attached property and then have the property set the VerticalScrollBarVisibility property on the TextBox for you. Here is a very quick example that I cooked up (using &lt;a href="http://blog.nerdplusart.com/archives/silverlight-code-snippets"&gt;Robby&amp;rsquo;s code snippet&lt;/a&gt;):&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet"&gt;
&lt;pre&gt;&lt;span id="lnum1"&gt;   1:&lt;/span&gt; &lt;span&gt;namespace&lt;/span&gt; Attachment&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; Attachments&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;readonly&lt;/span&gt; DependencyProperty MyVsbvProperty =&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum6"&gt;   6:&lt;/span&gt;             DependencyProperty.RegisterAttached(&lt;span&gt;"MyVsbv"&lt;/span&gt;, &lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum7"&gt;   7:&lt;/span&gt;                 &lt;span&gt;typeof&lt;/span&gt;(ScrollBarVisibility), &lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum8"&gt;   8:&lt;/span&gt;                 &lt;span&gt;typeof&lt;/span&gt;(Attachments), &lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum9"&gt;   9:&lt;/span&gt;                 &lt;span&gt;new&lt;/span&gt; PropertyMetadata(OnMyVsbvChanged));&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum10"&gt;  10:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; SetMyVsbv(DependencyObject o, ScrollBarVisibility &lt;span&gt;value&lt;/span&gt;)&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum12"&gt;  12:&lt;/span&gt;         {&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum13"&gt;  13:&lt;/span&gt;             o.SetValue(MyVsbvProperty, &lt;span&gt;value&lt;/span&gt;);&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum14"&gt;  14:&lt;/span&gt;         }&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum15"&gt;  15:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum16"&gt;  16:&lt;/span&gt;         &lt;span&gt;public&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; ScrollBarVisibility GetMyVsbv(DependencyObject o)&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum17"&gt;  17:&lt;/span&gt;         {&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum18"&gt;  18:&lt;/span&gt;             &lt;span&gt;return&lt;/span&gt; (ScrollBarVisibility)o.GetValue(MyVsbvProperty);&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum19"&gt;  19:&lt;/span&gt;         }&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum20"&gt;  20:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum21"&gt;  21:&lt;/span&gt;         &lt;span&gt;private&lt;/span&gt; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;void&lt;/span&gt; OnMyVsbvChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum22"&gt;  22:&lt;/span&gt;         {&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum23"&gt;  23:&lt;/span&gt;             ((TextBox)d).VerticalScrollBarVisibility = (ScrollBarVisibility)e.NewValue;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum24"&gt;  24:&lt;/span&gt;         }&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum25"&gt;  25:&lt;/span&gt;     }&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum26"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Very unintuitive name and my casts could be bad since there are no type checks, just an example. So here when the attached property is changed we change the property on the TextBox that the property is declared on. So if we change our style to use the attached property instead of the actual property it will work: &lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet"&gt;
&lt;pre&gt;&lt;span id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;UserControl x:Class=&lt;span&gt;"Attachment.Page"&lt;/span&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum2"&gt;   2:&lt;/span&gt;     xmlns=&lt;span&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; &lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum3"&gt;   3:&lt;/span&gt;     xmlns:x=&lt;span&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum4"&gt;   4:&lt;/span&gt;     xmlns:local=&lt;span&gt;"clr-namespace:Attachment"&lt;/span&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum5"&gt;   5:&lt;/span&gt;     Width=&lt;span&gt;"400"&lt;/span&gt; Height=&lt;span&gt;"300"&lt;/span&gt;&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum6"&gt;   6:&lt;/span&gt;     &amp;lt;UserControl.Resources&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum7"&gt;   7:&lt;/span&gt;         &amp;lt;Style TargetType=&lt;span&gt;"TextBox"&lt;/span&gt; x:Key=&lt;span&gt;"test"&lt;/span&gt;&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum8"&gt;   8:&lt;/span&gt;             &amp;lt;Setter Property=&lt;span&gt;"FontSize"&lt;/span&gt; Value=&lt;span&gt;"24"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum9"&gt;   9:&lt;/span&gt;             &amp;lt;Setter Property=&lt;span&gt;"local:Attachments.MyVsbv"&lt;/span&gt; Value=&lt;span&gt;"Visible"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum10"&gt;  10:&lt;/span&gt;         &amp;lt;/Style&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum11"&gt;  11:&lt;/span&gt;     &amp;lt;/UserControl.Resources&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum12"&gt;  12:&lt;/span&gt;     &amp;lt;Grid x:Name=&lt;span&gt;"LayoutRoot"&lt;/span&gt; Background=&lt;span&gt;"White"&lt;/span&gt;&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum13"&gt;  13:&lt;/span&gt;                 &amp;lt;TextBox Text=&lt;span&gt;"This is a test"&lt;/span&gt; Style=&lt;span&gt;"{StaticResource test}"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum14"&gt;  14:&lt;/span&gt;             &amp;lt;/Grid&amp;gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span id="lnum15"&gt;  15:&lt;/span&gt; &amp;lt;/UserControl&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So there you have it. If you need to style a property on a control that isn&amp;rsquo;t a dependency property you can use this method to get around that limitation. There are a bunch of other uses for this that I&amp;rsquo;ll be blogging when I have another minute. &lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=13086" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category></item><item><title>Silverlight Streaming Utility Classes</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/03/11/12919.aspx</link><pubDate>Wed, 11 Mar 2009 21:36:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:12919</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/12919.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=12919</wfw:commentRss><description>&lt;p&gt;Yesterday I was working through &lt;a href="http://silverlight.net/forums/t/78284.aspx"&gt;another question in the Silverlight Forums&lt;/a&gt; about how to upload video to &lt;a href="http://silverlight.live.com"&gt;Silverlight Streaming&lt;/a&gt; via code. At first I tried to reference &lt;a href="http://www.codeplex.com/videoshow"&gt;the Video.Show application&lt;/a&gt;, but there is a lot of code there and it doesn&amp;rsquo;t help if you just want to upload a bunch of videos to the same application. So I ended up taking some of the code from Video.Show and some of the code from &lt;a href="http://msdn.microsoft.com/en-us/library/bb851621.aspx"&gt;the SDK/API&lt;/a&gt; and created a very simple Utility class to help with the process. &lt;/p&gt;
&lt;p&gt;You can &lt;a href="http://code.msdn.microsoft.com/SlStreamingUtils"&gt;download the code on the Code Gallery site&lt;/a&gt;. It is very simple in that there is no error handling and I didn&amp;rsquo;t create a Silverlight version yet. I did implement GET, POST, PUT, MKCOL, and DELETE as well as creating the functionality to package a bunch of videos into a single zip which can be posted all at once. &lt;/p&gt;
&lt;p&gt;A few examples from the code, first creating a directory and PUTting a file in it:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;WebDavClient client = &lt;span class="kwrd"&gt;new&lt;/span&gt; WebDavClient(&lt;span class="str"&gt;"Your AppID"&lt;/span&gt;, &lt;span class="str"&gt;"Your Key"&lt;/span&gt;); 
&lt;span class="rem"&gt;// get those from http://silverlight.live.com&lt;/span&gt;
 
client.CreateFolder(&lt;span class="str"&gt;"MyVideos"&lt;/span&gt;);
client.PutFile(&lt;span class="str"&gt;"MyVideos"&lt;/span&gt;,&lt;span class="str"&gt;"C:\\videos\reallyCoolVideo.wmv"&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;


&lt;/p&gt;
&lt;p&gt;Next, packaging up a bunch of videos and POSTing the zip as an application:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;WebDavClient client = &lt;span class="kwrd"&gt;new&lt;/span&gt; WebDavClient(&lt;span class="str"&gt;"Your AppID"&lt;/span&gt;, &lt;span class="str"&gt;"Your Key"&lt;/span&gt;); 
&lt;span class="rem"&gt;// get those from http://silverlight.live.com&lt;/span&gt;
 
client.PackageAndPostFiles(&lt;span class="str"&gt;"MyVideos"&lt;/span&gt;,&lt;span class="str"&gt;"C:\\videos\firstCoolVideo.wmv"&lt;/span&gt;,&lt;span class="str"&gt;"C:\\videos\anothercoolVideo.wmv"&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;


&lt;/p&gt;
&lt;p&gt;Let me know if you&amp;rsquo;d like to see a Silverlight version (be easy to implement) or if there are any other features you&amp;rsquo;d like added. &lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;div class="wlWriterHeaderFooter"&gt;&lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;&lt;/a&gt;&lt;/div&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=12919" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category></item><item><title>Debugging a Remotely Hosted Silverlight App</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/03/10/12901.aspx</link><pubDate>Tue, 10 Mar 2009 16:32:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:12901</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/12901.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=12901</wfw:commentRss><description>&lt;p&gt;This question has come up in the &lt;a href="http://silverlight.net/forums/t/78511.aspx"&gt;forums a few times&lt;/a&gt; so I thought it would be worth a blog post. Most people are pretty familiar with debugging a Silverlight application running locally during development, but what people many times don&amp;rsquo;t realize is that you can also attach your debugger to a xap file that is hosted remotely. &lt;a href="http://msdn.microsoft.com/en-us/library/cc838267(VS.95).aspx"&gt;This MSDN article&lt;/a&gt; touches on this briefly, but doesn&amp;rsquo;t really go into details on how it works. &lt;/p&gt;
&lt;p&gt;The important thing to understand about Silverlight is that it runs the .NET code on the client machine, not on the server. The code runs in the browser process, so if you&amp;rsquo;re going to debug it you need to attach to that process. The one caveat is that the xap on the server must be the same as the compiled xap on your development machine. In other words, you can&amp;rsquo;t debug the remote xap after you&amp;rsquo;ve made changes locally and haven&amp;rsquo;t deployed them.&lt;/p&gt;
&lt;p&gt;As an example I will demonstrate remotely debugging the &lt;a href="http://www.codeplex.com/Twilight"&gt;Twilight badge&lt;/a&gt; on my blog. &lt;/p&gt;
&lt;p&gt;First I open the Twilight.sln and since I&amp;rsquo;ve made a few changes in the last week I&amp;rsquo;ll deploy the latest xap file from my project to my server at &lt;a href="/wpfe/twilight.xap"&gt;http://blogs.sqlxml.org/wpfe/twilight.xap&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Next, now that I am sure the xap file on the server has the same code as my solution, I can set a breakpoint on Line 36 (using version 1.5.2) where the Twitter javascript callback calls into Silverlight with the latest list of tweets:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;a href="http://files.bryantlikes.com/Images/image_14047933.png"&gt;&lt;img height="112" width="531" src="http://files.bryantlikes.com/Images/image_thumb_0CE53CBB.png" alt="image" border="0" title="image" /&gt;&lt;/a&gt; &lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now instead of hitting F5 to start debugging my application, I&amp;rsquo;ll open a new instance of Internet Explorer (or you could use Firefox to debug that as well) and navigate to &lt;a href="/bryantlikes"&gt;my blog&lt;/a&gt; since that is where the xap shows up. Back in Visual Studio I click Debug &amp;ndash;&amp;gt; Attach to Process and select the iexplore.exe process which is Internet Explorer (or firefox.exe if you&amp;rsquo;re debugging Firefox). &lt;/p&gt;
&lt;p&gt;NOTE: Make sure you click highlight iexplore.exe or firefox.exe and then click the Select button and choose Silverlight as the type of code you wish to debug.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://files.bryantlikes.com/Images/image_3AD28F73.png"&gt;&lt;img height="442" width="644" src="http://files.bryantlikes.com/Images/image_thumb_05C60043.png" alt="image" border="0" title="image" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Once I click attach I can go back to my Internet Explorer window and hit refresh to force the breakpoint to get hit. If everything was setup correctly you should get taken back to Visual Studio where your breakpoint is highlighted and you can now step through your Silverlight code.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://files.bryantlikes.com/Images/image_33B352FB.png"&gt;&lt;img height="105" width="555" src="http://files.bryantlikes.com/Images/image_thumb_61A0A5B3.png" alt="image" border="0" title="image" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;So why is this useful? Well a lot can change in your application when you start hosting it on a real server instead of in your localhost. For one, you now have to access services running on the server and you are subject to a lot more security checks that were ignored on your localhost. So I find this to be a useful tool for troubleshooting things when they work locally but break once I deploy out to a server.&lt;/p&gt;
&lt;p&gt;One last thing, you can also set this up to &lt;a href="http://msdn.microsoft.com/en-us/library/cc903948(VS.95).aspx"&gt;remotely debug code running on the Mac&lt;/a&gt;. &lt;/p&gt;
&lt;div class="wlWriterHeaderFooter"&gt;&lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;&lt;/a&gt;&lt;/div&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=12901" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category></item><item><title>Twilight 1.5: Multiple Views with MVVM</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/02/26/12766.aspx</link><pubDate>Thu, 26 Feb 2009 17:15:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:12766</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/12766.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=12766</wfw:commentRss><description>&lt;p&gt;You may have noticed the new look for the &lt;a href="http://www.codeplex.com/Twilight"&gt;Twilight Twitter Badge&lt;/a&gt; on my blog a few weeks ago. I wanted to add a few new looks for the badge and got one of them done but then decided I need to spend some more time on it before releasing it because I didn&amp;rsquo;t like the way the code was turning out. There were a couple of things I didn&amp;rsquo;t like:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The code was too tightly coupled to the views/skins. This made it hard to add new views/skins without duplicating code. &lt;/li&gt;
&lt;li&gt;The views/skins weren&amp;rsquo;t &lt;a href="http://alanle.com/?p=110"&gt;blendable&lt;/a&gt; at all. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To start my rework I began with &lt;a href="http://blogs.msdn.com/expression/archive/2008/10/27/simulating-sample-data-in-blend-2-sp1.aspx"&gt;this post by the Expression Blend/Design team on simulating sample data in Blend&lt;/a&gt;. The post is a very simple yet workable solution for displaying design time data in Blend so that you can work on the layout of your application. The only change I made was &lt;a href="/bryantlikes/archive/2009/02/25/detecting-design-mode-in-silverlight.aspx"&gt;how I detected design mode&lt;/a&gt;. After playing around with that sample I decided that to implement this in Twilight I would need to switch to a &lt;a href="http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx"&gt;Model-View-ViewModel&lt;/a&gt; approach so I started doing some research into using this approach with Silverlight. In my research I came across &lt;a href="http://www.ryankeeter.com/silverlight/silverlight-mvvm-pt-1-hello-world-style/"&gt;this post by Ryan Keeter&lt;/a&gt; on using MVVM in Silverlight. It was a nice simple explanation that made sense to me so I set out to combine the expression team example and this MVVM example. &lt;/p&gt;
&lt;p&gt;What I ended up with is pretty close to MVVM. I say pretty close because I don&amp;rsquo;t think it fully fits since the ViewModels hook into some of the Views Storyboard events and also control the Views VisualState transitions. Maybe that fits into MVVM, but it probably breaks some of the rules. However, for this tiny application it makes things a lot easier. I still have multiple Views per ViewModel and the Views have zero code which is what I really wanted. &lt;/p&gt;
&lt;p&gt;There are two ViewModels that I&amp;rsquo;m using: ListViewModel and RotatingViewModel. Then on top of these two ViewModels are four Views: Default, Large, Small, and Tiny. &lt;/p&gt;
&lt;table cellpadding="2" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td&gt;ListViewModel Views&lt;/td&gt;
&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=Twilight&amp;amp;DownloadId=56287" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=Twilight&amp;amp;DownloadId=59808" /&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p align="center"&gt;Default View&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p align="center"&gt;Large View&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;p&gt;The ListViewModel is for views where there is just a list of tweets while the RotatingViewModel is for views that display a single tweet at a time. &lt;/p&gt;
&lt;table cellpadding="2" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td&gt;RotatingViewModel Views&lt;/td&gt;
&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=Twilight&amp;amp;DownloadId=56691" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=Twilight&amp;amp;DownloadId=59807" /&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p align="center"&gt;Small&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p align="center"&gt;Tiny&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can switch between these views by setting the mode initParam equal to the view you want (example: mode=tiny). The Tiny view looks like the twitter counter badge but then pops the bubbles over the surrounding content. This is done using the windowless = true parameter and absolute positioning. Right now the Silverlight will float over the content below it even when the bubble isn&amp;rsquo;t showing, so you won&amp;rsquo;t be able to click through to that content. I might be able to figure out a better way to handle it, but for now that is a known limitation. &lt;/p&gt;
&lt;p&gt;Since now all the view logic is in the ViewModel, writing tests is a lot easier. I&amp;rsquo;m still using the same Silverlight test framework, but thanks to &lt;a href="http://silverlight.net/blogs/justinangel/archive/2009/02/25/silverlight-unit-testing-rhinomocks-unity-and-resharper.aspx"&gt;this post by Justin Angel I added a few more complex tests using his WaitFor extension&lt;/a&gt;. The test coverage is still very light and I&amp;rsquo;m not testing the views at all, but I feel like I&amp;rsquo;m starting to get testing in Silverlight. &lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve also added another option for hosting Twilight on your blog. You can now host it via Silverlight Streaming using an iframe. Add the following HTML to your page: &lt;/p&gt;
&lt;p&gt;&amp;lt;iframe src="http://silverlight.services.live.com/invoke/232/Twilight1.5/iframe.html?username=[your username]&amp;amp;count=10&amp;amp;mode=small" scrolling="no" frameborder="0" style='width:200px; height:175px'&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/p&gt;
&lt;p&gt;** Hosting it via Silverlight Streaming doesn&amp;rsquo;t support the Tiny mode since the Silverlight won&amp;rsquo;t be able to expand outside of the iframe. &lt;/p&gt;
&lt;p&gt;In addition to hosting it via Silverlight Streaming, you can always self-host it or use the xap I have hosted on dreamhost at &lt;a href="http://twilight.bryantlikes.com/twilight.xap"&gt;http://twilight.bryantlikes.com/twilight.xap&lt;/a&gt;. If you&amp;rsquo;re already using the hosted version, you can switch the mode by using the mode initParam as I mentioned above. &lt;/p&gt;
&lt;p&gt;Hopefully this will serve as a great twitter badge for your blog and also a decent example of MVVM in Silverlight along with some unit testing examples as well. Feel free to &lt;a href="http://www.codeplex.com/Twilight"&gt;join the project on Codeplex&lt;/a&gt; and create your own views. I am still working on at least one more version that will make the colors tweakable and maybe even detect what colors should be used based on the surrounding html. &lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=12766" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1398.aspx">Twitter</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1402.aspx">UX</category></item><item><title>Detecting Design Mode in Silverlight</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/02/25/12750.aspx</link><pubDate>Wed, 25 Feb 2009 15:46:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:12750</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/12750.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=12750</wfw:commentRss><description>&lt;p&gt;One of the things I&amp;rsquo;ve been trying to getting a better understanding of is how to make the Silverlight projects I work on more &lt;a href="http://twitter.com/a7an/status/1215936431"&gt;blendable&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In general, WPF and Silverlight controls should be "blendable". ItemsControls need to display representative data within the design surface.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The problem, at least for me, is that every &lt;a href="http://alanle.com/wp-trackback.php?p=110"&gt;example out there to detect design mode&lt;/a&gt; uses:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;var designMode = !HtmlPage.IsEnabled;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Since the Html Bridge is disable inside of Blend, this does work for the most part, but what about when your xap is hosted on another server? In this case the Html Bridge is disabled by default so if someone doesn&amp;rsquo;t configure it correctly they will get your design time data.&lt;/p&gt;
&lt;table cellpadding="2" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mode&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;HtmlPage.IsEnabled&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Blend&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Visual Studio&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Local Xap&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Remote Xap&lt;/td&gt;
&lt;td&gt;false*&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Streaming Silverlight&lt;/td&gt;
&lt;td&gt;true**&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;p&gt;* This can be changed to true, but it is &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.interop.settings.enablehtmlaccess(VS.95).aspx"&gt;disabled by default&lt;/a&gt;. &lt;br /&gt;** Enabled by default&lt;/p&gt;
&lt;p&gt;So I was trying to come up with another method to detect design mode in Silverlight and here is the best I have come up with so far:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsDesignTime()
{
    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        var host = Application.Current.Host.Source;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt;
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;p&gt;What happens is that Application.Current.Host.Source works great when the plugin is hosted in a web page and will return the path to the xap file, but in design mode trying to access that property throws an exception. So if you hit the exception then you&amp;rsquo;re in design mode, otherwise you&amp;rsquo;re in a web page. Not super elegant but it feels better to me than checking if the Html Bridge is enabled since that isn&amp;rsquo;t a true check.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;As Tom mentions in the comments, you can also use DesignerProperties.GetIsInDesignMode. But if your goal is to make your project more blendable then Visual Studio support might not be important. &lt;/p&gt;
&lt;table cellpadding="2" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mode&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;DesignerProperties.GetIsInDesignMode&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Blend&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Visual Studio&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Local Xap&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Remote Xap&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Streaming Silverlight&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;p&gt;So with this check worst case you get no data in the Visual Studio designer, but the Visual Studio designer isn&amp;rsquo;t that great anyway. Blend is the real goal. So instead instead of the above code you can use this code instead:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsDesignTime()
{
    &lt;span class="kwrd"&gt;return&lt;/span&gt; DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual);
}&lt;/pre&gt;
&lt;p&gt;Thanks for the tip Tom!&lt;/p&gt;
&lt;div class="wlWriterHeaderFooter"&gt;&lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;&lt;/a&gt;&lt;/div&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=12750" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category></item><item><title>Running a Home Office Web Server with a Dynamic IP</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/02/10/12564.aspx</link><pubDate>Tue, 10 Feb 2009 16:19:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:12564</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/12564.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=12564</wfw:commentRss><description>&lt;p&gt;I&amp;rsquo;ve blogged about &lt;a href="/bryantlikes/archive/2005/04/25/3019.aspx"&gt;my server closet in my home office&lt;/a&gt; before. I used to have three servers running in my home office and for Internet service I had AT&amp;amp;T DSL with 5 static IP addresses. That all changed by accident when I was looking into current pricing and found I could upgrade my speed and I would get a lower cost. However, someone over at AT&amp;amp;T DSL misread my order and changed me from static to dynamic, so yesterday morning I got knocked offline. I spent over 2 hours on the phone with them and they told me it could take up to 48 hours before they could get me static IP addresses again. So I started looking into getting my blog back online with a dynamic IP.&lt;/p&gt;
&lt;p&gt;One of my goals for last year was to outsource most of my home network to external servers because I didn&amp;rsquo;t like dealing with it. So last year I did outsource email to &lt;a href="http://www.google.com/a/cpanel/domain/new"&gt;Google Apps&lt;/a&gt;, DNS and some websites to &lt;a href="http://www.godaddy.com/"&gt;Godaddy&lt;/a&gt;, and Subversion to &lt;a href="http://www.dreamhost.com"&gt;Dreamhost&lt;/a&gt;. Because of that I was able to downsize to a single server which I run a few websites on. I also had been having network speed issues so I had just purchased a new router+dsl modem, the &lt;a href="http://www.amazon.com/D-Link-DSL-2540B-4-Port-Ethernet-Router/dp/B000O0XW7E/ref=pd_bbs_sr_1?ie=UTF8&amp;amp;s=electronics&amp;amp;qid=1234288874&amp;amp;sr=8-1"&gt;D-Link DSL 2540B&lt;/a&gt; which happens to support Dynamic DNS.&lt;/p&gt;
&lt;p&gt;Setting it up:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You need to make sure your router supports Dynamic DNS and you need an account with a Dynamic DNS service. I used &lt;a href="http://www.dyndns.com/"&gt;dyndns.com&lt;/a&gt; since they have free accounts. I setup mine to be bryantlikes.dyndns.org. &lt;/li&gt;
&lt;li&gt;Delete the A record for your DNS (if you have one) and then create a new CNAME for your domain that points to the Dynamic DNS name. So, for example, blogs.sqlxml.org has a CNAME that points to bryantlikes.dyndns.org. If you have other CNAME records already (for example, www), then point those to your dynamic DNS entry as well.&lt;/li&gt;
&lt;li&gt;Forward port 80 to your web server in your router settings. This is different for each router, D-Link calls it Virtual Servers under the advanced tab.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;At this point your website should be available from the Internet. However, internally you won&amp;rsquo;t be able to hit it. The port forwarding only happens from the WAN interface and not the LAN one. In order to get it working internally you have to take a couple more steps.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Setup DNS on your web server if it isn&amp;rsquo;t already on there. Then add a new domain for the domain that you used in your dynamic DNS. For example, I added the bryantlikes.dyndns.org domain and then created an A record for the root that points to my web server&amp;rsquo;s local IP address. &lt;/li&gt;
&lt;li&gt;Make sure your DHCP clients all point to your web server as their DNS. It is the only DNS Server that redirects the dynamic DNS entry to your local server.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That&amp;rsquo;s it! You should now have your dynamic IP serving up web pages both internally and externally. This caused me a bunch of headaches and googling yesterday so I thought it was worth blogging about. I glossed over lots of setup in each of the steps so if you want more information let me know and I&amp;rsquo;ll try to add it.&lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=12564" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1051.aspx">General</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1360.aspx">Community Server</category></item><item><title>A Year of Climbing Mountains</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/02/04/12454.aspx</link><pubDate>Wed, 04 Feb 2009 17:54:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:12454</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/12454.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=12454</wfw:commentRss><description>&lt;p&gt;This post is actually about cycling more than coding, but as I thought about it I realized that being a Software Developer is often much like mountain climbing. Each time I get to what I think is the peak (or close to the peak) I see that there is another even higher peak up ahead. For instance, I&amp;rsquo;m finally getting comfortable with Silverlight 2 and just starting to get a glimpse of Silverlight 3. A Software Developer can never stop learning (especially if you&amp;rsquo;re a web developer). I still remember my first glimpse of the .NET/FX mountain range at PDC 05 which we now know to have peaks such as WPF, WCF, and even Silverlight. It was very overwhelming at the time, but now it is fun to look back at where I was then. Quite a view from up here. With all the new stuff coming this year, Win7, Silverlight 3, VS 2010 (betas at least), it will be a year of climbing for sure.&lt;/p&gt;
&lt;p&gt;But the real climbing that inspired this post is climbing on my bike. Last year I got serious about riding my bike and did three big rides: 62.5 mile ADA Ride, 100 mile Coolbreeze Century, and the 175 mile MS Socal Ride. At the start of the season I rode mostly flats with a few hills but pretty much hated climbing. During the ADA ride I kept up with a pack of riders that were much faster than me but I would quickly get dropped every time we hit any kind of a climb. After that I started riding Rockstore once a week during the &lt;a href="http://www.winswheels.com"&gt;Wins Wheels&lt;/a&gt; shop ride and would ride Santa Susana once or twice a week. I did enough climbing prior to my century that I didn&amp;rsquo;t get passed a single time on any climbs and I was the one dropping the pack. On the MS ride I did get passed on one climb (by a girl), but that was because I was resting the in the shade so that I didn&amp;rsquo;t pass out from heat exhaustion. :)&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve actually started to enjoy climbing and so this year I&amp;rsquo;m planning on doing two rides: &lt;a href="http://www.cvcbike.org/cruisin/"&gt;Cruising the Conejo&lt;/a&gt; and &lt;a href="http://www.ocw.org/bear/bearinfo.asp"&gt;Ride Around the Bear&lt;/a&gt;. Both are century rides, but both have a lot of climbing. Cruising the Conejo has 6,000 feet of climbing while Ride Around the Bear has 10,000 feet of climbing. I just started to train for them in earnest this week and sometimes I wonder if I&amp;rsquo;m crazy to attempt these rides. Right now I know I couldn&amp;rsquo;t do it, but that is how you get to a place you want to be. You plan to get there at a later date and set that date in stone, otherwise you&amp;rsquo;ll never get there. &lt;/p&gt;
&lt;p&gt;So this year is a year of climbing for me, both in cycling and in software. Hope to see you on one of the peaks!&lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=12454" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1051.aspx">General</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1400.aspx">Cycling</category></item><item><title>Twilight 1.1: Using a Yahoo Pipes Proxy</title><link>http://blog.avanadeadvisor.com/blogs/bryantl/archive/2009/01/27/12412.aspx</link><pubDate>Tue, 27 Jan 2009 20:54:00 GMT</pubDate><guid isPermaLink="false">5e51d585-b788-4f7c-85ba-1877739ce145:12412</guid><dc:creator>bryantl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.avanadeadvisor.com/blogs/bryantl/comments/12412.aspx</comments><wfw:commentRss>http://blog.avanadeadvisor.com/blogs/bryantl/commentrss.aspx?PostID=12412</wfw:commentRss><description>&lt;p&gt;I just pushed a minor update to &lt;a href="http://www.codeplex.com/Twilight"&gt;Twilight that you can now download on the codeplex site&lt;/a&gt; (version 1.1). I really wanted to allow the xap file to be hosted on other servers since many bloggers don&amp;rsquo;t have the ability to host their own xap files. After reading &lt;a href="http://blogs.msdn.com/msmossyblog/archive/2009/01/26/replaced-my-msdn-graphic-header-with-silverlight.aspx"&gt;Scott Barnes&amp;rsquo; post about replacing his header with Silverlight&lt;/a&gt; I decided I would take a similar approach. Instead of using a callback or trying to get the data directly, Scott followed &lt;a href="http://jonas.follesoe.no/PermaLink,guid,52d330a9-2931-40dc-9320-01195b24996a.aspx"&gt;Jonas&amp;rsquo; post on using Yahoo Pipes to proxy data to Silverlight&lt;/a&gt;. I took the same approach and during the process refactored some of the code by moving all the data logic out to a separate set of classes. Now when the xap loads it checks to see if it can access the Html Bridge and makes sure it is on the same domain. If it is then it will just use the standard Twitter callback method, otherwise it uses the &lt;a href="http://pipes.yahoo.com/pipes/pipe.info?_id=bmyAAovs3RGkGYkMBRNMsA"&gt;yahoo pipes proxy&lt;/a&gt; I created.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://files.bryantlikes.com/Images/pipes_32F68400.png"&gt;&lt;img height="184" width="244" src="http://files.bryantlikes.com/Images/pipes_thumb_64F0B53B.png" align="left" alt="pipes" border="0" title="pipes" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The pipe I created simple takes a username and the number of tweets to return and grabs the twitter xml. I then use an HttpRequest in my code to get this xml from yahoo formatted as json which matches up to the json that I was getting from Twitter with the exception that there are a few wrapper objects I have to go through to get the tweets. I also moved all the update logic out of the page class and into the base data provider class since that made a lot more sense.&lt;/p&gt;
&lt;p&gt;I think the new code makes it much cleaner and the end result is you can now just stick the object tag up on your blog and leave the xap hosted on my server if you&amp;rsquo;d like. Here is the html you can use for the hosted version:&lt;/p&gt;
&lt;p&gt;&amp;lt;div id="silverlightControlHost"&amp;gt; &lt;br /&gt;&amp;nbsp; &amp;lt;object id="TwitterBadge" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="200" height="400"&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param name="source" value="http://twilight.bryantlikes.com/Twilight.xap"/&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param name="minRuntimeVersion" value="2.0.31005.0" /&amp;gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param name="initParams" value="username=&lt;b&gt;bryantlikes&lt;/b&gt;,count=10" /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div style='position:relative;'&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;a style='z-index:0;' href='http://go.microsoft.com/fwlink/?LinkID=124807' style='text-decoration: none;'&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;img src="http://twilight.bryantlikes.com/twilightNoSilverlight.png" alt="Get Microsoft Silverlight" style='border-style: none'/&amp;gt; &amp;lt;/a&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div style='font-family:Arial;font-size:10px;position:absolute;top:230;left:10;width:175px;'&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by clicking "Install Microsoft Silverlight" you accept the &amp;lt;br /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;a href="http://www.microsoft.com/silverlight/resources/License.aspx?v=2.0"&amp;gt;Silverlight license agreement&amp;lt;/a&amp;gt; &lt;br /&gt;&amp;nbsp; &amp;lt;/div&amp;gt; &lt;br /&gt;&amp;nbsp; &amp;lt;/div&amp;gt; &lt;br /&gt;&amp;nbsp; &amp;lt;/object&amp;gt; &lt;br /&gt;&amp;nbsp; &amp;lt;iframe style='visibility:hidden;height:0;width:0;border:0px'&amp;gt; &lt;br /&gt;&amp;nbsp; &amp;lt;/iframe&amp;gt; &lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;Today I had my first sighting of &lt;a href="http://blog.dennyboynton.com/default.aspx"&gt;Twilight in the wild over at Denny Boynton&amp;rsquo;s Blog&lt;/a&gt;.&amp;nbsp; Very cool!&lt;/p&gt;
Cross-posted from blogs.sqlxml.org&lt;img src="http://blog.avanadeadvisor.com/aggbug.aspx?PostID=12412" width="1" height="1"&gt;</description><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1103.aspx">WPF/E</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1164.aspx">Silverlight</category><category domain="http://blog.avanadeadvisor.com/blogs/bryantl/archive/category/1398.aspx">Twitter</category></item></channel></rss>