c a n d l a n d . n e t

Tips for using Silverlight with Monorail (or embedded)

Dusty Candland | |

Today I worked on getting a Silverlight chart embedded in my monorail application. I learned a few things.

You need to have a Silverlight application project someplace in order to create the XAP file. This is what will ultimately get used in your view.

Since it’s really running client side, the XAP files are included in your other projects like other client site stuff, that is just manually copied into a directory there.

Databinding to XML doesn’t seem to work, I think I must be doing something wrong, but I finally ended up using Linq to transfer the data into objects and bind to those. Like this:

…
series.ItemsSource = from n in descendants

                 select <span class="kwrd">new</span> Data
                            {
                                Date = n.Attribute(<span class="str">"Date"</span>).Value,
                                Count = <span class="kwrd">int</span>.Parse(n.Attribute(<span class="str">"Responded"</span>).Value)
                            };

series.IndependentValueBinding = new Binding(“Date”) { Mode = BindingMode.OneWay };
series.DependentValueBinding = new Binding(“Count”) { Mode = BindingMode.OneWay };

public class Data
{

<span class="kwrd">public</span> <span class="kwrd">string</span> Date { get; set; }
<span class="kwrd">public</span> <span class="kwrd">int</span> Count { get; set; }

}

In your View you use embed the XAP file using the object tag like:

<object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
    <param name="source" value="/assets/images/Charts.xap"/>
    <param name="background" value="white" />
    <param name="minRuntimeVersion" value="2.0.31005.0" />
    <param name="autoUpgrade" value="true" />
    <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
    <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
    </a>
</object>

This is really my first time checking out Silverlight, so I'm sure I'm missing a lot and have a ton left to learn. There is a bunch of great info on the Silverlight site.

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: