Introduction
This article talks about 21 important FAQs from the perspective of WPF and Silver light. Both of these technologies are connected to a certain extent. This article not only explains the theory aspect of these technologies but also shows small samples for each of them.
What is the need for WPF when we had GDI, GDI+, and DirectX?

User32
This provides the windows look and feel for buttons and textboxes and other UI elements. User32 lacked drawing capabilities.
GDI (Graphics device interface)
Microsoft introduced GDI to provide drawing capabilities. GDI not only provided drawing capabilities but also provided a high level of abstraction on the hardware display. In other words, it encapsulates all complexities of hardware in the GDI API.
GDI+
GDI+ was introduced which basically extends GDI and provides extra functionalities like JPG and PNG support, gradient shading and anti-aliasing. The biggest 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 hardware acceleration and animation support. This came as the biggest disadvantage for game 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 the gaming industry.
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 hardware acceleration. Microsoft wanted to develop UI elements like textboxes, button, grids, etc using the DirectX technology by which they can exploit the hardware acceleration feature. As WPF stands on the top of DirectX you can not only build simple UI elements 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 build animations.WPF is not meant for game development. DirectX still will lead in that scenario. In case you are looking for light animation ( not game programming ), WPF will be a choice. You can also express WPF using XML which is also called XAML. In other words, WPF is a wrapper which is built over DirectX. So let’s define WPF.

How does hardware acceleration work with WPF?
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.
WPF exploits hardware acceleration in a two-tier manner.

Tier 0
If the video card does not support hardware acceleration then WPF uses Tier 0 rendering mode. In other words, it uses software acceleration. This corresponds to the working of the DirectX version less than 7.0.
Tier 1
If the video card supports partial hardware acceleration then WPF uses Tier 1 rendering mode. This corresponds to the working of the DirectX version between 7.0 and 9.0.
Tier 2
If the video card supports hardware acceleration then WPF uses Tier 2 rendering mode. This corresponds to the working of the DirectX version equal to or greater than 9.0.
Does that mean WPF has replaced DirectX?
No, WPF does not replace DirectX. DirectX will still be still needed to make cutting edge games. The video performance of DirectX is still many times higher than the WPF API. So when it comes to game development the preference will be always DirectX and not WPF. WPF is not an optimum solution to make games, oh yes you can make a TIC 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?
Windows Presentation Framework is the new presentation API. WPF is a two and three-dimensional graphics engine. It has the following capabilities:-
-
Has all equivalent common user controls like buttons, checkboxes 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?
So is XAML meant only for WPF?
No, XAML is not meant only for WPF.XAML is an XML-based language and it had various variants.
WPF XAML is used to describe WPF content, such as WPF objects, controls, and documents. In WPF XAML we also have XPS XAML which defines an XML representation of electronic documents.
Silverlight XAML is a subset of WPF XAML meant for Silverlight applications. Silverlight is a cross-platform browser plug-in that helps us to create rich web content with 2-dimensional graphics, animation, and audio and video.
WWF XAML helps us to describe Windows Workflow Foundation content. WWF engine then uses this XAML and invokes workflow accordingly.
Can you explain the overall architecture of WPF?

User32
It decides which goes where on the screen.
DirectX
As said previously WPF uses DirectX internally. DirectX talks with drivers and renders the content.
Milcore
Mil stands for the media integration library. This section is an unmanaged code because it acts like a bridge between WPF managed and DirectX / User32 unmanaged API.
Presentation core
This is a low-level API exposed by WPF providing features for 2D, 3D, geometry, etc.
Presentation framework
This section has high-level features like application controls, layouts. Content etc which helps you to build up your application.
Which are the different namespaces and classes in WPF?

System.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual

System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Shapes.Shape
System.Windows.Controls.Control
System.Windows.Controls.ContentControl
System.Windows.Controls.ItemsControl
System.Windows.Controls.Panel
Can explain the different elements involved in the WPF application practically?
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 shown in the below figure below.




What are dependency properties?
<Rectangle Height="72" Width="131" Canvas.Left="74" Canvas.Top="77" />
Height and Width are regular properties of the Rectangle. But Canvas. Top and Canvas. Left is dependency property as it belongs to the canvas class. It is used by the Rectangle to specify its position within Canvas.
Are XAML files compiled or built on runtime?
Can you explain how we can separate code and XAML?

Figure 16.1:- XAML and behind code in action
Note
You can get a simple sample in the WindowsSimpleXAML folder. Feel free to experiment with the code! experimenting will teach you much more than reading something theoretical.
To access XAML objects in behind code you just need to define them with the same name as given in the XAML document. For instance in the below code snippet we named the object as object and the object is defined with the same name in the behind code.
How can we access XAML objects in behind code?

Figure 16.2 Accessing XAML object
You can get the source code in the 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 can view animations with flash and it's installed as a plug-in in the browser.
Can SilverLight run in other platforms other than the window?
Yes, animations made in SilverLight can run in other platforms other than the window. In whatever platform you want to be run you just need the SilverLight plug-in.
Come on, even WPF runs under browser why SilverLight?
What is the relationship between Silver Light, WPF, and XAML?
As explained previously XAML is an XML file that defines the UI elements. This XML file can be read by the WPF framework or Silver light framework for rendering. Microsoft first developed WPF and they used XAML files to describe the UI elements to the WPF framework. Microsoft then extended WPF and made WPF/e which helped to render the UI in the browser. WPF/e was the code name for Silver Light. Later Microsoft launched Silver Light officially.

Can you explain Silver Light architecture?
Before we talk about silver light architecture let's discuss what is silver light is really made of technically. Silver light has borrowed a lot of things from existing Microsoft technologies. We can think of silver light plug-in as a combination of some technologies from the core .NET framework, vector animations, media, and JavaScript.

-
Some .NET framework components
Silver light uses some components from the .NET framework. One of the main components is WPF. Many of the UI components ( checkbox, buttons, text boxes, etc), XAML parsing, etc are taken from the core WPF system. It also has taken components like WCF to simplify data access. It also has CLR for memory management, safety checking, and garbage collection. The base class libraries of Net are used for string manipulations, algorithms, expressions, collections, and globalization. -
Presentation core
The core presentation framework has functionalities to display vector 2d animations, images, media, DRM, and handle inputs like mouse and keyboard. -
Other technologies
Silver light interacts with other technologies like Ajax and javascript. So it also borrows some functionalities from there technologies. -
Hosting
Silver light animations finally run under the browser environment. So it has a hosting functionality that helps to host the application the browser, expose a DOM by which JavaScript can manipulate the silver light components and it also has an installer functionality that helps to install the silver light application and plug-in in the browser environment.One of the things which you can notice from the architecture diagram is that the presentation core reads from the XAML file for rendering. The XAML is a component that is a part of the .NET framework and the rendering part is done by the presentation core.


What are the various basic steps to make a simple Silver Light application?
The first thing we need to do is install the Silverlight SDK kit from http://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 the silver light template. So when you go to create a new project you will see a "SilverLight application" template as shown in the below figure.

Once you click ok you will see a dialog box as shown below which has three options.

Link This Silverlight Control Into An Existing Web Site
If you have an existing silver light application then this option helps to link the silver light application with the existing web application project. You will not see this option enabled to new projects, you need to have an existing web application.
For this example, we have selected the first option. Once you click ok you should see the full IDE environment for silver light.

Now for simplicity's sake, we just use the TextBlock tag to display a text. You can see as we type in the Page.XAML its displayed in the viewer.

Now we need to consume the silver light application in an ASPX page. So in the HTML / ASPX page, we need to first refer the silver light namespace using the "Register" attribute.
<%@Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %>
We also need to refer the script manager from the silver light namespace. The script manager control is the functionality of AJAX. The main purpose of this control is to manage the download and referencing of JavaScript libraries.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
Finally, we need to refer to the silver light application. You can see that in the source we have referred to the XAP file. XAP file is nothing but a compiled silver light application which is compressed and ZIP. It basically has all the files that’s needed for the application in a compressed format. If you rename the file to ZIP extension you can open the same using WINZIP.
- <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/MyFirstSilverLightApplication.xap" MinimumVersion="2.0.31005.0" Width="100%" Height="100%" />
- <%@ Page Language="C#" AutoEventWireup="true" %>
- <%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %>
- <! 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</title>
- </head>
- <body style="height:100%;margin:0;">
- <form id="form1" runat="server" style="height:100%;">
- <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
- <div style="height:100%;">
- <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/MyFirstSilverLightApplication.xap" MinimumVersion="2.0.31005.0" Width="100%" Height="100%" />
- </div>
- </form>
- </body>
- </html>
Step 6
So finally set the web application as a start-up and also set this page as a start-up and run it. You should be pleased to see your first silver light application running.

Summary
In this article, we learned about 21 Important FAQ questions for WPF and SilverLight.

Gowtham RajamanickamPosted May 20, 2015, 12:57 AM
good
Michael PaineeditedPosted May 27, 2009, 4:33 PMEdited May 27, 2009, 4:35 PM
Note that GDI/GDI+ is now hardware accelerated within Windows 7 and Windows Server 2008R2 (and beyond). See article for more details.