Building A Silverlight 3 Dashboard With Composite UI

If you’ve been following me on Twitter (igtony), you’ve probably heard me grumbling about Visual Studio crashing, services not working, or various other gremlins I’ve been fighting with for the past few days.  Well, I’ve finally got something to show for all of my pain! 

Image 1

My goal when I started building this application was to build a POC Silverlight Application which dynamically loaded sub-applications.  In essence, I wanted to build a Silverlight shell that could load N applications unknown at compile time.  I started out by choosing from the new Navigation project template in Silverlight 3.  This gives a MasterPage scenario that works as a good starting point for an application which may have multiple distinct Views.  I tweaked the base appearance of the template around just to make it look a little more presentable.  The White background used in the <Frame> element and the big 10px borders reminded me of Windows 3.1, and IE4.  I used a Border element to create the rounded edges which wrapped around my Frame, and I set my Frame background to be transparent.  With some of the UI tweaks out of the way, it was down to business.

The first task I needed to tackle was loading a XAML page (UserControl) dynamically.  It turns out this is a pretty simple task as long as that user control is in the same XAP file.  The Frame element has a Navigate method which takes a URI and will fill the Frame’s Content with the UserControl specified via the URI.  Unfortunately, the solution I was looking for places my UserControl in a separate XAP file, which meant I couldn’t use the simple Frame.Navigate(URI) method.  Instead I needed to dynamically load the UserControl in question.  Luckily, this is a pretty straight forward task with the help of the WebClient.OpenReadAsync method, and AssemblyPart class.  Here’s the code I used:

        private void NavButton_Click(object sender, RoutedEventArgs e)
        {
            Button navigationButton = sender as Button;
            //Create a WebClient instance to download our separate XAP file
            WebClient client=new WebClient();

            client.OpenReadCompleted+=new OpenReadCompletedEventHandler(client_OpenReadCompleted);
            //Download the XAP file
            client.OpenReadAsync(new Uri("CompositeApp.xap",UriKind.Relative));
        }

        void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {

			//Create a StreamResourceInfo object out of our XAP stream            
			StreamResourceInfo sri = new StreamResourceInfo(e.Result, null);
			
			//Get a StreamResourceInfo for the Application's DLL
			//The one that houses our main XAML UserControl
            StreamResourceInfo mainAppSRI = Application.GetResourceStream(sri, new Uri("CompositeApp.dll", UriKind.Relative));
			
			//Load the Assembly using AssemblyPart.Load
            AssemblyPart loader = new AssemblyPart();
            Assembly assembly = loader.Load(mainAppSRI.Stream);
			
			//Now that the Assembly is loaded, create an instance of our UserControl
            this.Frame.Content = assembly.CreateInstance("CompositeApp.MainPage");
           
        }

There’s one drawback to using this method to dynamically load a UserControl – dependencies are not automatically loaded for you.  If your UserControl in the separate XAP has a dependency on 4 assemblies you must manually load those 4 assemblies before loading your UserControl or CreateInstance will fail.  The hack solution I used was to include the assembly references in the main shell application.  This doesn’t scale well though, since ideally you want the additional dependencies to be loaded dynamically as necessary.  There’s no way you’ll know today every assembly reference each sub app will need for the entire life of the shell.  It’s actually impossible since you’ll likely need a ‘new’ assembly at some point down the road.  I saw some code fragments while looking for a solution which read the manifest in the XAP to determine what assemblies need to be loaded out of the (external) XAP.  If I were building this as a real world app, I would go that route.  If you know of a better way to handle this, I encourage you to share in the comments!  In a perfect world Frame.Navigate would allow you to specify a XAML file in a separate XAP and do all of this work for you.  Are you listening Silverlight team? ;)

Ok, main hurdle down (dynamic loading of UserControl from separate XAP), it was time for the next challenge – creating content!  I started out with a grid, because you can’t have a good application without a grid in there somewhere, right?  I used the XamWebGrid, and used it in a couple of places.  One on the main page which showed hierarchical data (Accounts and Transactions)

Image 2

Next I created another ‘page’ or View which Visualized data in a Map.  In this scenario the map shapes came from my “Shapefile” and the data came from a SQL Database via WCF and LinqToSQL.  I think this probably mirrors the major use case out there, where the data is kept separate from the Shapefile. 

Image 3

On the final Screen, I went with ‘live’ updating data (Image 1).  Since this was just a demo, I used a DispatcherTimer to change my underlying datasource every second.  Since my underlying datasource was an ObservableCollection of INotifyPropertyChanged objects, my grid immediately showed any changes made to the underlying datasource.  The Grid does 2-way databinding by default.  Since my View still looked empty, I dropped a chart in there as well, and added a new datapoint to the chart’s DataPoints collection each second (representing the history of changes made to the grid).  The end result was a chart and grid showing updates every second, with the Chart “always in motion”.  It was a pretty impressive experience.  My next step is to see what this would look like with a real data feed.  I’m guessing with proper queuing in place, the experience should mirror my mock up almost exactly. 

63 Comments

  • this is exactly what i was looking for, could you please share your advances on this task?, a little demo project or something please.

    regards.

  • Hey, do you have a code fragment that shows how to read the manifest file of a dynamically loaded xap? I'd really appreciate it!

  • this is excatly what i was looking for,could you share the demo project of this task ..
    Regards!!!

  • Yes there should realize the reader to RSS my feed to RSS commentary, quite simply

  • Good post however , I was wanting to know if you could write a litte more
    on this subject? I'd be very thankful if you could elaborate a little bit more. Thanks!

  • Hello there! Do you use Twitter? I'd like to follow you if that would be okay. I'm absolutely enjoying your blog and look forward to new updates.

  • When you are newbie trader, you can start with just
    one one kind of expenditure. Select an individual home kind which you would take pleasure in beginning with and simply take note of it.

    It is actually beneficial for you to stay focused entirely on one sort and do your best,
    rather than spread your self also slender and only do average
    at multiple assets.

  • nice blog. That's exactly what I was looking for.

  • Such pressure may increase experience other issues, emotional or otherwise.
    Caladuim is a homeopathic treatment for men whose genitals are completely limp.
    If the fear instinct becomes attached to something
    that in reality is not threatening you, anxiety will
    result.

  • Hi to every one, the contents existing at this website are genuinely amazing for people experience, well,
    keep up the good work fellows.

  • I always used to study post in news papers but now as I am a user of net
    thus from now I am using net for content, thanks to web.

  • Hey there! I know this is kind of off-topic but I had to ask.

    Does building a well-established blog such as yours take a lot of work?
    I am completely new to running a blog but I do write in my
    diary on a daily basis. I'd like to start a blog so I can share my experience and thoughts online. Please let me know if you have any kind of recommendations or tips for brand new aspiring blog owners. Thankyou!

  • Keep on writing, great job!

  • Right now it sounds like Movable Type is the best
    blogging platform out there right now. (from what I've read) Is that what you're using on your blog?

  • This post offers clear idea in favor of the new people of blogging, that truly how to do blogging.

  • I create a comment each time I especially enjoy a
    post on a website or if I have something to add to the conversation.

    Usually it's triggered by the passion communicated in the post I looked at. And on this article Building A Silverlight 3 Dashboard With Composite UI - Tony Lombardo. I was actually excited enough to leave a thought ;-) I do have a few questions for you if it's okay.
    Could it be simply me or do some of the comments come across like they are written by
    brain dead individuals? :-P And, if you are writing on additional social
    sites, I'd like to follow everything fresh you have to post. Could you make a list every one of all your communal pages like your twitter feed, Facebook page or linkedin profile?Watch Leverage Season 5 Episode 15 Online

  • You actually make it seem so easy with your presentation but I find this matter
    to be really something that I think I would never understand.
    It seems too complex and very broad for me. I'm looking forward for your next post, I'll try to get the hang
    of it!

  • I have been browsing online greater than 3 hours as of late, yet I never
    found any attention-grabbing article like yours.
    It's lovely worth enough for me. Personally, if all web owners and bloggers made just right content material as you did, the web shall be much more useful than ever before.

  • Please let me know if you're looking for a article writer for your blog. You have some really great articles and I think I would be a good asset. If you ever want to take some of the load off, I'd love to write some articles for your blog
    in exchange for a link back to mine. Please send me an
    email if interested. Regards!

  • You have made some really good points there. I looked on the web for additional information
    about the issue and found most individuals will go
    along with your views on this web site.

  • ミュウミュウ トートバッグミュウミュウ アウトレットルイヴィトンバッグルイヴィトン 店舗ミュウミュウバッグ[url]ミュウミュウの公式通販サイトです。miumiu バッグ新作,ミュウミュウバッグ,ミュウミュウ 長財布,ミュウミュウ,ミュウミュウ アウトレット,ご注文後最短で3日にお 届け!全品送料無料!

  • ルイヴィトン 店舗ミュウミュウ ハンドバッグルイヴィトン財布[url]2013新作ルイビトン公式認証販売店!ルイヴィトン 財布,ルイヴィトン バッグ,ヴィトン メンズ,ルイヴィトン トート激安販売,最高品質割引80%OFF,全国送料無料!

  • ルイヴィトン トートミュウミュウミュウミュウ 激安ミュウミュウ バッグミュウミュウバッグ[url]ミュウミュウの公式通販サイトです。miumiu バッグ新作,ミュウミュウバッグ,ミュウミュウ 長財布,ミュウミュウ,ミュウミュウ アウトレット,ご注文後最短で3日にお 届け!全品送料無料!

  • You could certainly see your enthusiasm within the work you write.
    The world hopes for even more passionate writers such as you who are not afraid to mention how they believe.
    Always go after your heart.

  • Hello, I enjoy reading all of your post. I wanted to
    write a little comment to support you.

  • To whiten teeth is a pretty simple affair if you look at it in
    a research oriented manner. Teeth Whitening Gels Previously acquiring teeth bleaching kits containing bleaching gel,
    you have to verify the formulation has twenty-one particular % concentration and is carbamide peroxide based mostly. Before you proceed with any teeth whitening option, beware: Tooth sensitivity may occur with any method.

  • I loved as much as you'll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get bought an impatience over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly a lot often inside case you shield this increase.

  • The internal memory capacity of the i - Pod Shuffle starts at 2 gigabytes, and a 4 gigabyte model is also available.
    The Frequency Response of these headphones is 18-22,000Hz.
    Also, notably missing is a Fire - Wire communications port, which is necessary to transfer big multimedia files.

  • Great delivery. Solid arguments. Keep up the
    good effort.


  • This is the perfect website for everyone who would like to find out about this topic. You realize a whole lot its almost hard to argue with you (not that I personally will need to…HaHa). You definitely put a fresh spin on a topic that has been discussed for decades. Wonderful stuff, just wonderful!


  • Your style is so unique compared to other people I have read stuff from. I appreciate you for posting when you've got the opportunity, Guess I'll just book mark this site.


  • Spot on with this write-up, I seriously believe that this amazing site needs much more attention. I’ll probably be back again to read more, thanks for the information!


  • I couldn’t resist commenting. Perfectly written!


  • This is a topic that is close to my heart... Many thanks! Exactly where are your contact details though?


  • I could not refrain from commenting. Perfectly written!


  • You have made some really good points there. I checked on the net for more info about the issue and found most people will go along with your views on this website.


  • Everything is very open with a precise description of the challenges. It was definitely informative. Your website is extremely helpful. Thanks for sharing!


  • This is the perfect site for everyone who hopes to find out about this topic. You understand a whole lot its almost tough to argue with you (not that I personally would want to…HaHa). You certainly put a fresh spin on a subject that has been discussed for a long time. Excellent stuff, just excellent!


  • Greetings! Very helpful advice within this post! It is the little changes that will make the most significant changes. Many thanks for sharing!


  • Having read this I believed it was rather enlightening. I appreciate you finding the time and effort to put this article together. I once again find myself personally spending a lot of time both reading and posting comments. But so what, it was still worthwhile!


  • I blog frequently and I really appreciate your information. The article has really peaked my interest. I will book mark your blog and keep checking for new information about once per week. I subscribed to your Feed too.


  • Spot on with this write-up, I seriously feel this site needs a lot more attention. I’ll probably be back again to read through more, thanks for the info!


  • I’m impressed, I have to admit. Seldom do I encounter a blog that’s both equally educative and interesting, and without a doubt, you've hit the nail on the head. The problem is an issue that too few folks are speaking intelligently about. I'm very happy that I found this during my search for something relating to this.


  • There's certainly a lot to find out about this issue. I really like all the points you've made.


  • That is a great tip especially to those fresh to the blogosphere. Simple but very accurate info… Thanks for sharing this one. A must read article!


  • This is a topic that is near to my heart... Take care! Where are your contact details though?


  • This is a topic which is near to my heart... Cheers! Exactly where are your contact details though?

  • If some one needs to be updated with hottest technologies afterward
    he must be go to see this site and be up to date everyday.

  • I am no longer positive the place you're getting your information, however good topic. I needs to spend some time finding out more or understanding more. Thanks for magnificent info I was in search of this info for my mission.


  • I’m amazed, I have to admit. Seldom do I come across a blog that’s both equally educative and entertaining, and without a doubt, you've hit the nail on the head. The issue is something which too few folks are speaking intelligently about. Now i'm very happy that I found this in my search for something regarding this.


  • This is a good tip particularly to those fresh to the blogosphere. Simple but very precise information… Many thanks for sharing this one. A must read article!


  • Howdy! I just want to give you a big thumbs up for the excellent information you have got here on this post. I will be returning to your website for more soon.


  • It’s difficult to find experienced people in this particular subject, but you sound like you know what you’re talking about! Thanks


  • That is a really good tip particularly to those fresh to the blogosphere. Brief but very accurate information… Thanks for sharing this one. A must read post!


  • This is a good tip especially to those fresh to the blogosphere. Short but very precise information… Thanks for sharing this one. A must read post!


  • Nice post. I learn something totally new and challenging on sites I stumbleupon everyday. It will always be interesting to read through content from other authors and use a little something from other sites.


  • Your style is so unique in comparison to other people I've read stuff from. Many thanks for posting when you have the opportunity, Guess I'll just book mark this blog.

  • We're a gaggle of volunteers and starting a new scheme in our community. Your web site offered us with helpful info to work on. You have performed an impressive process and our entire neighborhood shall be grateful to you.

  • I seldom leave a response, but after reading a few of the remarks on Building A Silverlight 3 Dashboard With Composite UI - Tony Lombardo.
    I do have a couple of questions for you if it's okay. Could it be only me or does it give the impression like some of these responses appear as if they are left by brain dead people? :-P And, if you are writing on other places, I'd like to follow anything
    new you have to post. Would you post a list of
    the complete urls of all your social community sites like your Facebook page, twitter feed, or linkedin profile?

  • Very great post. I simply stumbled upon your weblog and wished to say that I have truly enjoyed surfing around your blog posts.
    In any case I'll be subscribing to your feed and I hope you write once more very soon!

  • This is the perfect website for anyone who really wants to understand this
    topic. You realize so much its almost tough to argue with you (not that I
    actually would want to?HaHa). You definitely put a fresh spin on a subject which has been written about for years.
    Excellent stuff, just excellent!

  • I'm not sure exactly why but this web site is loading very slow for me. Is anyone else having this issue or is it a issue on my end? I'll check back later on
    and see if the problem still exists.

  • I for all time emailed this weblog post page to all my friends, as if like to read it
    afterward my friends will too.

Comments have been disabled for this content.