Today we are going to learn about WPF, like:
Birth of WPF:
- What is WPF?
- From where does it come?
- It's features, tools, assemblies & namespaces.
- It's advantages & disadvantages.
- It's hierarchy.
- It's architecture etc.
Microsoft has developed numerous graphical interface toolkits like C++ Win32 API, VB6, MFC, etc. to build desktop applications. These technologies are capable of designing a good GUI interface for the Windows Applications. But these lack some additional and advanced features, such as, 2D & 3D Rendering Support, Multimedia Support, Animation Support, etc. which are essential now a days. So Microsoft introduced WPF (Windows Presentation Foundation) API in .NET 3.0 framework for the first time. It was released in 2007. WPF applications can be hosted on web browsers which offer rich graphics features for web applications. Web Browser Applications (WBA) developed with WPF technology uses XAML to host user interface for browser applications. XAML stands for EXtended Application Markup Language which is a new declarative programming model from Microsoft. XAML files are hosted as discrete files in the Web server, but are downloaded to the browsers and converted to user interface by the .NET runtime in the client browsers.
.NET 3.0 was officially shipped for the first time with Windows Vista OS. But Windows XP and 2003 versions can also use .NET 3.0. Visual Studio 2005 is the first gateway to program .NET 3.0 applications. So to develop WPF applications you need Visual Studio 2005 or later.
What is WPF?
The Windows Presentation Foundation (WPF) Application Programming Interface (API) was introduced by Microsoft. It is a next generation UI framework to create applications with a rich user experience. It is part of the .NET Framework 3.0 and higher. WPF combines application UIs, 2D graphics, 3D graphics, documents and multimedia into one single framework. It's vector based rendering engine uses hardware acceleration of modern graphic cards. This makes the UI faster, scalable and resolution independent.
WPF provides us the capability to design Windows applications like an ASP.NET application using a markup language. Microsoft called this XAML (Extended Application Markup Language). XAML provides a separation of coding from designing. So you can develop your application using the toolbox and properties window like the general windows application or in a different form like web applications using markup language.
XAML is capable of providing all the simple UI elements (such as labels, textboxes, etc.) to complex functionality (animation, graphics rendering and multimedia support). If you want to animate a button with a picture on it you only need a few lines of XAML code. WPF elements can also be customized using styles and templates, minimizing your efforts. There are also a lot of tools to generate XAML code for you. You have to just define the UI in a drag and drop manner. You can also apply rendering effects and animations to these UI using a simple IDE. Then the IDE will give you the XAML code to be used in your application.
<TextBlock Margin="20">Welcome to the World of XAML</TextBlock>
<Button Margin="10" HorizontalAlignment="Right">OK</Button>
FEATURES INTRODUCED IN WPF:
There are several new features introduced with WPF:
Let's discuss these features in detail:
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. The 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 Tier 2 rendering mode.
Vector Based Rendering:
- 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 working of 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 working of 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 working of DirectX version equal or greater than 9.0.
The core of WPF is a resolution-independent and vector-based rendering engine that is built to take advantage of modern graphics hardware. A visual object stores its render data as a vector graphics instruction list. Each item in the instruction list represents a low-level set of graphics data and associated resources in a serialized format.
Another feature of WPF is Resolution Independence which allows text and graphical elements to be resized without affecting the layout or clarity of the items. This means that elements can be made larger and therefore accessible to people with visual impairment. Large items, such as buttons, icons and menus, are also easier for people with physical difficulties to target using their trackball, joystick or other pointing device.
Animations and timelines:
Windows Presentation Foundation (WPF) provides a powerful set of graphics and layout features Animation that enables you to create attractive user interfaces and appealing documents. Animation can make an attractive user interface even more spectacular and usable. By just animating a background color or applying an animated Transform, you can create dramatic screen transitions or provide helpful visual cues.
WPF supports time-based animations, in contrast to the frame-based approach. This decouples the speed of the animation from how the system is performing. It also supports low level animation via timers and higher level abstractions of animations via the Animation classes.
From="1.0" To="0.0" Duration="0:0:5"
AutoReverse="True" RepeatBehavior="Forever" />
One of the best things about WPF is the advanced data binding support; the Binding class that is used to create data bindings has many interesting and useful options. WPF has a built-in set of data services to enable application developers to bind and manipulate data within applications. It supports three types of data binding:
- One time: Where the client ignores updates on the server.
- One way: Where the client has read-only access to data.
- Two way: Where client can read from and write data to the server.
Controls in WPF are extremely composable. You can define almost any type of control as content of another. Although this flexibility sounds horrible to designers, it's a very powerful feature if you use it appropriatly. Put an image into a button to create an image button, or put a list of videos into a combo box to choose a video file.
Windows Presentation Foundation (WPF) offers a wide range of document features that enable the creation of high-fidelity content that is designed to be more easily accessed and read than in previous generations of Windows. One type of a new featured document is XPS.
Graphics, including desktop items like windows, are rendered using Direct3D. This provides an avenue for displaying more complex graphics and custom themes, at the cost of GDI's wider range of support and uniform control theming. It allows Windows to offload some graphics tasks to the GPU. This reduces the workload on the computer's CPU. GPUs are optimized for parallel pixel computations; this tends to speed up screen refreshes at the cost of decreased compatibility in markets where GPUs are not necessarily as powerful, such as the netbook market. WPF's emphasis on vector graphics allows most controls and elements to be scaled without loss in quality or pixelization, thus increasing accessibility.
The Windows Presentation Foundation provides great support for UI skinning. There are various situations in which UI skinning might be important for an application. It can be used to allow the end-user to customize the UI based on his or her personal aesthetic preferences. Another scenario in which skinning might be used is when a company creates one application that is subsequently deployed to various clients. Each client might want their company logo, colors, font, etc. to be displayed by the application. If the UI is designed with skinning in mind, that task is easy to accomplish with minimal effort.
Windows Presentation Foundation (WPF) provides support for multimedia, vector graphics, animation, and content composition, making it easy for developers to build interesting user interfaces and content.
Declarative UI XAML:
XAML is an XML based language that is used as a foundation for the WPF. It allows forms to be created using syntax very similar to ASP.NET and HTML. The design pattern that is getting popular in the .Net world is MVC, called Model View Controller. This is why we have the WPF designed differently than traditional Microsoft framework like MFC. The Declarative UI is an approach to separating the UI completely from the business logic. The XAML is a general purpose markup language being used in WPF. For Example:
A Button in HTML:
<input type="Button" value="Click Me" id="MyButton" />
And in XAML:
<Button Name="MyButton">Click Me<Button>
Continue to Part 2