Understanding Windows Presentation Foundation
Windows Presentation Foundation
The Windows Presentation Foundation (formerly known as “Avalon”) is the new strategic graphics subsystem in Windows that provides a unified approach to user interface, 2D and 3D graphics, documents and media. Built on the .NET Framework foundation and utilizing Direct3D for vector-based rendering, it provides a powerful solution for building immersive applications of all kinds. Furthermore, the Windows Presentation Foundation enables designers to be an integral part of the development process by providing declarative programming models for toolability and flexibility
The Design Principles
Integration Developers today are faced with a myriad choice of disparate technologies and APIs, depending on whether they are targeting 2D graphics (GDI or GDI+), user interface (USER32 or Windows Forms), media (DirectShow), or 3D (Direct3D or OpenGL). Windows Presentation Foundation provides a single model that is orthogonal across all these services and allows seamless integration of content within a single application. You can use the same constructs for animation, data binding and styling, regardless of whether you are targeting 2D, 3D or text content.
Vector graphics. As described in the introduction, the Windows Presentation Foundation takes full advantage of the powerful Graphical Processing Units that are part of modern PC systems. At its heart, the composition engine is vector-based, allowing for scaling of all output to match the resolution of a specific machine. The rendering architecture uses Direct3D for all output: on video cards that implement DirectX 7 or later in hardware, Windows Presentation Foundation renders output using the GPU wherever possible. In situations where hardware rendering cannot be used, software rendering is available as a fallback. Lastly, a floating-point logical pixel system and 32-bit ARGB color support provide a rich, high-fidelity experience that anticipates future technology needs, such as high-DPI displays.
Declarative programming. Windows Presentation Foundation introduces XAML (eXtensible Application Markup Language), an XML-based language for instantiating and populating nested object hierarchies. Whilst XAML isn’t exclusively tied to Windows Presentation Foundation, it is inherently suitable for tasks such as UI definition and construction. The design of XAML allows applications to parse and manipulate UI logic at run-time for dynamic workflow scenarios. Importantly, the XAML / code-behind model embodied in Windows Presentation Foundation allows designers and developers to work collaboratively on client application design and development, using tools such as Expression “Sparkle” as well as third-party specialist tools including ZAM 3D and Mobiform Aurora.
Easy deployment. With support for both standalone applications and web-browser applications, the Windows Presentation Foundation offers the best of both deployment models. Web-browser applications run from within Internet Explorer, either occupying the entire window or within an inline frame. They offer the ease of deployment for which web applications are famed, as well as operating within a partial trust sandbox which protects the client machine against malicious applications. Yet they can still take advantage of the local client hardware and use 3D and media services for the richest web experience available today. On the other hand, standalone applications are locally installed via ClickOnce or MSI technologies and offer full access to the underlying platform.
Document lifecycle. The Windows Presentation Foundation introduces a new set of document and print technologies. Applications that need to persist data to a local store can use the Open Packaging Conventions, a ZIP-based packaging convention shared with Office 12 that supports core properties and custom metadata, digital signatures and rights management functionality. For applications that want to share documents for collaboration across multiple machines, even without the application installed, the XML Paper Specification allows visuals to be fixed in a printable, portable format.
NET Framework 3.0 Architecture
At the top level, the Presentation Framework provides a managed API that offers full access to the underlying functionality. The vast majority of Windows Presentation Foundation developers will work exclusively with this layer. The framework includes a large number of standard controls (such as Button, Label, Menu), layout panels, 2D and 3D graphics and text primitives, support for imaging effects, media, animation and document services, and support for interoperability with GDI, DirectX and Windows Forms / GDI+.
The real workhorse of the Windows Presentation Foundation is the visual system. Most elements in the Windows Presentation Foundation derive from a base Visual class. The visual system composites all the data and produces the output onto the screen. This is where we integrate video and audio, 2D, 3D and animation together, as well as deliver certain text layout services. Lower in the architectural model sits the composition engine, which has the responsibility of rendering a visual tree to the screen, taking account of everything from transparent layers to window region invalidation.
All rendering in Windows Presentation Foundation takes place through Direct3D (indeed the Windows Vista hardware logo program will require a DirectX 9-level GPU). By moving more graphics processing to the GPU, we release the CPU for other work, increasing performance whilst simultaneously improving graphics quality. These benefits aren't limited to the 3D world, however - 2D graphics also take advantage of the same services; GDI is not used within Windows Presentation Foundation except for integration with legacy elements. For machines with Windows Vista, the new display driver model offers superior output with higher performance characteristics for media-intensive applications.
What do I need to develop .Net framework 3.0 Application?
- Net Framework 3.0 RC1
- The Windows SDK RC1 is needed for the development of WPF applications.
- The Visual Studio Code Name "Orcas" CTP WinFX Development Tools are add-ons to the release version of Visual Studio 2005 that make the development of WPF applications with Visual Studio 2005 easier.
- Expression Interactive Designer (EID) can be used for the (easy) creation of WPF user interfaces, templates and resources.
- Expression Graphics Designer (EGD) can be used to create (scalable) graphics for WPF applications by using the XAML exporter
Understanding WPF Layout Panels
Canvas allows you to do (x,y) positioning, much as provided with GDI and GDI+ today. You can also use attached properties to control the location of an item.
DockPanel allows you to dock items without worrying about their exact (x,y) positioning:
StackPanel provides a stacking model that places content from left to right or top to bottom.
Grid provides a model that allows row/grid positioning:
WrapPanel models the right hand pane of an Explorer window, allowing you to handle items that flow over to a new row when the current row is full.
The ScrollViewer provides a scrolling view on a child's content; if the content overflows the available space, a scrollbar will appear and allow the user to move around the content area
ViewBox has the opposite effect of constraining the size of the content to fit the parent panel. This provides a kind of auto-zoom effect.
Styles in WPF
Styles allow an application, document, or user interface (UI) designer to standardize on a particular look for their product. An author or designer can customize a look extensively on an application-by-application basis, but a strong style model is necessary to allow maintenance and sharing of a look. Windows Presentation Foundation provides that model.
Another feature of the Windows Presentation Foundation styling model is the separation of presentation and logic. This means that designers can design the appearance of an application at the same time that developers write the programming logic. The designer is creating the design directly, so the design isn't lost in translation from mockup to implementation.
There are several ways that styles in Windows Presentation Foundation can be extended or inherited. Styles can be based on other styles through the BasedOn property. When you use the based on property, the new style will inherit the values of the original style that are not explicitly redefined in the new style. In the following example, Style2 inherits the Control.Background value of Yellow, and adds a Control.Foreground value of Blue.
Code sample is attached