Starting Silverlight Development with Samples

I was never a Silverlight Developer but after spending some time on SharePoint 2010 and watching the SL Dialogs all way around I decided to play with it for a moment. I never knew how SL Works. Just saw couple of vidoes and some SharePoint Sessions talks on Silverlight and SharePoint Integration that also shows SharePoint Client OM. So After spending some time on Hello Worlds I search on SL Toolkit and I am so happy that I found this link. When you see a running examples of the controls it is so easy to start development. The Link to the sample is given below. some of you are already experts so dont feel tough on me. I am just a begginer.

but I have completed web part that displays pending tasks to users which prooved quite handy in my situation as I was able to develop it in just 2 days. I will try to post the code soon.

I must say that Silverlight is simply “AWSOME”.

Client Object Model Basic Example – CAMLQuery

I was able to make a nice CAML Query Work in my Silverlight application so though it might be worth posting it over here as it might help some one. It is a query to read all items assigned to me or the group I am part of and the status is not completed. Now you can go ahead by your self and play with Query as you wish and make it to complex. But it is a working example.

void DoIt()
using (ClientContext ctx = ClientContext.Current)

string OrderBy = <OrderBy><FieldRef Name=’Created’ Ascending=’FALSE’/></OrderBy>;
                string Where = <View><Query><Where><And> +
                        <Or> +
                            <Membership Type=’CurrentUserGroups’> +
                                <FieldRef Name=’AssignedTo’/> +
                            </Membership> +
                            <Eq> +
                                <FieldRef Name=’AssignedTo’/> +
                                <Value Type=’Integer’> +
                                    <UserID/> +
                                </Value> +
                            </Eq> +
                        </Or> +
                        <Neq> +
                            <FieldRef Name=’Status’/> +
                            <Value Type=’Text’>Completed</Value> +
                        </Neq> +
                    </And></Where></Query> + OrderBy + </View>;

CamlQuery Query = new CamlQuery();
Query.ViewXml = Where;

TasksListItemCollection = ctx.Web.Lists.GetByTitle(“Tasks”).GetItems(Query);

ctx.ExecuteQueryAsync(Success, Fail);


void Success(object sender, ClientRequestSucceededEventArgs e)
this.Dispatcher.BeginInvoke(() =>
txtTaskCount.Text = TasksListItemCollection.Count.ToString();
catch (Exception ex)
MessageBox.Show(ex.ToString() + ex.StackTrace);


void Fail(object sender, ClientRequestFailedEventArgs e)
this.Dispatcher.BeginInvoke(() =>
MessageBox.Show(“Failed to Load Items ” + e.Exception.ToString());

Thanks to Thousands of Blogers who blogged about Silverlight and SharePoint Client Object Model.

Creating a Dialog from Silverlight

A simple piece of code for Creating a Dialog from Silverlight.

private void button1_Click(object sender, RoutedEventArgs e)
ChildWindow flotwin = new ChildWindow(); flotwin.Title = “Blue Window”;
System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();

flotwin.MouseLeftButtonDown += (a, x) =>

popup.IsOpen = true;

StackPanel stackPanel = new StackPanel()
Height = 600,
Width = 800

WebBrowser browswer = new WebBrowser();
browswer.Width = 800;
browswer.Height = 600;
browswer.Navigate(new Uri(http://MyServer/));

flotwin.Content = stackPanel;
flotwin.Closing += (ss, ee) =>
popup.IsOpen = false;

popup.Child = flotwin;
popup.IsOpen = true;


Special Thank to Usama Wahab Khan

Right To Left Support Silverlight 4

Just find a nice property in Silverligh 4 that support Right to Left Support.

FlowDirection=”RightToLeft” | “LeftToRight”

Setting it to StackPanel e.g. will set everything to Right to Left.  I just used it with grid control.

<StackPanel Orientation=”Vertical” FlowDirection=”RightToLeft”>



Get All Tasks Assigned to ME or Group I am part Off

Below is the CAML Query to get All the task assigned to me or the group I am part of.  And only tasks which are not complete.

     <GroupBy Collapse=”TRUE” GroupLimit=”50″>
      <FieldRef Name=”AssignedTo”/>
      <FieldRef Name=”Created” Ascending=”FALSE”/>
        <Membership Type=”CurrentUserGroups”>
         <FieldRef Name=”AssignedTo”/>
         <FieldRef Name=”AssignedTo”/>
         <Value Type=”Integer”>
        <FieldRef Name=”Status”/>
        <Value Type=”Text”>Completed</Value>
     <FieldRef Name=”Created”/>
     <FieldRef Name=”LinkTitleNoMenu”/>
     <FieldRef Name=”Status”/>

     <FieldRef Name=”Title”/>

     <FieldRef Name=”ID”/>
     <FieldRef Name=”WorkflowLink”/>

Some cool SPQuery Links

How to Set Null Values to Query

Working with Large Lists in SharePoint 2010 – List Throttling