Silverlight5 : Tips and tricks

When we are new to any technology, we spend hours to solve any simple problem, right? This article will help all sliverlight5 beginners to overcome difficulties in developing sliverlight5 application. I hope it will be helpful for you all.

Silverlight5 : tips and tricks
Tip 1: If you have two xaml pages in your application and you do not know how to set up start up page for the execution then this will help you.
To set start up page you need to make changes in App.xaml.cs page. You can use following code:

private void Application_Startup(object sender, StartupEventArgs e)
//after new put the name of the xaml page which you want to display as start up page.
this.RootVisual = new MainPage ();

Tip 2: How to put scrollbars to grid?
You have to use scrollviewer control and set the properties as follows:

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Height="488">

Tip 3: Easy way to navigate xaml page is as follows:
There is alternative for navigation frame is put this code in some button's click event.

this.Content = new nextpagename ();

This will create object of next page which you want to navigate and will open in the browser.
Tip 4 : Different ways of Data binding to datagrid control.
If you want any kind of binding for static data with datagrid control then it can be done through observable collection. If you want to bind XML data then it is also possible.
Similarly data from database can be bound via WCF RIA services. Sliverlight enabled WCF service helps in this type of binding. You have to give service reference and consume that WCF service in your application.
Tip 5 : How to set up controls on Silverlight 5 Tab control ?
You have to use stack panel and put different controls in it for each tab so that when you click on any particular tab then different controls will appear for each tab.

<sdk:TabControl HorizontalAlignment="Left" Margin="20,89,0,8" Name="tabMenu" Width="1059" FontFamily="Lucida Sans Unicode" FontSize="15" FontStretch="Condensed"
<GradientStop Color="White" Offset="0" />
<GradientStop Color="#FF19AAD8" Offset="1" />
<sdk:TabItem Header="TabItemname1" Name="TabItemname1" Background="#FF637A8D">
<!-- put grid and other controls which you want to display for TabItemname1-->


<sdk:TabItem Header="TabItemname2" Name="TabItemname2">
<StackPanel >
<!-- put grid and other controls which you want to display for TabItemname2-->


Tip 6 : How to unload xaml page along with warning message for confirmation ?

private void btnCancel_Click(object sender, RoutedEventArgs e)

This will first ask user whether he wants to close browser or not, if user clicks on "yes" then it will unload application and close the browser.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: