You are on page 1of 33

Windows Presentation

Foundation
Introducing Windows Presentation
Foundation
• The primary goal of Windows Presentation Foundation
(WPF) is to help developers create attractive and effective
user interfaces.

• WPF unified platform helps make designers active


participants in creating user interfaces, and provides a
common programming model for standalone and browser
applications.

• WPF allows building interfaces that incorporate documents,


media, two- and three-dimensional graphics, animations,
Web-like characteristics, and much more.
Illustrating the Problem

Suppose a hospital wants to create a new application for examining


and monitoring patients. The requirements for this new
application's user interface might include the following:

• Displaying images and text about the patient.


• Displaying and updating two-dimensional graphics showing the
patient's vital signs, such as heart rate and blood pressure.
• Providing three-dimensional views and overlays of patient
information.
• Presenting video of ultrasounds and other diagnostics, perhaps
allowing physicians and nurses to add annotations.
• Allowing hospital staff to read and make notations on documents
describing the patient and her condition.
• Running both as a Windows application, allowing full capability for
hospital employees, and in a security-restricted Web browser
application, allowing more limited access by remote physicians via
the Internet.
The point is that many modern
applications can benefit from
providing interfaces that
integrate graphics, media,
documents, and the other
elements of a modern user
experience.
Addressing the Problem: What
Windows Presentation Foundation
Provides
Three aspects of what WPF provides stand out as
most important. They are:

• A unified platform for modern user interfaces.

• The ability for developers and designers to work


together.

• A common technology for Windows and Web


browser user interfaces.
Addressing the Problem: What
Windows Presentation Foundation
Provides

In a pre-WPF world, creating a Windows user interface like the


one described earlier would require using several different
technologies. The table below summarizes the situation.
Wind
ows Windo D
Form ws ire
Window PD s/ Media ct WP
  s Forms F GDI+ Player 3D F
Graphical interface, X         X
e.g., forms and
controls
On-screen X         X
documents
Fixed-format   X       X
documents
Images     X     X
Video and audio       X   X
Two-dimensional     X     X
graphics
Three-dimensional         X X
graphics
Figure 1. A WPF interface can combine
images, text, 2D and 3D graphics, and more.
A WPF interface can include video, allowing
the user to make text annotations

This screen contains text and images along with both two- and three-dimensional graphics. All of
this was produced using WPF—the developer doesn't need to write code that uses specialized
graphics technologies such as GDI+ or Direct3D. Similarly, WPF allows displaying and perhaps
annotating video, such as the ultrasound feed shown below.
To define this type of document, Microsoft has created the XML Paper
Specification (XPS). WPF also provides a group of application programming
interfaces (APIs) that developers can use to create and work with XPS
documents.

WPF interface can display multi-column


documents, including annotations.
The WPF

• WPF doesn't replace everything on this list, of


course.

• Windows Forms applications will continue to have


value.

• Windows Media Player continues to have an


independent role to play, and PDF documents will
continue to be used.

• WPF itself relies on Direct3D for all rendering.


The Evolution of WPF

• WPF is an integrated client platform.

• The evolution of WPF begins with the Internet


Explorer and dynamic HTML model.

• This model can produce sophisticated content but


has scalability, content, and media limitations.

• Microsoft also saw a need for a new platform that


could exploit the significant graphical power of
modern computers.
WPF- Features
• Modern interfaces also shouldn't be constrained by the limitations
of bit-mapped graphics. Accordingly, WPF relies entirely on vector
graphics, allowing an image to be automatically resized to fit the
size and resolution of the screen it's displayed on. Rather than
creating different graphics for display on a small monitor and a
big-screen television, the developer can let WPF itself handle this.

• Yet creating modern user interfaces means more than just


unifying what were once diverse technologies. It also means
taking advantage of modern graphics cards, and so WPF exploits
whatever graphics processing unit (GPU) is available on a system
by offloading as much work as possible to it.

• WPF can make creating and maintaining applications less


expensive. And by making it straightforward to build interfaces
that incorporate graphics, video, and more, WPF can improve the
quality—and business value—of how users interact with Windows
applications.

• One of the most powerful features of WPF is the way that it


The Ability for Developers and Designers to
Work Together

Most commonly, a designer uses a graphical tool to


create static images of the screen layouts that an
application should display. He then gives these
images to the developer, whose job is to create
the code that makes them real. Something that's
easy for a designer to draw, however, might be
difficult or impossible for a developer to
implement.

To allow this, WPF introduces the eXtensible


Application Markup Language (XAML).
What Is XAML?

• XAML defines a set of XML elements such as Button,


TextBox, Label, and many more to define exactly how a
user interface looks. XAML elements typically have
attributes as well, allowing various options to be set.

<Button Background="Red">
No
</Button>
What Is XAML?

• Each XAML element corresponds to a WPF class, and each


of that element's attributes has a corresponding property or
event in the class. For example, the same red button could
be produced with this C# code:

Button btn = new Button();


btn.Background = Brushes.Red;
btn.Content = "No";
What Is XAML?

• If everything expressible in XAML is also expressible in code


—and it is—what's the value of XAML? The answer is that
building tools that generate and consume XML-based
descriptions is much easier than doing the same thing with
code. Because XAML offers a tool-friendly way to describe a
user interface, it provides a better way for developers and
designers to work together.

• It provides you a xml based way to specific or declare


hierarchy of Object, property and logics.
• It is positioned as User Interface Designing Language.
• Therefore xaml based design, with Expression Designer
Tool can Collaborate with Visual Studio.
Expression Blend Visual Studio
XAML
XAML helps designers and developers
work together

• A designer can specify how a user interface should look and


interact using a tool such as Microsoft Expression Interactive
Designer. Oriented entirely toward defining the look and feel of a
WPF interface, this tool generates a description of that interface
expressed in XAML.

• A developer then imports that XAML description into a tool such as


Microsoft Visual Studio. Rather than recreating the interface from
scratch based on static images produced by a designer, the
interface definition itself is adopted wholesale.

• The developer then writes the code for the interface, such as
event handlers, along with any other functionality the application
requires.
XAML helps designers and developers
work together

• More specialized tools for designing XAML-defined interfaces are


also available, such as Electric Rain's ZAM 3D for creating three-
dimensional interface elements.
What Is XAML?

• XAML is an XML-based declarative markup language for


user interface development.

• With XAML, you can separate the application design from


the business logic.

• You can also create an entire user interface without the


need to write any code.

• Because XAML is an XML-based serialization format for .NET


objects, any public .NET class that exposes a default
constructor can be represented in XAML.
What Is XAML?

• You can integrate code into your XAML application by using


code-behind files. For example, you might need to write
procedural code to handle the Click event of a button. You
can also specify inline code in your XAML for simple cases.

• Windows Workflow Foundation (WF) also uses XAML to


define workflows. You can use XAML to create items such
as controls, styles, text, 3D graphics, animations, and many
others.
WPF -Deployment Options
• WPF Offers you two deployment options-
– Stand Alone Application
– Host them in a Browser (XBAP-XAML Browser
Application)
A Common Technology for Windows and Web
Browser User Interfaces

A developer can create a XAML Browser Application (XBAP)


using WPF that runs in Internet Explorer. In fact, the same
code can be used to create a standalone WPF application
and an XBAP.

Using the same code also means using the same developer
skills.

Because an XBAP is downloaded on demand from a Web


server, it faces more stringent security requirements than a
standalone Windows application. Accordingly, XBAPs run in
a security sandbox provided by the .NET Framework's code
access security. XBAPs also run only on Windows systems
with WPF installed and only with Internet Explorer versions
6 and 7. For applications that meet these requirements,
however, rich Internet applications can now use the same
WPF- Custom Controls

• We can Create t a Custom Control and use it.


WPF- Interop

• WPF Control can be hosted on the Windows


Forms Application. Or Visa Versa.
A Common Technology for Windows and Web
Browser User Interfaces

As the figure below shows, an XBAP runs inside Internet


Explorer. XBAPs can act as a client for Web applications
built using ASP.NET, JavaServer Pages (JSP), or other Web
technologies. To communicate back to this Web application,
the XBAP can use HTTP or SOAP. Whatever server platform
is used, an XBAP is always loaded via ClickOnce. It presents
no dialogs or prompts to the user during this process,
however; an XBAP loads just like a Web page. Because of
this, XBAPs don't appear on the Start menu or in
Add/Remove Programs.
The end

You might also like