<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>silverlight</title>
        <link>http://blog.kellybrownsberger.com/category/20.aspx</link>
        <description>silverlight</description>
        <language>en-US</language>
        <copyright>kellyb</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>My take on the ViewModelLocator pattern for MVVM</title>
            <link>http://blog.kellybrownsberger.com/archive/2010/03/31/81.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://johnpapa.net/silverlight/simple-viewmodel-locator-for-mvvm-the-patients-have-left-the-asylum/" target="_blank"&gt;John Papa&lt;/a&gt; and &lt;a href="http://codebetter.com/blogs/glenn.block/archive/2010/03/30/view-model-locator-mef-style.aspx" target="_blank"&gt;Glen Block&lt;/a&gt; have recently posted on a topic that touched home for me.  They put together a solution to find view models for a given view in a view-first fashion to support Blendability and a clean MVVM presentation pattern.  Funny, I put this very pattern together last week after being motivated by what I saw from &lt;a href="http://devlicio.us/blogs/rob_eisenberg/archive/2010/03/16/build-your-own-mvvm-framework-is-online.aspx" target="_blank"&gt;Rob Eisenberg&lt;/a&gt; and &lt;a href="http://www.galasoft.ch/" target="_blank"&gt;Laurent Bugnion&lt;/a&gt; at MIX the week before.  I too came to the conclusion that it makes a lot of sense to go with a View-first approach if you’re going to make Blend a first class citizen in your development process (as I believe you should).&lt;/p&gt; &lt;p&gt;What John and Glen put together is MEF based (obviously), but what I put together is IoC based.  In my case I’m using Unity, but it could be any IoC container.  With a very simple convention, I can greatly simplify this entire pattern.  That convention is this:  The View and the ViewModel will always reside in the same namespaces within the same assembly and the View will always be suffixed with xxxxxView and the ViewModel will always be suffixed with xxxxxViewModel.  That’s it.  With that convention in place, one line of markup can be used in all views to auto-locate, instantiate, and bind to it’s corresponding ViewModel.  No need to Export anything with MEF and no need to have string names on your exports to find by.  I like my approach a lot better and my team has been very happy with it so far.  It’s very simple, straightforward and requires very little ceremony code.&lt;/p&gt; &lt;p&gt;Below is what the code looks like…&lt;/p&gt; &lt;p&gt;All views have this markup at the root element:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="attr"&gt;DataContext&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding RelativeSource={RelativeSource Self},  Converter={StaticResource LocatorConverter} }"&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;This is simply binding the View’s DataContext to itself and passing itself to the LocatorConverter.  The LocatorConverter looks like this:&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; ViewModelLocator
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; Locate(&lt;span class="kwrd"&gt;object&lt;/span&gt; view)
        {
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                Check.ForNullArg(view, &lt;span class="str"&gt;"view"&lt;/span&gt;);

                Type viewType = view.GetType();
                &lt;span class="kwrd"&gt;string&lt;/span&gt; viewTypeName = viewType.Name;

                Logger.WriteInfo(&lt;span class="str"&gt;"Attempting to auto-resolve the view model from the view (type: {0})"&lt;/span&gt;, viewTypeName);

                &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(viewTypeName) || !viewTypeName.EndsWith(&lt;span class="str"&gt;"View"&lt;/span&gt;))
                {
                    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; PresentationModelException(&lt;span class="str"&gt;"Attempting to locate a view model instance for an invalid {0} implementation - expected the type name to be suffixed with 'View'"&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IView).Name);
                }

                &lt;span class="kwrd"&gt;string&lt;/span&gt; viewModelTypeName = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Concat(viewTypeName, &lt;span class="str"&gt;"Model"&lt;/span&gt;);

                var viewModelTypeFullName = viewType.AssemblyQualifiedName.Replace(viewTypeName, viewModelTypeName);

                var viewModelType = Type.GetType(viewModelTypeFullName);

                &lt;span class="kwrd"&gt;if&lt;/span&gt; (viewModelType == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; PresentationModelException(&lt;span class="str"&gt;"Could not find view model type '{0}' in namespace '{1}' within assembly '{2}'.  Auto resolution of the view model requires both the view and the view model to reside within the same namespace."&lt;/span&gt;, viewModelTypeName, viewType.Namespace, viewType.Assembly.FullName);
                }

                &lt;span class="kwrd"&gt;object&lt;/span&gt; resolved = IoC.Resolve(viewModelType);

                &lt;span class="kwrd"&gt;if&lt;/span&gt; (resolved == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; PresentationModelException(&lt;span class="str"&gt;"Failed to resolve the view model type '{0}'"&lt;/span&gt;, viewModelTypeFullName);
                }

                Logger.WriteInfo(&lt;span class="str"&gt;"Successfully auto-resolved view model (type {0})"&lt;/span&gt;, viewModelTypeFullName);

                &lt;span class="kwrd"&gt;return&lt;/span&gt; resolved;
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                &lt;span class="kwrd"&gt;string&lt;/span&gt; viewType = view != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? view.GetType().FullName : &lt;span class="str"&gt;"NULL"&lt;/span&gt;;

                &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; PresentationModelException(ex, &lt;span class="str"&gt;"The attempt to auto-instantiate the view model for the view '{0}' threw an exception: {1}.  See the inner exception for details."&lt;/span&gt;, viewType, ex.Message);
            }
        }&lt;/pre&gt;&lt;pre class="csharpcode"&gt;
&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[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; }
]]&gt;&lt;/style&gt;

&lt;p&gt;IoC is a very think shim around Unity that’s setup by our application’s Bootstrapping process:&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;object&lt;/span&gt; Resolve(Type type)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _container.Resolve(type);
        }

&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[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; }
]]&gt;&lt;/style&gt;

&lt;p&gt;I love MEF, but this doesn’t feel like a good fit for MEF to me – at least not in it’s current form.&lt;/p&gt;&lt;img src="http://blog.kellybrownsberger.com/aggbug/81.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>kellyb</dc:creator>
            <guid>http://blog.kellybrownsberger.com/archive/2010/03/31/81.aspx</guid>
            <pubDate>Thu, 01 Apr 2010 01:51:38 GMT</pubDate>
            <wfw:comment>http://blog.kellybrownsberger.com/comments/81.aspx</wfw:comment>
            <comments>http://blog.kellybrownsberger.com/archive/2010/03/31/81.aspx#feedback</comments>
            <wfw:commentRss>http://blog.kellybrownsberger.com/comments/commentRss/81.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Handy Serialization Extension Method, Clean code with Action&amp;lt;T&amp;gt;</title>
            <link>http://blog.kellybrownsberger.com/archive/2010/03/23/79.aspx</link>
            <description>&lt;p&gt;Here’s a handy Extension Method in C# that attaches a “ToXml()” method to any and all object instances.  I added the capability to dictate whether or not to use the classic XmlSerializer or the DataContractSerializer that came to us with WCF.  I made the XmlSerializer the default because typically, when I’m doing this programmatically in my code, it’s intended for human eyes and the XmlSerializer is far more readable, but the DataContractSerializer is what’s actually used at runtime by WCF.  So, call the overload the matters to you.&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;string&lt;/span&gt; ToXml&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; T obj) &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; ToXml(obj, &lt;span class="kwrd"&gt;false&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;string&lt;/span&gt; ToXml&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; T obj, &lt;span class="kwrd"&gt;bool&lt;/span&gt; useDataContractSerializer) &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (obj != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                Type type = &lt;span class="kwrd"&gt;typeof&lt;/span&gt; (T);

                Action&amp;lt;XmlWriter, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; action;
                
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (useDataContractSerializer)
                {
                    action = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataContractSerializer(type).WriteObject;
                }
                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                {
                    action = &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlSerializer(type).Serialize;
                }


                &lt;span class="kwrd"&gt;using&lt;/span&gt; (MemoryStream stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; MemoryStream())
                {
                    XmlWriterSettings settings = &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlWriterSettings { Encoding = Encoding.UTF8, Indent = &lt;span class="kwrd"&gt;true&lt;/span&gt; };
                    XmlWriter writer = XmlWriter.Create(stream, settings);

                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (writer != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                    {
                        &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] bytes;

                        &lt;span class="kwrd"&gt;using&lt;/span&gt; (writer)
                        {
                            action(writer, obj);
                            writer.Flush();
                            stream.Flush();

                            bytes = stream.ToArray();
                        }

                        &lt;span class="kwrd"&gt;return&lt;/span&gt; Encoding.UTF8.GetString(bytes, 0, bytes.Length);
                    }
                }
            }

            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        }&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.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; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;This is a good example of C# generics using Action&amp;lt;T&amp;gt;.  Notice I’m assigning the variable “action” to either the XmlSerializer’s Serialize() method, or the DataContractSerializer’s WriteObject() – which both have a method overload of &lt;em&gt;void (XmlWriter writer, object obj)&lt;/em&gt;.  I really like this syntax as it provides yet another way to remove duplication from your code without requiring the types to share a base class or interface, and without having to create a full blown Template Method pattern implementation.&lt;/p&gt;

&lt;p&gt;And it works in Silverlight too :)&lt;/p&gt;&lt;img src="http://blog.kellybrownsberger.com/aggbug/79.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>kellyb</dc:creator>
            <guid>http://blog.kellybrownsberger.com/archive/2010/03/23/79.aspx</guid>
            <pubDate>Wed, 24 Mar 2010 03:44:34 GMT</pubDate>
            <wfw:comment>http://blog.kellybrownsberger.com/comments/79.aspx</wfw:comment>
            <comments>http://blog.kellybrownsberger.com/archive/2010/03/23/79.aspx#feedback</comments>
            <wfw:commentRss>http://blog.kellybrownsberger.com/comments/commentRss/79.aspx</wfw:commentRss>
        </item>
        <item>
            <title>ASP.NET MVC - Unhandled Error in Silverlight Application Code: 2104</title>
            <link>http://blog.kellybrownsberger.com/archive/2009/12/10/71.aspx</link>
            <description>&lt;p&gt;I’m creating a simple ASP.NET MVC application and on first run I’m getting blasted with this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.kellybrownsberger.com/____Uploads____/ASP.NETMVCUnhandledErrorinSilverlightApp_107A5/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.kellybrownsberger.com/____Uploads____/ASP.NETMVCUnhandledErrorinSilverlightApp_107A5/image_thumb.png" width="446" height="296" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Google didn’t turn up the solution as fast as I would have liked, so I thought I’d post it here for the next fool to find :)&lt;/p&gt;  &lt;h2&gt;Solution:&lt;/h2&gt;  &lt;p&gt;When you add a Silverlight project to a solution, Visual Studio will ask you if you would like to &lt;em&gt;create new web site&lt;/em&gt; to host it, or &lt;em&gt;choose an existing one&lt;/em&gt; in your solution.  I choose an existing one.  By default, Visual Studio creates this in your HTML markup to host a Silverlight application:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="silverlight"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;object&lt;/span&gt; &lt;span class="attr"&gt;data&lt;/span&gt;&lt;span class="kwrd"&gt;="data:application/x-silverlight-2,"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="application/x-silverlight-2"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="source"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="ClientBin/MySilverlightApp.xap"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="onError"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="onSilverlightError"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="background"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="white"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="minRuntimeVersion"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="3.0.40624.0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="autoUpgrade"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="true"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="initParams"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="page=UserRegistrationView"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;

          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="http://go.microsoft.com/fwlink/?LinkID=149156&amp;amp;v=3.0.40624.0"&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;="text-decoration:none"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
               &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;img&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="http://go.microsoft.com/fwlink/?LinkId=108181"&lt;/span&gt; &lt;span class="attr"&gt;alt&lt;/span&gt;&lt;span class="kwrd"&gt;="Get Microsoft Silverlight"&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;="border-style:none"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;object&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;iframe&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="_sl_historyFrame"&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;="visibility:hidden;height:0px;width:0px;border:0px"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;iframe&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Visual Studio does not account for the URL rewriting that comes with MVC and by default the path to xap file is wrong.  Change the source parameter to be rooted like so:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="source"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="/ClientBin/MySilverlightApp.xap"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;One simple slash should fix your problem.  Hope this helps someone else (you’re not a fool :)&lt;/p&gt;&lt;img src="http://blog.kellybrownsberger.com/aggbug/71.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>kellyb</dc:creator>
            <guid>http://blog.kellybrownsberger.com/archive/2009/12/10/71.aspx</guid>
            <pubDate>Thu, 10 Dec 2009 23:52:02 GMT</pubDate>
            <wfw:comment>http://blog.kellybrownsberger.com/comments/71.aspx</wfw:comment>
            <comments>http://blog.kellybrownsberger.com/archive/2009/12/10/71.aspx#feedback</comments>
            <wfw:commentRss>http://blog.kellybrownsberger.com/comments/commentRss/71.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Debugging Silverlight with Silverlight Spy</title>
            <link>http://blog.kellybrownsberger.com/archive/2009/11/23/69.aspx</link>
            <description>&lt;p&gt;The debugging experience in Silverlight project using Visual Studio is quite good.  However, there are two things that is doesn’t help much with:  when data bindings don’t work, and when your XAML doesn’t look like you think it should.  &lt;a href="http://blog.kellybrownsberger.com/archive/2009/11/23/67.aspx" target="_blank"&gt;Here’s a post about debugging data bindings&lt;/a&gt;.  The visual part is a little more involved.  Yes, yes Expression Blend has a nice visual designer, but it’s fairly common for Blend to show a piece of XAML in one way and for it to actually render in the browser differently (sometime &lt;em&gt;significantly&lt;/em&gt; differently).  Today I found First Floor Software’s &lt;a href="http://firstfloorsoftware.com/silverlightspy/" target="_blank"&gt;Silverlight Spy&lt;/a&gt;.  This appears to be a pretty awesome diagnostics tool that allows you to see and alter Silverlight’s Visual Tree at runtime side by side an embedded browser.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.kellybrownsberger.com/____Uploads____/DebuggingSilverlightwithSilverlightSpy_B3E2/image.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="244" alt="image" src="http://blog.kellybrownsberger.com/____Uploads____/DebuggingSilverlightwithSilverlightSpy_B3E2/image_thumb.png" width="224" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You can edit the Visual Studio within Silverlight Spy and see the rendered content change immediately.  This is extremely useful.  This is to Silverlight apps what Firebug is to web apps. &lt;/p&gt;  &lt;p&gt;If this is still useful at the end of the trial period, I’ll be buying a copy of this for myself.&lt;/p&gt;&lt;img src="http://blog.kellybrownsberger.com/aggbug/69.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>kellyb</dc:creator>
            <guid>http://blog.kellybrownsberger.com/archive/2009/11/23/69.aspx</guid>
            <pubDate>Mon, 23 Nov 2009 17:47:35 GMT</pubDate>
            <wfw:comment>http://blog.kellybrownsberger.com/comments/69.aspx</wfw:comment>
            <comments>http://blog.kellybrownsberger.com/archive/2009/11/23/69.aspx#feedback</comments>
            <wfw:commentRss>http://blog.kellybrownsberger.com/comments/commentRss/69.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Silverlight ComboBox SelectedItem Not Working</title>
            <link>http://blog.kellybrownsberger.com/archive/2009/11/23/68.aspx</link>
            <description>&lt;p&gt;I spent well over an hour on Friday with this one and gave up.  I spent almost another hour today working on this.  I almost gave up, but when I’m in learn-mode like I am with Silverlight, these types of issues can really teach you a lot if you see them through.  I had a ComboBox with bindings on it’s ItemSource and SelectedItem like so:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ComboBox&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ComboBoxControl"&lt;/span&gt; &lt;span class="attr"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource ComboBoxStyle}"&lt;/span&gt;
                &lt;span class="attr"&gt;SelectedItem&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Path=SelectedOption, Mode=TwoWay}"&lt;/span&gt;
                &lt;span class="attr"&gt;ItemsSource&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Path=Options}"&lt;/span&gt;
                &lt;span class="attr"&gt;IsEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Path=IsReadOnly}"&lt;/span&gt;
                &lt;span class="attr"&gt;Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource SemiDarkTextBrush}"&lt;/span&gt;                    
                &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="22"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="150"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="30,0,10,0"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ComboBox.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; 
                            &lt;span class="attr"&gt;Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource SemiDarkTextBrush}"&lt;/span&gt;                    
                            &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Path=Label, Mode=OneWay}"&lt;/span&gt; 
                            &lt;span class="attr"&gt;TextWrapping&lt;/span&gt;&lt;span class="kwrd"&gt;="Wrap"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ComboBox.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ComboBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;I put breakpoints in my model’s SelectedOption property and I could see Silverlight calling it.  So, I knew there were no hard binding errors.  The bindings were working, except… they weren’t.  The ComboBox always showed up with no selected item.  I kept plugging away, and by accident I discovered the order of the binding occurrences matter.  Changing the markup to define the ItemsSource binding &lt;em&gt;before&lt;/em&gt; the SelectedItem binding solved the problem.  Like so:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ComboBox&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ComboBoxControl"&lt;/span&gt; &lt;span class="attr"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource ComboBoxStyle}"&lt;/span&gt;
                &lt;span class="attr"&gt;ItemsSource&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Path=Options}"&lt;/span&gt;
                &lt;span class="attr"&gt;SelectedItem&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Path=SelectedOption, Mode=TwoWay}"&lt;/span&gt;
                &lt;span class="attr"&gt;IsEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Path=IsReadOnly}"&lt;/span&gt;
                &lt;span class="attr"&gt;Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource SemiDarkTextBrush}"&lt;/span&gt;                    
                &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="22"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="150"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="30,0,10,0"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ComboBox.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; 
                            &lt;span class="attr"&gt;Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource SemiDarkTextBrush}"&lt;/span&gt;                    
                            &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Path=Label, Mode=OneWay}"&lt;/span&gt; 
                            &lt;span class="attr"&gt;TextWrapping&lt;/span&gt;&lt;span class="kwrd"&gt;="Wrap"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ComboBox.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ComboBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Wow, that’s pretty nasty.  I’m lucky stumbled on the solution.  I consider this a bug.&lt;/p&gt;

&lt;p&gt;Hope this helps someone else out there&lt;/p&gt;&lt;img src="http://blog.kellybrownsberger.com/aggbug/68.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>kellyb</dc:creator>
            <guid>http://blog.kellybrownsberger.com/archive/2009/11/23/68.aspx</guid>
            <pubDate>Mon, 23 Nov 2009 17:31:54 GMT</pubDate>
            <wfw:comment>http://blog.kellybrownsberger.com/comments/68.aspx</wfw:comment>
            <comments>http://blog.kellybrownsberger.com/archive/2009/11/23/68.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://blog.kellybrownsberger.com/comments/commentRss/68.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Silverlight Lessons Learn &amp;ndash; Debugging Data Bindings</title>
            <link>http://blog.kellybrownsberger.com/archive/2009/11/23/67.aspx</link>
            <description>&lt;p&gt;I’ve been neck deep in Silverlight development for the last couple of weeks.  I’m finally starting to feel somewhat competent.  Most of my struggles have been with XAML in general, so I think the steep learning curve applies to both Silverlight and WPF.  One of the things I’ve been using struggling with the most is troubleshooting data bindings.  The data binding system in Silverlight and WPF is pretty awesome, but it’s definitely not intuitive nor discoverable.  When you force yourself to learn it, most of those issues melt away, but… buuuuut, debugging binding remains extremely difficult.&lt;/p&gt;  &lt;p&gt;Today I discovered something that helps a TON.  Binding errors are written to the Visual Studio Output Window!  Check this out:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.kellybrownsberger.com/____Uploads____/SilverlightLessonsLearnDebuggingDataBind_AE50/image.png"&gt;&lt;img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="144" alt="image" src="http://blog.kellybrownsberger.com/____Uploads____/SilverlightLessonsLearnDebuggingDataBind_AE50/image_thumb.png" width="916" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It’s not the most robust solution, but it’s definitely workable.&lt;/p&gt;  &lt;p&gt;After discovering this, I did a bit more Googling around and found this handy article:  &lt;a href="http://www.beacosta.com/blog/?p=52" target="_blank"&gt;How can I debug WPF bindings&lt;/a&gt;.  He covers the Output Window approach there as well.  For the record, I was not able to get the “Trace Sources” technique to work in Silverlight – only WPF.&lt;/p&gt;  &lt;p&gt;Hope this helps someone else out&lt;/p&gt;&lt;img src="http://blog.kellybrownsberger.com/aggbug/67.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>kellyb</dc:creator>
            <guid>http://blog.kellybrownsberger.com/archive/2009/11/23/67.aspx</guid>
            <pubDate>Mon, 23 Nov 2009 17:23:51 GMT</pubDate>
            <wfw:comment>http://blog.kellybrownsberger.com/comments/67.aspx</wfw:comment>
            <comments>http://blog.kellybrownsberger.com/archive/2009/11/23/67.aspx#feedback</comments>
            <wfw:commentRss>http://blog.kellybrownsberger.com/comments/commentRss/67.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>