Silverlight interview questions and answers - freshers and experienced

How to implement the style in Silverlight?

Silverlight is a web-based application framework to write rich internet application. The style is a collection of property values that applies to an element. The style allows the application to look more visually appealing. The style is defined in the file named App.xaml.

The silverlight style will be given as:
<Application.Resource>
<Style a:key="app_button" TargetType="Button">
<Setter Property="FontFamily" Value="Verdana" />
<Setter Property="FontSize" Value="36" />
</Style>
</Application.Resource>
This is the programming code that is used to apply the style to a particular Button.
<Button Style="{StaticResource app_button}" Content="app_button" ></Button>

What are the different development tools used in Silverlight?

The tool that is used with the Silverlight application is the Microsoft Visual Studio. The applications are written in .NET language. So, all the associated tools with the .NET language will also work with the Silverlight as well. Microsoft Expression Blend is the tool that is used to develop and design the Silverlight user interface applications. Visual studio is the platform that is used to debug the Silverlight errors and use error free applications. Silverlight usually come in the zip format and it contains the .XAP format that consists of one or more .NET managed assemblies that are stored in .DLL files. It also consists of AppManifest.XAML that contains the entry point including the important classes and assemblies.

What are the different important files that are used in Silverlight?

There are several files that are required to be used in silverlight to make it function properly and to include the properties of applications together:
AppManifest.XAML : it consist the list of all the entry points including the class and assembly. This file can be taken and hosted in any HTML file using an object tag.

The code will be given as:
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"><param name="source" value="MySilverLightControl.xap"/></object>
Silverlight.js and CreateSilverlight.js: contains the initialization of the Silverlight plug-in that will be used in HTML pages.

Write the code to populate the controls in Silverlight

To populate the control in silverlight the requirement is to create the template and their styles. The code mentioned below does it:
The file that is involved in setting up the control is Page.xaml.cs file and then check for the page constructor is being done.
The modification will be done in this file as:
public Page()
{
   InitializeComponent();
   // Write the code for list of items
   IEnumerable list = GetItems();
   // Write the code for Adding of items
   _listBox.ItemsSource = list;
   _cmb.ItemsSource = list;
   // Set the properties of the font from here
   FontFamily[] ff = new FontFamily[]
   {
       new FontFamily("Default font"),
       new FontFamily("Arial"),
   };
   _cmb1.ItemsSource = ff;
}
This allows the setting up the list and combo box to set up the properties of the silverlight functions by using the ItemsSource property.

What are the steps required to set the controls in silverlight?

The steps that are involved in setting up the control in silverlight are as follows:
- First the file Page.xaml.cs will be modified to set the property of a particular page and the style of the page.

- The GetItems() function will be used in the Page class to get the items from the database and it will be written as follows:
List<DataItem> GetItems()
{
   List<DataItem> members = new List<DataItem>();
   foreach (MemberInfo mi in this.GetType().GetMembers())
   {
       members.Add(new DataItem(mi));
   }
   return members;
}
The definition will be added in the DataItem class in the Page.xaml.cs file.

What is the purpose of control templates in Silverlight?

Control templates allow the control of the data templates to allow easy specification in conversion of the data objects into the user interface element objects. This helps the same content to be displayed to the user. The control templates can be used to modify the visual structure of the template with an existing user interface element. The objects will be controlled by using the property of reusability. The control templates have their own visual appearance defined by native XAML resource. This file is contained in assembly of the silverlight that defines that particular control that is getting used.

What are the different resource properties specifying a style?

The control properties that are used to define the resources of the styles include the template properties that are internal. The style element is used to control the template properties that can be visualized in a tree format.

The code that is being given is as follows:
<Style TargetType="Button">
<Setter Property="IsEnabled" Value="true" />
<Setter Property="IsTabStop" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<!-- Focus indicator -->
<Rectangle x:Name="FocusVisualElement" StrokeDashCap="Round"
...=""/>
<!-- Button content -->
<ContentPresenter x:Name="Normal"
Background="{TemplateBinding Background}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"...=""/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

What are the modes that are provided in Silverlight?

Silverlight provides the mode graphics that includes multimedia graphics, animations and interactivity programs at runtime. It is well handled with XAML file and the JavaScript is used to give it overall functionality for user interaction. XAML is used for providing the vector graphics and animations to an application. Textual content can be created using Silverlight as it allows easy to search and index the created graphics that can’t be represented as graphics but text. Silverlight supports the provision to create gadgets and playback of multimedia files or content that is supported by all the browsers. It uses the commercial and non-commercial mode to support both the levels of consumers. It allows the dynamic code that load XML component that can be modified through DOM interface.

Explain the element tree in Silverlight architecture.

Silverlight architecture functions on the properties given below:

Element Tree: is the heart of silverlight application that keeps the object in the tree form like path, image or media element objects. It is a simple container object that stores the data structure in hierarchical methods. It is used to compose and build an application with different properties. It is rich in graphical elements and works just like the DOM (Document Object Model). The XAML parsers are used to build this kind of element tree and it can be provided with CreateFromXAML method used in Silverlight. The element tree wrapper is used to add the code of XML file.

The code that is being written to generate the element tree is as follows:
class xml.etree.ElementTree.Element(tag, attrib={}, **extra)

How to use XAML namescope in Silverlight?

Namescope allows the templates in Silverlight to allow the reusability of the content and it can also include the elements with the names defined at the template level. The template can be reused for more than once in the same page. To be able to do that every single template defines their own XAML namescope that differentiate and make it independent from other templates and styles. Due to the difference in the namescope finding the elements within the template from a page is easy. GetTemplateChild method is used to get the template element from the template used in various pages or in a single page.

The following code is used to set the same template on two different controls:
<UserControlxmlns="http://xyz.com/xaml/presentation"xmlns:x="http://xyz.com/xaml">
<UserControl.Resources>
<ControlTemplate x:Key="Temp">
//write your own code here
<TextBlock x:Name="TextBlock"/>
</ControlTemplate>
</UserControl.Resources>
</UserControl>

How to use XAML namescope at run time?

XAML namescope allow the user to create different template files and reference the objects that are declared in XAML. This allows the separate files to be maintained and make it individually separate from each other. XAML uses the parser that creates a set of objects that retain some or all of the relationships that are declared in XAML files. The relationship manages the specific object properties of the created objects. The namescope is used at run time to identify the individual elements from one another and to give the direct reference to an object instance. The instance becomes enabled by using the markups that is used for compilation process. The initializeComponent method is used to initialize the partial class template. Silverlight consists of build in functions and actions that can identify the namescope for different element at run time. The FindName method can be also used at run time to return the reference of the object that is defined by the XAML markup.

What is the function of an object tree used in Silverlight?

Object tree is used to create and manage the objects in a hierarchical way. This allows easy to make the relation at run time that are related to each other. The relationships are based on the properties of the objects that are similar to one another and the value of the property that are comparatively similar to each other. The object tree consists of branches that are used to store some properties that are collection of other properties and it holds more objects in a chain. The object tree consists of the root element that is considered as parent and it is necessary to maintain the architecture. This architecture is used to reference single object to display the content of it. Object tree structure is composed of parent and child implementation details.

What is the procedure to add an event handler in managed code?

CLR language specific syntax is used to add event handler as XAML is not the only way to add it. XAML allows the event handler to be added to an object. CLR allows the objects to be included even if it is not being used by any program or application. The event handlers to the object can be added during the run time of the object or the lifetime. The callback method also can be used to add an event using the OnApplyTemplate method. By doing this the event handler will be added to the relevant object that will be ready for the use to the events of the user at run time.
The code that will be used to load the event handler in the managed code is given below:
<Grid x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded">
<StackPanel>
<TextBlock Name="text">Text is given as when on mouse hover</TextBlock>
//Write your own code
</StackPanel>
</Grid>

How the even routing method works in Silverlight?

Event routing is an important concept that is based on the visual tree. Routing of the events support RoutingStragegy of Bubble, Tunnel and Direct methods that are used to make it possible.

- Bubble: is the most used routing method used. It allows a bubble to propagate the visual tree from source element till it is handled differently to reach the root element. It also allows the event of an object to be handled by the element hierarchy coming from the source element.

- Tunnel: they start at the root element and then traverse down the element in the tree till they have handled and reached the source element of the event. They have their own names that are prefixed with Preview like PreviewMouseDown.
Direct: are the normal events that handles the event delegates hooked up to an event.

What are the different event modes in Silverlight?

There are two different modes in Silverlight:
Input events: are the browser dependent that hosts the silverlight plug-in. It handles the initial input that is used for the input events. Silverlight has a plug-in architecture that solves the purpose of responding to the event that is being given from the silverlight object model.
Another mode is Non-input event mode: that reports a state change to a particular object in the form of download state or some actions that shows the progress done in web client. There are some frameworks that provides the lifetime information of an object at a framework level. It allows an even to be loaded at a particular instance to show the progress initiated by the web client.

What is the difference between logical and Visual tree?

Visual tree is the representation of the object tree that is being filtered and modified. Visual tree also reports the objects that are part of the control in a composite form. Visual tree is used for rendering process that includes control template and analysis of control’s structure. Silverlight comes with VisualTreeHelper API that represents the tree in a generalized way. It shows object parent and child relationship properties.
The files that are used are as follows:
- System.Windows.Controls.ListBox
- System.Windows.Controls.Border
- System.Windows.Controls.ScrollViewer
- System.Windows.Controls.Grid
- System.Windows.Shapes.Rectangle

Logical trees add content to the elements using different properties that is being provided with other controls and item properties. Logical tree shows the content model and iterate over the child elements and the content models can be made extensive for the use only. It provides a framework for notifications till all the contents models are not loaded.

Example: ListBox and the files that are used are:
- System.Windows.Controls.ListBox
- System.Windows.Controls.ListBoxItem
- System.String

What are the different classes used in Visual tree?

The different classes that are used in Visual tree are as follows:
- ScrollViewer: allows to include an area that is scrollable and contains the visible elements of it like scroll bar.
- ScrollContentPresenter: allows the content of the ScrollViewer to be displayed.
- ItemsPresenter: allows the control of the specific item to be used in a visual tree where it present the items that has to be arranged in a panel using ItemsPanel and ItemsControl.
- VirtualizingStackPanel: this arranges the stack panel and virtualizes the content used in it in a single line that can be made oriented in any direction either horizontal or vertical.
- ContentPresenter: allows the user to present and displays the content of a ContentControl method. It also allows the flow of the content to be managed together in one way and can be represented together.

How does the rendering engine work in Silverlight?

Silverlight allows many functionalities and provide a rendering engine that optimizes the content of the element tree. It also gives the desired rate of conversation to indicate the optimization technique used in the plug-in. The rendering process involves incremental approach to redraw the frames to reduce the number of pixels in the image and of the content that is changing. It also include non-rasterizing the content that is uncomplete. Silverlight uses vector graphics as data format that can be easily scaled and the size and display can be changed accordingly. The user interface provides lots of tools like Button, etc. that helps in creating user interface element and help in developing a process in which rendering of the objects takes less time. There is a process of rendering that takes place from the root that is top-most node and then progresses to its child from left to right.

What does rendering engine in the Silverlight includes?

Rendering engine is a powerful engine to render the visual appearance and the content of the page. It also helps in controlling the content of the page. It includes the following:

- Text rendering support: it helps in rendering the text that can be used by the content and to make the visual appearance more effective.
- Subpixel positioning: it helps in positioning the pixels and the pixels that are contained by the previous one together. It helps in maintaining a format between the pixels that provide the correct aligning of it.
- Custom anti-aliasing for sharper text: Anti aliasing allows the text to be more smooth and to soften the edges of the text. It helps in making the text more legible by aligning text that remains on the pixel positions and rendered in small font sizes. Custom anti-aliasing helps in choosing the better option of it.
- Transforms: the transform can be of many type but the main type is path transform or brush transform that is used to transform the text and graphics by resampling the content and the data involved in it.

What is the difference between Glyph cache and Image cache?

Image cache caches the content associated with the image that is downloaded from a specified URL. If the references will be made to the image multiple times then the image will be loaded from the cache and the time of loading will be less. The pattern or the process will be much more faster. Whereas Glyph cache is used for text based engine to produce rendered text files by rendering the fonts and its properties. Glyph optimizes the readability and increase the resolution of the text that has to be changed. It also applies to the dynamic change of the text and apply the visual properties dynamically.
Silverlight architecture
Silverlight architecture - Silver light is a plug-in used for different platforms and browsers. It is designed for offering media experiences...
Difference between WPF and Silverlight
Difference between WPF and Silverlight - In terms of features and functionality, Silver light is a sub set of Windows Presentation Foundation...
Limitations of using external fonts in Silverlight
"Limitations of using external fonts in Silverlight - One of the major challenges is to use a downloader and some of the SetFontSource methods on a TextBlock to perform it..
Post your comment
Discussion Board
Silverlight interview questions and answers
What are the graphics related features supported in Silverlight?
Use of graphics nowadays is common as more and more websites are started using lots of graphics in there web pages. Silverlight also supports most of the graphics design and provides lots of features such as:
- Draw 2D vector graphics such as rectangle, ellipse, and path, with fill and/or stroke.
- Brushes: SolidColorBrush, Linear/RadialGradientBrush, ImageBrush, VideoBrush.
- Opacity mask.
- Shape (supports mouse/keyboard events) and Geometry (lightweight).
- EvenOdd and Nonzero path fill rule.
- Affine transforms.
- Render bitmap images encoded with jpg and png.
- Ink and stylus devices.
Rohit Sharma 12-16-2011
Silverlight interview questions and answers
What is the cross domain/scheme/zone policy? How do I configure it?
Cross domain is the domain that is represented by a single domain name. Ex: www. Abc.com. If a Silverlight application is being hosted under one domain and the resources are being on another domain then it is considered as cross domain.
Cross Scheme consists of three types of schemes, which are as follows:
1. http
2. https
3. file
If the file is hosted under http or https or file scheme, then it is a cross scheme.
Cross Zone is browser specific and they differ browser to browser. You can find them in your browser’s security options.

How do I provide a cross domain policy file for a self-host WCF service?
It is quite easy to provide the cross domain policy file for self-host WCF services, but it requires programming to be done on the other side to do it. Example code:
ServiceHost host = new ServiceHost(typeof(Service1));
host.Open();
Console.Read();
host.Close();
<add baseAddress="http://localhost:8731/Service1/" /> // base address
When you will call the service from the Silverlight application, you will get a cross domain issue which can be solved by putting the cross domain file in the same directory with the console .exe.

What are the restrictions of web service accessing in Silverlight?
Silverlight provides and supports lots of features but there are some restrictions as well, such as WS-Security and WS-Addressing are not supported. When working with the languages such as ASMX/JAVA/PHP, you need to see that you have SOAP 1.1 and WS-I Basic Profile 1.0. Silverlight only support GET and POST actions, others are not supported. It doesn’t have full http features also.
Rohit Sharma 12-16-2011
Silverlight interview questions and answers
What is the real advantage of using Excel/Word files or local database in Silverlight?
The real advantage of using Excel or World files or any local database in Silverlight is that it provides easy to manage features for store and fetching the data, which are frequently used by the applications. It doesn’t rely much on WCF services to provide the properties for data communication. The data is automatically fetched and saved in excel or word sheets for future references.

What are the advantages of Extensible Application Markup Language (XAML) over C# or VB.NET?
XAML is the language which is used with Silverlight. It is one of the growing languages that has lots of features and properties. The advantages of it over C# or VB.NET are that:
C# or VB.NET provide development by using coding whereas, XAML provides codeless development and provides lots of features to create complex user interface controls etc. It can also define an instance of class which is being already defined by C# or VB.NET.

Can you use any specific Patterns in Silverlight programming?
Yes, you can use any specific patters in Silverlight programming, as it provides Model-View or View-Model approach. This approach provides the provision to create loosely coupled application where the code is completely isolated from XAML. Prism which is a set of classes provided for development of such applications can also be used to provide more flexibility.

What is namescope in Silverlight?
Name scope in Silverlight stores the relationship between XAML and the objects which are being defined by the XAML, with their instance equivalents. Whenever, you create a new object, a new name scope will automatically be created. But, there is a problem in this, when name scope is being created for the dynamic objects, sometimes it causes an exception to occur or some kind of error.
Rohit Sharma 12-16-2011
Silverlight interview questions and answers
What types of security measures are provided with Silverlight?
Silverlight is Microsoft based technology and it come up with some security features, to make it secure to use and implement. For secure communication its applications makes use of WCF services and uses WCF security features. SSL (Secure Socket Layer) can be used for security mechanism to give the transport layer security.

Does Silverlight application supports desktop implementation?
Yes, Silverlight supports desktop implementation. Newer version of Silverlight provides out-of-browser facility, by using this feature it can be physically deployed on the local machine. Silverlight 4.0 supports OOB facility that enhances the communication with other applications like Word, Excel etc. and with the local database like MS Access etc.

Where is the Silverlight application present?
Silverlight application resides on the host computer where the ASP.NET is installed. It resides in the ASP.NET webpage, but it can be hosted on other HTML pages too, by using the extension .xap. Silverlight application is made available to the browser when a user makes a HTTP request to ASP.NET page.

What are the controls provided in Silverlight for Line-of-Business (LOB) applications?
Silverlight provides lots of applications for Line-of-Business (LOB) to have better communication among the elements and also to enrich the properties of the application. The controls which are being provided by the Silverlight are as follows:
- Data Grid: The representation of data in a grid form
- Data Form: Representation of data in a form
- Chart controls: Representation of data in chart forms and has additional functionality to display the controls for customization.
Rohit Sharma 12-16-2011
Silverlight interview questions and answers
What is the relationship between Silver Light, WPF and XAML?
Silverlight is used to read and render the user interface (UI) elements. XAML is a XML file that defines the user interface elements. This file is being read by the WPF framework. Microsoft developed WPF framework and then extended it to WPF/e, which helped the application to render user interface in the browser. Silverlight is being officially launched by Microsoft.

Explain SilverLight architecture?
Silverlight is a plugin that is provided by the Microsoft. Silverlight architecture includes the functionality from core .NET framework, Ajax and having some of its own functionality such as animation, media etc. The architecture consists of four blocks:
- .NET framework components: WPF is .NET framework, used in Silverlight.
- Presentation core: core presentation framework includes the display options such as images, vector animations etc.
- Other technologies: Ajax and JavaScript technologies are used to interact with Silverlight framework.
- Hosting: Silver-light animations run under the browser environment and it also provides lots of other application hosting programs.

What type of applications can be developed using Silverlight?
Silverlight is a plug-in, which can be used to develop web based or mobile based applications. Silverlight is used in those applications where you need to represent the graphics or the output should be in graphical format. Silverlight can be used in various types of Line-of-Business applications such as: Healthcare, Insurance, Logistics etc. One of the good example of its application is healthcare application.
Rohit Sharma 12-16-2011