dotnet thoughts 

a dotnet developer's technical blog

Full screen option in Silverlight

Like Adobe Flash, Silverlight also supports full screen option. You can enable Full Screen option by setting the IsFullScreen property to true. This property available under Application.Current.Host.Content class.

You can toggle the Full Screen mode and normal mode using

Application.Current.Host.Content.IsFullScreen
= !Application.Current.Host.Content.IsFullScreen;

Happy Coding… :)

Hosting Silverlight application in Sharepoint 2010

Microsoft SharePoint 2010 comes with an out of the box Silverlight webpart which helps to host Silverlight applications in SharePoint. For hosting the Silverlight application you need to provide the URL of the Silverlight executable in the URL property of the webpart.

Configure URL Property of Silverlight Web Part

Configure URL Property of Silverlight Web Part

You can also pass the parameters to the Silverlight application using InitParams property.

Init Params Property

Init Params Property

You need to implement the Silverlight application such a way that it can accept and use the InitParams, which can be consumed in Application_Start event.

private void Application_Startup(object sender, StartupEventArgs e)
{
    IDictionary<string, string> parameters = e.InitParams;
    foreach (KeyValuePair<string,string> parameter in parameters)
    {
        Console.WriteLine("{0} - {1}", parameter.Key, parameter.Value);
    }
}

How to access SharePoint List Items using Silverlight Object Model

In the last postI introduced the Silverlight Object Model, which helps to access the SharePoint objects directly from Silverlight. In this I am posting about how to access SharePoint List Items using Silverlight Object Model. In this I am using Caml query object, which is used to get the Fields.

private Web oWebSite = null;
private List oList = null;
private ListItemCollection oListItems = null;
private ClientContext clientContext = null;

this.clientContext = ClientContext.Current;
if (this.clientContext == null)
{
this.clientContext = new ClientContext(url);
}
using (this.clientContext)
{
this.oWebSite = clientContext.Web;
this.oList = this.oWebSite.Lists.GetByTitle(this.listName);
this.oListItems = this.oList.GetItems(CamlQuery.CreateAllItemsQuery());
    clientContext.Load(this.oListItems);
clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
}

private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
//FillItems method converts the List items to Class Properties
//and binds them to the Silverlight User Interface.
this.Dispatcher.BeginInvoke(new Action(FillItems));
}

private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
MessageBox.Show("An error occured.\n" + args.Message + "\n" + args.StackTrace);
}

And if you don’t want all the columns or you want to specify the columns you want to access you can use Caml Query object’s ViewXml property.

CamlQuery camlQuery = new CamlQuery();
string query = "<OrderBy><FieldRef Name='Name' Ascending='False' /></OrderBy>";
camlQuery.ViewXml = query;
this.oListItems = this.oList.GetItems(camlQuery);

You can access CustomLists and Document Libraries by this method.

Using the Silverlight Object Model

Recently I moved to a new project where I have to integrate Silverlight with SharePoint. I had done a few posts regarding this also. Yesterday I found that in SharePoint 2010(SharePoint foundation), Microsoft introduces Silverlight Object Model which helps to access SharePoint Lists and Document Libraries directly from Silverlight.

Here is my first experiment with Silverlight Object Model which helps to retrieve all the Lists from a given SharePoint site, and displays it in a Combo Box.

private Web oWebSite;
private ListCollection collList;
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
    using (ClientContext clientContext = new ClientContext("http://sharepoint2010/"))
    {
        this.oWebSite = clientContext.Web;
        this.collList = this.oWebSite.Lists;
        clientContext.Load(collList);
        clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
    }
}

private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
    this.Dispatcher.BeginInvoke(new Action(DisplayLists));
}
private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
    MessageBox.Show("An error occured.\n" + args.Message + "\n" + args.StackTrace);
}

private void DisplayLists()
{
    foreach (List item in collList)
    {
        lstItems.Items.Add(item.Title);
    }
}

Because query execution is asynchronous when you use the SharePoint Foundation Silverlight object model, you must pass delegates for callback methods as parameters in the ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler) method.

The hash value is not correct – Silverlight Installation Error

While installing Silverlight some time you may get an error like The hash value is not correct. You can get more details about the error on clicking the Log File link in the error dialog. This error is coming may be because the setup is unable to download the Silverlight_Developer.exe / Developer runtime failed to download correctly.

The hash value is not correct - Error Screenshot

The hash value is not correct - Error Screenshot

You can resolve this error by copy / paste the Silverlight_Developer.exe to the “%TEMP%/Silverlight 3.0 Tools folder”. You can download the Silverlight_Developer.exe from here – http://go.microsoft.com/fwlink/?LinkID=150228

« Newer PostsOlder Posts »