Dashboard in Silverlight 4


Introduction
 
In this article we will see how we can make a Dashboard in Silverlight 4.
 
1.gif
 
Create Silverlight Application
 
Fire up Visual Studio 2010, and select Silverlight Project from the templates. Name the solution as DashboardSample.
 
2.gif 

A Dashboard is a page that contains brief description of a large content or any tool on the page. For example igoogle. It consists of varieties of gadgets, that can be added or removed.
 
We will see how to start with a Dashboard.
 
I am going to add couple of RSS feeds from some sites, twitter tweets and a Calculator to the Dashboard.
 
Before that we need to have a Widget Control that can hold the Content or Tool.
 
Widget Control
 
Widget control is a control with fixed size and style, which can contain the widget inside it.
 
Add a Silverlight User Control name it as WidgetControl.
 
3.gif
 
Open up Expression Blend 4 and design it. I have designed it as displayed below.
 
4.gif 

 
5.gif 
 
If you look into above Objects in the panel, you could see we have a Title Text, 3 Image Buttons, and a Border to contain the widget.
 
A Dependency Property called TitleProperty is added.
 
6.gif 
Then we have the Routed events for minimizing and restoring the widget.
 
7.gif
 
Calculator Control
 
This is a calculator with simple operations.
 
Add a User Control to the Silverlight project and name it as UCCalculator.
 
8.gif
 
As I said it is a simple calculator, and you can design it in either of the tools (Expression Blend or VS 2010).

9.gif
 
You can refer the source code, for the calculator user control code, as it is commonly used code.
 
RSS Feeds Control
 
Add a new user control to the Silverlight project and name it as UCRSSFeeds.
 
10.gif

 
Let's create a class named RSSFeeds which would have the below properties.

 
11.gif 

 
We will have a ListBox to display the feeds.

 
12.gif 
The following is for loading RSS Feeds. As you can see we have created an overloaded constructor through which we can pass the RSS Feed url.
 
13.gif 
14.gif
 
Twitter Control
 
Add a new user control to the Silverlight project and name it as USTwitter.
 
15.gif

Add a class named Twitter which would contain the following properties.
 
16.gif 

We need to add a ListBox to display the data from the Twitter api call.
 
Following is the xaml code for the data template of the ListBox.

17.gif 

Add the following code for getting the feeds from twitter api.
 
18.gif
 
Authentication Issue
 
In Silverlight 4 we cannot have the RSS Feeds or twitter api call directly, for that we need to have the application running in OOB mode as well as with Elevated Privilege. 
 
19.gif
 
20.gif 

Adding Widgets
 
As per requirement we can have widget panels defined. For example 3 column widget panel or 2 column widget panel.

In our case I have taken two panels such as Left Panel and Right Panel.
 
The MainPage.xaml has the following two panels.

21.gif 

We can add the Widgets to the WidgetControl and then to the columns as following.

22.gif
 
That's it now we can run the application and see the Dashboard.
 
24.gif
 
Hope this article helps.


Similar Articles