21 Important FAQ Questions for WPF And

Embed Size (px)

Citation preview

  • 8/14/2019 21 Important FAQ Questions for WPF And

    1/24

    21 Important FAQ questions for WPF and SilverLight

    Introduction

    What is the need of WPF when we had GDI, GDI+ and DirectX?

    How does hardware acceleration work with WPF?

    Does that mean WPF has replaced DirectX?

    So can we define WPF in a precise way?

    What is XAML?

    So is XAML meant only for WPF ?

    Can you explain the overall architecture of WPF?

    Which are the different namespaces and classes in WPF ?

    Can explain the different elements involved in WPF application practically?

    What are dependency properties?

    Are XAML file compiled or built on runtime?

    Can you explain how we can separate code and XAML?

    How can we access XAML objects in behind code?

    What kind of documents are supported in WPF?

    What is SilverLight ?

    Come on, even WPF runs under browser why SilverLight ?

    Can SilverLight run in other platforms other than window?

    What is the relationship between Silver Light, WPF and XAML?

    Can you explain Sliver Light architecture?

    Source code

    http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Introduction%23Introductionhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20is%20the%20need%20of%20WPF%20when%20we%20had%20GDI,%20GDI+%20and%20DirectX%23What%20is%20the%20need%20of%20WPF%20when%20we%20had%20GDI,%20GDI+%20and%20DirectXhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#How%20does%20hardware%20acceleration%20work%20with%20WPF%23How%20does%20hardware%20acceleration%20work%20with%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Does%20that%20mean%20WPF%20has%20replaced%20DirectX%23Does%20that%20mean%20WPF%20has%20replaced%20DirectXhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#So%20can%20we%20define%20WPF%20in%20a%20precise%20way%23So%20can%20we%20define%20WPF%20in%20a%20precise%20wayhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20is%20XAML%23What%20is%20XAMLhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#So%20is%20XAML%20meant%20only%20for%20WPF%23So%20is%20XAML%20meant%20only%20for%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20you%20explain%20the%20overall%20architecture%20of%20WPF%23Can%20you%20explain%20the%20overall%20architecture%20of%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Which%20are%20the%20different%20namespaces%20and%20classes%20in%20WPF%23Which%20are%20the%20different%20namespaces%20and%20classes%20in%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20explain%20the%20different%20elements%20involved%20in%20WPF%20application%20practically%23Can%20explain%20the%20different%20elements%20involved%20in%20WPF%20application%20practicallyhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20are%20dependency%20properties%23What%20are%20dependency%20propertieshttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Are%20XAML%20file%20compiled%20or%20built%20on%20runtime%23Are%20XAML%20file%20compiled%20or%20built%20on%20runtimehttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20you%20explain%20how%20we%20can%20separate%20code%20and%20XAML%23Can%20you%20explain%20how%20we%20can%20separate%20code%20and%20XAMLhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#How%20can%20we%20access%20XAML%20objects%20in%20behind%20code%23How%20can%20we%20access%20XAML%20objects%20in%20behind%20codehttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20kind%20of%20documents%20are%20supported%20in%20WPF%23What%20kind%20of%20documents%20are%20supported%20in%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20is%20SilverLight%23What%20is%20SilverLighthttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Come%20on,%20even%20WPF%20runs%20under%20browser%20why%20SilverLight%23Come%20on,%20even%20WPF%20runs%20under%20browser%20why%20SilverLighthttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20SilverLight%20run%20in%20other%20platforms%20other%20than%20window%23Can%20SilverLight%20run%20in%20other%20platforms%20other%20than%20windowhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20is%20the%20relationship%20between%20Silver%20Light,%20WPF%20and%20XAML%23What%20is%20the%20relationship%20between%20Silver%20Light,%20WPF%20and%20XAMLhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20you%20explain%20Sliver%20Light%20architecture%23Can%20you%20explain%20Sliver%20Light%20architecturehttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Source%20code%23Source%20codehttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Introduction%23Introductionhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20is%20the%20need%20of%20WPF%20when%20we%20had%20GDI,%20GDI+%20and%20DirectX%23What%20is%20the%20need%20of%20WPF%20when%20we%20had%20GDI,%20GDI+%20and%20DirectXhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#How%20does%20hardware%20acceleration%20work%20with%20WPF%23How%20does%20hardware%20acceleration%20work%20with%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Does%20that%20mean%20WPF%20has%20replaced%20DirectX%23Does%20that%20mean%20WPF%20has%20replaced%20DirectXhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#So%20can%20we%20define%20WPF%20in%20a%20precise%20way%23So%20can%20we%20define%20WPF%20in%20a%20precise%20wayhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20is%20XAML%23What%20is%20XAMLhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#So%20is%20XAML%20meant%20only%20for%20WPF%23So%20is%20XAML%20meant%20only%20for%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20you%20explain%20the%20overall%20architecture%20of%20WPF%23Can%20you%20explain%20the%20overall%20architecture%20of%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Which%20are%20the%20different%20namespaces%20and%20classes%20in%20WPF%23Which%20are%20the%20different%20namespaces%20and%20classes%20in%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20explain%20the%20different%20elements%20involved%20in%20WPF%20application%20practically%23Can%20explain%20the%20different%20elements%20involved%20in%20WPF%20application%20practicallyhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20are%20dependency%20properties%23What%20are%20dependency%20propertieshttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Are%20XAML%20file%20compiled%20or%20built%20on%20runtime%23Are%20XAML%20file%20compiled%20or%20built%20on%20runtimehttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20you%20explain%20how%20we%20can%20separate%20code%20and%20XAML%23Can%20you%20explain%20how%20we%20can%20separate%20code%20and%20XAMLhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#How%20can%20we%20access%20XAML%20objects%20in%20behind%20code%23How%20can%20we%20access%20XAML%20objects%20in%20behind%20codehttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20kind%20of%20documents%20are%20supported%20in%20WPF%23What%20kind%20of%20documents%20are%20supported%20in%20WPFhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20is%20SilverLight%23What%20is%20SilverLighthttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Come%20on,%20even%20WPF%20runs%20under%20browser%20why%20SilverLight%23Come%20on,%20even%20WPF%20runs%20under%20browser%20why%20SilverLighthttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20SilverLight%20run%20in%20other%20platforms%20other%20than%20window%23Can%20SilverLight%20run%20in%20other%20platforms%20other%20than%20windowhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#What%20is%20the%20relationship%20between%20Silver%20Light,%20WPF%20and%20XAML%23What%20is%20the%20relationship%20between%20Silver%20Light,%20WPF%20and%20XAMLhttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Can%20you%20explain%20Sliver%20Light%20architecture%23Can%20you%20explain%20Sliver%20Light%20architecturehttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#Source%20code%23Source%20code
  • 8/14/2019 21 Important FAQ Questions for WPF And

    2/24

    Introduction

    This article talks about 21 important FAQ from the perspective of WPF and Silverlight. Both of these technologies are connected to a certain extent. This article notonly explains the theory aspect of these technologies but also shows small samples

    for each of them.

    Heres a complete free e-book covering 400 FAQ for C#, SQL Server, WPF, WWF,WCF and lot more feel free to download it and enjoyhttp://www.questpond.com/SampleDotNetInterviewQuestionBook.zip

    Other silverlight FAQ

    Silverlight FAQ Part 1:-http://www.codeproject.com/KB/silverlight/SilverLightFAQPart2.aspx

    What is the need of WPF when we had GDI, GDI+ and DirectX?

    http://www.questpond.com/SampleDotNetInterviewQuestionBook.ziphttp://www.codeproject.com/KB/silverlight/SilverLightFAQPart2.aspxhttp://www.questpond.com/SampleDotNetInterviewQuestionBook.ziphttp://www.codeproject.com/KB/silverlight/SilverLightFAQPart2.aspx
  • 8/14/2019 21 Important FAQ Questions for WPF And

    3/24

    First lets try to understand how display technology has evolved in Microsofttechnology.

    User32:- This provides the windows look and feel for buttons and textboxes andother UI elements. User32 lacked drawing capabilities.

    GDI (Graphics device interface):- Microsoft introduced GDI to provide drawingcapabilities. GDI not only provided drawing capabilities but also provided a high levelof abstraction on the hardware display. In other words it encapsulates allcomplexities of hardware in the GDI API.

    GDI+:- GDI+ was introduced which basically extends GDI and provides extrafunctionalities like JPG and PNG support, gradient shading and anti-aliasing. Thebiggest issue with GDI API was it did not use hardware acceleration and did not have

    animation and 3D support.

    Note: - Hardware acceleration is a process in which we use hardware to perform some functions rather than performing those functions using the software which is running in the CPU.

    DirectX :- One of the biggest issues with GDI and its extension GDI+ was hardwareacceleration and animation support. This came as a biggest disadvantage for game

  • 8/14/2019 21 Important FAQ Questions for WPF And

    4/24

    developers. To answer and server game developers Microsoft developed DirectX.DirectX exploited hardware acceleration, had support for 3D, full color graphics ,media streaming facility and lot more. This API no matured when it comes to gamingindustry.

    WPF :- Microsoft almost had 3 to 4 API's for display technologies , so why a need for

    one more display technology. DirectX had this excellent feature of using hardwareacceleration. Microsoft wanted to develop UI elements like textboxes,button,grids etcusing the DirectX technology by which they can exploit the hardware accelerationfeature. As WPF stands on the top of directX you can not only build simple UIelements but also go one step further and develop special UI elements like Grid,FlowDocument, and Ellipse. Oh yes you can go one more step further and buildanimations.WPF is not meant for game development. DirectX still will lead in thatscenario. In case you are looking for light animation ( not game programming ) WPFwill be a choice. You can also express WPF using XML which is also called as XAML.Inother words WPF is a wrapper which is built over DirectX. So lets define WPF.

    WPF is a collection of classes that simplify building dynamic user interfaces. Thoseclasses include a new set of controls, some of which mimic old UI elements (such asLabel, TextBox, Button), and some that are new (such as Grid, FlowDocument andEllipse).

    How does hardware acceleration work with WPF?

    Hardware acceleration is a process in which we use hardware to perform somefunctions rather than performing those functions using the software which is runningin the CPU.

    WPF exploits hardware acceleration in a two tier manner.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    5/24

    WPF API first detects the level of hardware acceleration using parameters like RAM of video card , per pixel value etc. Depending on that it either uses Tier 0, Tier 1 or Tier2 rendering mode.

    Tier 0:- If the video card does not support hardware acceleration then WPF uses Tier0 rendering mode. In other words it uses software acceleration. This corresponds toworking of DirectX version less than 7.0.

    Tier 1:- If the video card supports partial hardware acceleration then WPF uses Tier 1rendering mode. This corresponds to working of DirectX version between 7.0 and9.0.

    Tier 2:- If the video card supports hardware acceleration then WPF uses Tier 2rendering mode. This corresponds to working of DirectX version equal or greaterthan 9.0.

    Does that mean WPF has replaced DirectX?

    No, WPF does not replace DirectX. DirectX will still be still needed to make cuttingedge games. The video performance of directX is still many times higher than WPFAPI. So when it comes to game development the preference will be always DirectXand not WPF. WPF is not a optimum solution to make games, oh yes you can make aTIC TAC TOE game but not high action animation games.

    One point to remember WPF is a replacement for windows form and not directX.

    So can we define WPF in a precise way?

  • 8/14/2019 21 Important FAQ Questions for WPF And

    6/24

    Windows Presentation Framework is the new presentation API. WPF is a two andthree dimensional graphics engine. It has the following capabilities:- Has all equivalent common user controls like buttons, check boxes sliders etc. Fixed and flow format documents Has all of the capabilities of HTML and Flash

    2D and 3D vector graphics Animation Multimedia Data binding

    What is XAML?

    XAML (pronounced as Zammel) is a declarative XML-based language by which youcan define object and properties in XML. XAML document is loaded by a XAML parser.XAML parser instantiates objects and set their properties. XAML describes objects,properties and there relation in between them. Using XAML, you can create any kind

    of objects that means graphical or non-graphical. WPF parses the XAML documentand instantiates the objects and creates the relation as defined by XAML.So XAML is a XML document which defines objects and properties and WPF loads thisdocument in actual memory.

    So is XAML meant only for WPF ?

    No,XAML is not meant only for WPF.XAML is a XML-based language and it hadvarious variants.WPF XAML is used to describe WPF content, such as WPF objects, controls anddocuments. In WPF XAML we also have XPS XAML which defines an XMLrepresentation of electronic documents.Silverlight XAML is a subset of WPF XAML meant for Silverlight applications.Silverlight is a cross-platform browser plug-in which helps us to create rich webcontent with 2-dimensional graphics, animation, and audio and video.WWF XAML helps us to describe Windows Workflow Foundation content. WWFengine then uses this XAML and invokes workflow accordingly.

    Can you explain the overall architecture of WPF?

  • 8/14/2019 21 Important FAQ Questions for WPF And

    7/24

    Above figure shows the overall architecture of WPF. It has three major sectionspresentation core, presentation framework and milcore. In the same diagram wehave shown how other section like direct and operating system interact with thesystem. So lets go section by section to understand how every section works.User32:- It decides which goes where on the screen.

    DirectX: - As said previously WPF uses directX internally. DirectX talks with driversand renders the content.

    Milcore: - Mil stands for media integration library. This section is a unmanaged codebecause it acts like a bridge between WPF managed and DirectX / User32unmanaged API.

    Presentation core ;- This is a low level API exposed by WPF providing features for2D , 3D , geometry etc.

    Presentation framework:- This section has high level features like applicationcontrols , layouts . Content etc which helps you to build up your application.

    Which are the different namespaces and classes in WPF ?

  • 8/14/2019 21 Important FAQ Questions for WPF And

    8/24

    There are ten important namespaces / classes in WPF.

    System.Threading.DispatcherObjectAll WPF objects derive from the DispatcherObject. WPF works on STA model i.e.Single Threading Apartment Model. The main duty of this object is to handleconcurrency and threading. When any message like mouse clicks, button clicks etcare initiated they are sent to the DispatcherObject who verifies whether code isrunning on the correct thread. In the coming section we will look in to detail howWPF threading works.

    System.Windows.DependencyObject

  • 8/14/2019 21 Important FAQ Questions for WPF And

    9/24

    When WPF was designed property based architecture was considered. In other wordsrather than using methods, functions and events object behavior will interact usingproperties. For now we will only restrict ourselves to this definition. In the comingsection we have dedicated question for the same.

    System.Windows.Media.Visual

    Visual class is a drawing object which abstracts drawing instructions, how drawingshould be drawn like clipping, opacity and other functionalities. Visual class also actslike a bridge between unmanaged MilCore.dll and WPF managed classes. When anyclass derived from visual it can be displayed on windows. If you want to create yourown customized user interface then you can program using visual objects.

    System.Windows.UIElementUIElement handled three important aspects layout, input and events.System.Windows.FrameworkElementFrameWorkElement uses the foundation set by UIElement. It adds key properties like

    HorizontalAlignment , VerticalAlignment , margins etc.

    System.Windows.Shapes.ShapeThis class helps us to create basic shapes such as Rectangle, Polygon, Ellipse, Line,and Path.

    System.Windows.Controls.ControlThis class has controls like TextBox,Button,ListBox etc. It adds some extra propertieslike font,foreground and background colors.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    10/24

    System.Windows.Controls.ContentControlIt holds a single piece of content. This can start from a simple label and go down to aunit level of string in a layout panel using shapes.System.Windows.Controls.ItemsControlThis is the base class for all controls that show a collection of items, such as the

    ListBox and TreeView.

    System.Windows.Controls.PanelThis class is used for all layout containerselements that can contain one or morechildren and arrange them as per specific layout rules. These containers are thefoundation of the WPF layout system, and using them is the key to arranging yourcontent in the most attractive, flexible way possible.

    Can explain the different elements involved in WPF applicationpractically?

    In order to understand the different elements of WPF, we will do a small hello world sample and in that process we will understand the different elements of WPF.

    Note :- For this sample we have VS 2008 express edition.

    So start VS 2008 express and from the templates select the WPF application as showin the below figure below.

    Once we have created the WPF application project you will see two file types one theXAML file and the other is the behind code i.e. XAML.cs. XAML files are nothing butXML files which has all the elements needed to display the windows UI. Every of theXAML elements maps to come class. For instance the Window element maps to

    WpfApplication1.Window1 class , Button elements in XAML file maps to System.Windows.Control.Button class and Grid XAML element is mapped to System.Windows.Control.Grid.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    11/24

    The App.XAML and App.XAML.CS are the entry point files. If we see the code for App.XAML.CS you will see the reference to XAML file which needs to be loaded. Sothe first code which runs in the application is void main() method from

    App.XAML.CS which in turn loads the Window1.XAML file for rendering.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    12/24

    We can now connect the behind code method and function to events in XAML fileelements.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    13/24

    You can see from the above code snippet how the button element has the click eventlinked to the MyButton_Click function. MyButton_Click is the method which is in

    the XAML.CS behind code.So now if you run the code you can see the button and if you click on it you can seethe message box for the same.

    What are dependency properties?

    These dependency properties belong to one class but can be used in another.Consider the below code snippet:-

  • 8/14/2019 21 Important FAQ Questions for WPF And

    14/24

    Collapse Copy Code

    Height and Width are regular properties of the Rectangle. But Canvas. Top andCanvas. Left is dependency property as it belongs the canvas class. It is used by theRectangle to specify its position within Canvas.

    Are XAML file compiled or built on runtime?

    XAML files are usually compiled rather than parsing on runtime. But it also supportsparsing during runtime. When we build a XAML based project, you will see it createsg.cs extension in obi\Debug folder. Therefore, for every XAMl file you will find a g.csfile. For instance, a Shiv.XAML will have Shiv.g.cs file in obi\Debug folder. In short,in runtime you actually do not see the XAML file. But if you want to do runtime,parsing of XAML file it also allows that to be done.

    Can you explain how we can separate code and XAML?

    This is one of the most important features of WPF, separating the XAML from thecode to be handled. So designers can independently work on the presentation of theapplication and developers can actually write the code logic independent of how thepresentation is.

    Figure 16.1:- XAML and behind code in action

    Above is the code snippet, which shows a XAML file and the code completelydetached from the XAML presentation. In order to associate a class with XAML fileyou need to specify the x: Class attribute. Any event specified on the XAML objectcan be connected by defining a method with sender and event values. You can see

    http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23
  • 8/14/2019 21 Important FAQ Questions for WPF And

    15/24

    from the above code snippet we have linked the MyClickEvent to an event in thebehind code.

    Note: - You can get a simple sample in WindowsSimpleXAML folder. Feel free to experiment with the code experimenting will teach you much morethan reading something theoretical.

    How can we access XAML objects in behind code?

    To access XAML objects in behind code you just need to define them with the samename as given in the XAML document. For instance in the below code snippet wenamed the object as objtext and the object is defined with the same name in thebehind code.

    Figure 16.2 Accessing XAML object

    Note: - You can get the source code in WindowsAccessXAML folder.

    What is SilverLight ?

    Silver light is a web browser plug-in by which we can enable animations,graphics and audio video. You can compare silver light with flash. We canview animations with flash and its installed as a plug-in in the browser.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    16/24

    Can SilverLight run in other platforms other than window?

    Yes, animations made in SilverLight can run in other platforms other thanwindow. In whatever platform you want run you just need the SilverLightplug-in.

    Come on, even WPF runs under browser why SilverLight ?

    Yes there is something called as WPF browser application which can runWPF in browser. For WPF browser application you need .Net framework tobe installed in the client location while for silver light you need only theplug-in. So in other words WPF browser applications are OS dependentwhile SilverLight is not. SilverLight plug-in can run in other OS other thanwindows while we all know .NET framework only runs in windows.

    What is the relationship between Silver Light, WPF and XAML?

    As explained previously XAML is a XML file which defines the UI elements.This XML file can be read by WPF framework or Silver light framework forrendering. Microsoft first developed WPF and they used XAML files todescribe the UI elements to the WPF framework. Microsoft then extendedWPF and made WPF/e which helped to render the UI in the browser. WPF/ewas the code name for Silver Light. Later Microsoft launched Silver Lightofficially.So the XAML just defines the XML structure to represent the UI elements.Both the frameworks i.e. WPF and Silverlight then reads the UI elementsand renders the UI elements in the respective platform.

    Can you explain Sliver Light architecture?

    Before we talk about silver light architecture lets discuss what is silver lightis really made of technically. Silver light has borrowed lot of things fromexisting Microsoft technologies. We can think silver light plug-in as acombination of some technologies from core .NET framework, vectoranimations, media and JavaScript.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    17/24

    So we can visualize the silver light architecture as combination of somefunctionalities from core .NET framework , Ajax and some functionalitieslike animation , media etc provided by core silver light framework.We can think silver light architecture as a combination of four importantblocks:-

    Some .NET framework components: - Silver light uses some componentsfrom .NET framework. One of the main components is WPF. Many of the UIcomponents ( check box , buttons , text boxes etc) , XAML parsing etc aretaken from the core WPF system. It also has taken components like WCF tosimplify data access. It also have CLR for memory management, safetychecking and garbage collection. The base class libraries of Net are used forstring manipulations, algorithms, expressions, collections and globalization. Presentation core: - The core presentation framework has functionalitiesto display vector 2d animations, images, media, DRM and handle inputs likemouse and keyboard. Other technologies: - Silver light interacts with other technologies likeAjax and javascript. So it also borrows some functionalities from theretechnologies. Hosting: - Silver light animations finally run under the browserenvironment. So it has a the hosting functionality which helps to host theapplication the browser , expose a DOM by which JavaScript can manipulatethe silver light components and it also has a installer functionality whichhelps to install silver light application and plug-in in the browserenvironment.One of the things which you can notice from the architecture diagram is thatthe presentation core reads from the XAML file for rendering. The XAML is a

  • 8/14/2019 21 Important FAQ Questions for WPF And

    18/24

    component which is a part of the .NET framework and the rendering part isdone by the presentation core.

    The application is a typical HTML which runs under the browser. There aremarkups which instantiates the silver light plug-in. Now when user interactswith the silver light application it sends event to JavaScript system or the.NET system. This depends on which programming language you are using.The program code which is either in JavaScript of .NET can make calls to thesilver light run-time and achieve the necessary functionalities. XAML will beread and parsed by the silver light runtime and then rendered accordingly tothe browser.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    19/24

    What are the various basic steps to make a simple Silver Light application?

    This sample we are making using VS 2008 web express edition and .NET3.5. Its a 6 step procedure to run our first silver light application. So letsgo through it step by step.

    Step1:- The first thing we need to do is install silverlight SDK kit fromhttp://www.microsoft.com/downloads/details.aspx?familyid=FB7900DB-4380-4B0F-BB95-0BAEC714EE17&displaylang=en

    Step 2:- Once you install the silver light SDK you should be able to use thesilver light template. So when you go to create a new project you will see a

    SilverLight application template as shown in the below figure.

    http://www.microsoft.com/downloads/details.aspx?familyid=FB7900DB-4380-4B0F-BB95-0BAEC714EE17&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?familyid=FB7900DB-4380-4B0F-BB95-0BAEC714EE17&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?familyid=FB7900DB-4380-4B0F-BB95-0BAEC714EE17&displaylang=enhttp://www.microsoft.com/downloads/details.aspx?familyid=FB7900DB-4380-4B0F-BB95-0BAEC714EE17&displaylang=en
  • 8/14/2019 21 Important FAQ Questions for WPF And

    20/24

    Step 3 :- Once you click ok you will see a dialog box as shown below whichhas three options.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    21/24

    Add a ASP.NET web project to the solution to host silver light: - This optionis the default option, and it will create a new Web application project that isconfigured to host and run your Silverlight application. If you are creating anew silver light application then this is the option to go.

    Automatically generate Test Page To Host Silverlight at build time: - This

    option will create a new page at run time every time you try to debug andtest your application. If you want to only concentrate on your silver lightapplication then this option is worth looking at.

    Link This Silverlight Control Into An Existing Web Site :- If you have aexisting silver light application then this option helps to link the silver lightapplication with the existing web application project. You will not see thisoption enabled to new projects , you need to have an existing webapplication.

    For this example we have selected the first option. Once you click ok youshould see the full IDE environment for silver light.

    So lets run through some basic points regarding the IDE view what we see.You will see there are two projects one is your web application and theother is the silver light application. In the silver light application we twoXAML files one is App.XAML and the other is Page.XAML.App.XAML has the global level information.

    Step 4:- Now for simplicity sake we just use the TextBlock tag to display atext. You can see as we type in the Page.XAML its displayed in the viewer.

  • 8/14/2019 21 Important FAQ Questions for WPF And

    22/24

    Step 5 :- Now we need to consume the silver light application in a ASPX

    page. So in the HTML / ASPX page we need to first refer the silver lightname space using the Register attribute.

    Collapse Copy Code

    We also need to refer the script manager from the silver light name space.The script manager control is functionality from AJAX. The main purpose of this control is to manage the download and referencing of JavaScriptlibraries.

    Collapse Copy Code

    Finally we need to refer the silver light application. You can see that in thesource we have referred to the XAP file. XAP file is nothing but a compiledsilver light application which is compressed and ZIP. It basically has all the

    http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23
  • 8/14/2019 21 Important FAQ Questions for WPF And

    23/24

    files thats needed for the application in a compressed format. If yourename the file to ZIP extension you can open the same using WINZIP.

    Collapse Copy Code

    So your final ASPX / HTML code consuming the silver light application lookssomething as shown below.

    Collapse Copy Code < !DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.0 Transitional // EN"

    "http: // www.w3.org / TR / xhtml1 / DTD/ xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" style ="height:100%;"> < head runat ="server"> < title > MyFirstSilverLightApplication < body style ="height:100%;margin:0;"> < form id ="form1" runat ="server" style ="height:100%;"> < asp:ScriptManager ID ="ScriptManager1" runat ="server"> < div style ="height:100%;"> < asp:Silverlight ID ="Xaml1" runat ="server"

    Source ="~/ClientBin/MyFirstSilverLightApplication.xap" MinimumVersion ="2.0.31005.0" Width ="100%" Height ="100%" />

    Step 6 :- So finally set the web application as start up and also set this pageas start up and run it. You should be pleased to see your first silver lightapplication running.

    Source code

    You can download the source code Click here

    http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23http://www.codeproject.com/KB/WPF/WPFSilverLight/MyfirstSilverLightApplication_1.ziphttp://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx#%23http://www.codeproject.com/KB/WPF/WPFSilverLight/MyfirstSilverLightApplication_1.zip
  • 8/14/2019 21 Important FAQ Questions for WPF And

    24/24