Silverlight Interview Questions – I

Hello folks,

Marching forward, I will post a series of Interview Questions on Silverlight.  This would be first of its kind. This will cover questions at each level – easy, intermediate and advanced.  And I am sure, other sites & users would post these on many other sites too :)

So keep watching this space. Some questions below to start with

Level: Developer 

  • What is the role of Silverlight Plugin in the Silverlight Application Life-Cycle?
  • What does the keyword ‘type’ signify in the Silverlight Hosting page.
    <object data="data:application/x-silverlight-2,"
    type="application/x-silverlight-2" width="100%" height="100%">
    
  • You have developed an application on Silverlight 2, will it execute on Silverlight 4 platform? Is vice-versa true?
  • Your organization has blocked download of any software from Internet and you want to deploy your Silverlight Application as Intranet Application.  The users do not have Silverlight plugin installed on their machine; however you have the installable.  How do you plan to deploy your application? Will you change the application code to fit this requirement or change the organization policy?
  • Your Silverlight application faces some technical errors while it is executed. Where will you write your code to get notification of these errors?
  • Can any Silverlight Application be viewed on Linux? Or a specific installation is required?
  • Assume your host page defines the background as White
    <param name="background" value="white" />
    

    while your MainPage.xaml (that loads initially) defines background as ‘Gray’

    <Grid x:Name="LayoutRoot" Background="Gray">
    

    What will be the color of the background?

  • I have two actors to a Silverlight Application – Employee and Customer. The default page (default.html) should always open Customer view; whereas \view\employee.html should open Employee view.

    How would you implement this?

  • What is significance of initParams in
    <param name="initParams" value="symbol=true" />
    
Continue reading » · Rating: · Written on: 02-12-10 · 1 Comment »

Customizing Splash Screen in Silverlight

Customizing Splash Screen (a screen that loads before the Silverlight application loads) requires some development effort in the host application (could be HTML/ASPX/any other application).

Creating SplashScreen.xaml

First, we create a XAML file – say SplashScreen.xaml file which displays two things – a progress bar and a textblock that displays ‘% completed’


<Grid xmlns="<a href="http://schemas.microsoft.com/client/2007">http://schemas.microsoft.com/client/2007</a>"
        xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>">
   <StackPanel VerticalAlignment="Center">
      <Grid>
        <Rectangle x:Name="<strong>baseBackground</strong>" Fill="Black" Stroke="White" StrokeThickness="1" Stretch="Fill" Height="30" Margin="100,20"></Rectangle>
        <Rectangle x:Name="<strong>movementBar</strong>" Fill="Gray" Height="28" Margin="101,20">
          <Rectangle.RenderTransform>
            <TransformGroup>
              <ScaleTransform x:Name="<strong>movementBarTransform</strong>" ScaleX="0" ScaleY="1"/>
            </TransformGroup>
          </Rectangle.RenderTransform>
        </Rectangle>
      </Grid>
      <TextBlock x:Name="<strong>progressText</strong>" HorizontalAlignment="Center" Text="0% downloaded ..."></TextBlock>
    </StackPanel>
</Grid>

Here, we have a baseBackground (that forms background) that is Black in color and small bar that will move ‘movementBar‘ which is Gray in color.

As the page downloads the data, movementBarTransform needs to be changed, so that the movementBar appears as if it is increasing. And simultaneously, progressText should display the % downloaded.

Modifying host file

Now let’s modify the host file that loads the Silverlight Application.


<object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
   <param name="source" value="ClientBin/SplashScreen.xap"/>
   <param name="onerror" value="onSilverlightError" />
   <param name="background" value="white" />
   <param name="splashscreensource" value="SplashScreen.xaml" />
   <param name="onsourcedownloadprogresschanged" value="onSourceDownloadProgressChanged" />
   
   <a href="<a href="http://go.microsoft.com/fwlink/?LinkID=115261">http://go.microsoft.com/fwlink/?LinkID=115261</a>" style="text-decoration: none;">
        <img src="<a href="http://go.microsoft.com/fwlink/?LinkId=108181">http://go.microsoft.com/fwlink/?LinkId=108181</a>" alt="Get Microsoft Silverlight" style="border-style: none"/>
   </a>
  </object>

The most important line that calls a JS function ‘onSourceDownloadProgressChanged’ when some part (bytes) of the XAP is downloaded is:


 <param name="onsourcedownloadprogresschanged" value="onSourceDownloadProgressChanged" />

Adding JS in hosting file


function onSourceDownloadProgressChanged(sender, eventArgs)
        {
       
         sender.findName("progressText").Text = Math.round((eventArgs.progress * 100)) + "% downloaded ...";        
         sender.findName("movementBarTransform").ScaleX = eventArgs.progress;        
        }

This code snippet calculates the percentage of XAP file downloaded and displays it in the textbox.  It also increases the ScaleX property of ScaleTransform of movementBar as per the progress.

Testing the Splash Screen

Now, add some heavy sized ZIP file in the Silverlight application so that your XAP file becomes atleast 5 MB and try to execute the application. 

What you would see is a new custom Splash Screen

Continue reading » · Rating: · Written on: 02-10-10 · No Comments »