Tuesday, November 1, 2011

Interview Questions Silverlight


What is Moonlight?

Moonlight is an open source implementation of Silverlight, primarily for Linux and other Unix/X11 based operating systems. In September of 2007, Microsoft and Novell announced a technical collaboration that includes access to Microsoft's test suites for Silverlight and the distribution of a Media Pack for Linux users that will contain licensed media codecs for video and audio.

What is RIA service?

WCF RIA Services simplifies the development of n-tier solutions for Rich Internet Applications (RIA), such as Silverlight applications. A common problem when developing an n-tier RIA solution is coordinating application logic between the middle tier and the presentation tier. To create the best user experience, you want your RIA Services client to be aware of the application logic that resides on the server, but you do not want to develop and maintain the application logic on both the presentation tier and the middle tier. RIA Services solves this problem by providing framework components, tools, and services that make the application logic on the server available to the RIA Services client without requiring you to manually duplicate that programming logic. You can create a RIA Services client that is aware of business rules and know that the client is automatically updated with latest middle tier logic every time that the solution is re-compiled.

What is the difference between WCF and RIA service?

RIA Services gives you is code generation. It creates your classes for you. You only need to put the business logic. I think RIA Services is very useful for developing small to mid apps very rapidly.
Another difference is that it hides the asynchronous calls to the web service. Many people don't like the async model (which is the only one you can use in Silverlight) and a RIA service handles that for you.

How many types of binding are there in Silverlight?

There are three types of data binding that happens in Silverlight applications between a source and target.
1.       OneTime data binding
2.       OneWay data binding (default mode)
3.       TwoWay data binding
OneTime data binding: As the name suggests, data binding happens between the source and target only once. In this binding, the source (CRL object) data will bind with the target (XAML element) only when the page executes the first time. Later on, any changes made in the source will not be reflected back in the target element. You will prefer to use this binding mode to reduce overhead if you know that the source property won’t change.
OneWay data binding: In this data binding, the source will immediately inform about changes to the target control. We will be using this binding only for frequently changed elements. This is the default mode.
TwoWay data binding: This happens in bidirectional mode. Whenever any change occurs in the backend or the CRL object, it will inform to the XAML controls immediately, and vice versa.

 What is a storyboard?

Controls animations with a timeline, and provides object and property targeting information for its child animations.

What is the difference between Label and a text block controls?

Even though TextBlock lives in the System.Windows.Controls namespace, it is not a control.  It derives directly from FrameworkElement.  Label, on the other hand, derives from ContentControl.  This means that Label can:
1.       Be given a custom control template (via the Template property).
2.       Display data other than just a string (via the Content property).
3.       Apply a DataTemplate to its content (via the ContentTemplate property).
4.       Do whatever else a ContentControl can do that a FrameworkElement cannot.

What are Pixel Shedders?

A pixel shader is an object that transforms pixels output from the rendering pipeline before they're rendered to the display surface.

What is the difference between WPF and Silverlight?

WPF is for desktop applications- you create an .exe file when you build WPF applications. To run a WPF exe requires you to have Framework 3 or higher on your pc.
Silverlight is on the web. What you create is an application that can be hosted either in an html page or an asp.net page. To watch it from your browser it requires to have installed in your browser the silverlight plugin. Silverlight uses very fewer libraries than WPF does, and that's pretty logical because Silverlight’s CLR is in the plugin which is about 5-10 MB.
WPF and silverlight though use the same logic in development and the same technology.

Can WPF application runs in browser, if so then why do I go for Silverlight?

WPF applications can be deployed to the desktop or run in Internet Explorer (on Windows only, as far as I know). When WPF application run in Internet Explorer they run in a sandbox, so users simply point Internet Explorer at an URL and your application appears without any installation or confirmation need. All development tools are the same (Visual Studio) when making desktop and browser-based WPF applications and you can use the same widgets for both.
WPF running in Internet Explorer have some restrictions compared to a program running on the desktop. For example, opening new windows is not possible and communication (WCF) is not allowed. Apparently SOAP calls can be used instead.
Making a WPF application run in the browser is easy. You create a project in Visual Studio marking it as a “WPF Browser Application”. After compilation, you publish the executable to a web server. I think one idea in Visual Studio is to allow a desktop-based WPF application and the same browser-based application to be produced from the same codebase. I have not tried this yet, but this looks like a promising concept.
Like WPF-applications can run in a browser, so do Silverlight applications. But Silverlight applications can be deployed to more platforms (OS X and Linux) and more browsers. This does however come with a cost… Like browsers-based WPF applications lose access to some functions compared to desktop applications, Silverlight applications can build on even less infrastructure. The GUI is one (of many) missing elements in Silverlight

What us the difference between DataTemplate, ControlTemplate and HierarchicalDatatemplate?

Before we get into differences between them, let me show how one would typically use them. It’s a good practice that all your templates are embedded inside resources / styles. It makes your XAML centralized, shareable and easier to understand (a refactored XAML of sorts, waiting for ReSharper to include this refactoring.
Don’t Do:

[ListBox]
            [ListBox.ItemTemplate]
                [DataTemplate]
                    [!– Your Data Template Goes here–]
                [/DataTemplate]
            [/ListBox.ItemTemplate]
[/ListBox]
Recommended:
[Window.Resources]
        [DataTemplate x:Key=”myDataTemplate”]
            [!– Your Data Template Goes here–]          
        [/DataTemplate]
[/Window.Resources]
[ListBox ItemTemplate=”{StaticResource myDataTemplate}” /]
The above XAML holds true also for HierarchicalDataTemplate & ItemsPanelTemplate. But it won’t quite work for ControlTemplate, as ControlTemplate can be assigned to Template property of a class that inherits from ContentControl class, which ListBox doesn’t.
So the listbox code would typically look like this:

[ControlTemplate x:Key=”myControlTemplate” TargetType=”{x:Type ListBoxItem}”]
            [TextBox /]
[/ControlTemplate]
[ListBox]
            [ListBoxItem Template=”{StaticResource myControlTemplate}” /]          
[/ListBox]
But the problem with above snippet is, you are manually specifying item which is never the case in real world. Ideally you would like to bind ItemsSource Property of ListBox with some collection obtained at runtime from your data access layer. Solution to this problem is creating a style and binding it to ItemContainerStyle property of ListBox. By doing that you will be able to use ItemsSource for Binding & the ControlTemplate which is present inside the style will be applied to each binded item.

[ListBox x:Name=”myList” ItemsSource=”{Binding}” ItemContainerStyle=”{StaticResource myStyle}” /]
[Style x:Key=”myStyle” TargetType=”{x:Type ListBoxItem}”]
            [Setter Property=”Template”]
                [Setter.Value]
                    [ControlTemplate TargetType=”{x:Type ListBoxItem}”]
                        [TextBox Text=”{Binding collectionPropertyName}” /]
                    [/ControlTemplate]
                [/Setter.Value]
            [/Setter]
[/Style]

ItemsPanelTemplate is mainly used by controls inheriting from ItemsControl class for displaying their Items. ItemsPanelTemplate can be customized through ItemsPanel property of ItemsControl class or any class which inherits from ItemsControl. 

[ListBox x:Name=”myList” ItemsPanel=”{StaticResource myItemsPanelTemplate}” /]
[ItemsPanelTemplate x:Key=”myItemsPanelTemplate”]          
            [StackPanel Orientation=”Horizontal” /]
[/ItemsPanelTemplate]
 
The point of confusion is normally between selecting a ControlTemplate or DataTemplate. Normal saying goes as DataTemplate provides visualization to a business object while ControlTemplate does the same to a UI control. But in my project I see ControlTemplate used almost everywhere. Normally UI guys start creating screens while we are still giving shapes to our domain model (deadlines issues you see). Moreover, I feel one has to get slightly deep with WPF control properties to create an appealing professional UI.  So atleast here, we developers don’t quite mind giving a free hand to UI guys. We just go over to control templates residing inside styles & giving names of Business Object properties inside the bindings created by them. Also ControlTemplate triggers are based on UI control properties which is what UI team is often interested in. Few more differences are given here.
HierarchicalDataTemplate is an extension of DataTemplate with an additional ItemSource property. It is used to render hierarchical data in controls like treeview or menu. HierarchicalDataTemplate ends with a Data Template.

[HierarchicalDataTemplate DataType=”{x:Type Department}” ItemsSource=”{Binding Path=Classes}”]
            [TextBlock Text=”{Binding Path=DepartmentName}” /]
[/HierarchicalDataTemplate]
[DataTemplate DataType=”{x:Type UniversityClass}”]
            [TextBlock Text=”{Binding Path=ClassName}” /]
[/DataTemplate]

Attached property vs. Dependency property?

Attached properties are a type of dependency property. The difference is in how they're used.
With an attached property, the property is defined on a class that isn't the same class for which it's being used. This is usually used for layout. Good examples are Panel.ZIndex or Grid.Row - you apply this to a control (ie: Button), but it's actually defined in Panel or Grid. The property is "attached" to the button's instance.
This allows a container, for example, to create properties that can be used on any UIelement.
As for implementation differences - it's basically just a matter of using Register vs. RegisterAttached when you define the property.

Define Framework element?

UIElement is a base class for most of the objects that have visual appearance and can process basic input in Silverlight.
FrameworkElement provides a framework of common APIs for objects that participate in Silverlight layout. FrameworkElement also defines APIs related to data binding, object tree, and object lifetime feature areas in Silverlight.

What kind of elements used in storyboard?

From/To Animation: Animates between a starting and ending value. While creating the Animation, we will be having From and To properties to set the beginning and ending values.
Use the From property to set the starting value
Use the To property to set the ending value
These are simple to implement and these are basic animations. Animations belonging to this category are:
·         ColorAnimation
·         DoubleAnimation
·         PointAnimation
Key-frame Animation: Animates between a series of values specified using key-frame objects. Key-frame animations are more powerful than From/To animations because you can specify any number of target values and even control their interpolation method. This kind of Animation implementation is a bit complex than basic animations. Animations belonging to this category are:
·         ColorAnimationUsingKeyFrames
·         DoubleAnimationUsingKeyFrames
·         PointAnimationUsingKeyFrames

What is Downloader Object in Silverlight?

This object will retrieve objects (images, video, xaml) asynchronously, much like AJAX.  There is a gaping limitation being that it cannot go cross domain. 
An interesting feature of the Downloader object is the ability to get XAML asynchronously.  This gives us the ability to create module Silverlight applications and code XAML Plug-ins.
What is BAML? 
XAML stands for extended application markup language. It is nothing but an xml file which is used to declarative create the user interface of the silver light or the WPF applications. This XAML file generally rendered by the silverlight plugin and displayed inside the browser. When you compile your project which includes XAML pages,those first converts into BAML (Binary application markup language) and then rendered in the web browser.

What kind of Brushes you are used in Silver light project?

     a) Linear Gradient
     b) Solid color brush

What kind of audio video formats is supported in Silverlight?

Silverlight supports Windows Media Audio and Video (WMA, WMV7-9) and VC-1, as well as MP3 audio.

What is the XAP mime type in Silverlight?

The .xap mime type is: application/x-silverlight

No comments: