Architectural Overview of the Windows Presentation Foundation Beta 1 Release

 

Tim Sneath
Microsoft Corporation

August 2005

Applies to:
   WinFX Runtime Components Beta 1 Release (click to download)

Summary: This article highlights the Beta 1 release of the Windows Presentation Foundation ("Avalon"), the next-generation Windows presentation graphics subsystem. It provides a brief overview of the platform and explores new features added in this release from previous releases. (15 printed pages)

Contents

Introduction
Windows Presentation Foundation Beta 1
   Windows Integration
   New Features
   WinFX SDK
Exploring the New Features
   Introducing "Express" Applications
Introducing "Metro"
   Media
   Speech
   New Controls
   New Codec Support
   Typography
Feature and API Changes
   Styles
   Data Templates
   Changeables and Freezables
   Removal of SqlDataSource
   API Changes
Conclusion

The Microsoft Windows Presentation Foundation (formerly known by the codename "Avalon") provides an integrated platform for building highly immersive, visually differentiated applications. In this white paper, we review the background and context to this new technology, take a look at the major new features that are delivered in the Beta 1 timeframe, and highlight some of the most significant breaking changes that will affect applications ported forward from previous releases.

Introduction

The invocation of Moore's Law of exponential growth in processing power has become a distinctly jaded metaphor in the computing industry. Yet the powerful 3-D graphics hardware that is now standard in most modern computers is today somewhat underutilized outside of gaming and a few specialist business applications. The Windows Presentation Foundation sets out to take full advantage of these capabilities as a platform for building rich, immersive user experiences.

The Windows Presentation Foundation is a next-generation presentation subsystem that unifies a whole range of output services: user interface, 2-D and 3-D drawing and imaging, document-based printing and rendering, speech, and audio and video services. By providing a single framework based on managed code for all these services, the Windows Presentation Foundation makes it possible to build new rich user experiences that were hitherto difficult or impossible. For .NET developers, its framework will be familiar, and it will ultimately reduce the number of lines of code required to build data-bound applications. In addition, the Windows Presentation Foundation introduces new and enhanced services such as animation, while retaining interoperability with existing code written for GDI/GDI+.

One of the overriding objectives in building the Windows Presentation Foundation has been integration. Services such as animation and data binding are used in exactly the same way whether the target is 2-D or 3-D graphics, user interface elements such as buttons and text boxes, or even media.

Windows Presentation Foundation applications are rendered using a new vector-based composition engine. Hardware acceleration is used for the rendering process on DirectX graphics cards, with a fallback software solution for older display hardware. The coordinate system provides double precision, resolution-independent pixel addressing that enables support for the high-dpi displays that are becoming increasingly prevalent.

The Windows Presentation Foundation also introduces a new declarative programming model code-named "XAML," which enables user interfaces to be specified as a hierarchy of objects with properties and logic. XAML neatly separates user interface design from code, enabling graphical designers to create compelling, highly refined user interfaces and developers to focus on the application logic. This collaborative model of application development allows developers and designers to work closely and efficiently together. In addition, XAML is easy for tools to create and consume, and can be compiled into an application alongside classes written in any CLS-compliant language such as Visual Basic and C#.

Windows Presentation Foundation Beta 1

Windows Integration

The Windows Presentation Foundation is included as part of the Windows Vista operating system. For the Beta 1 release of Windows Vista, the runtime components necessary to run Windows Presentation Foundation applications are not installed by default; a desktop shortcut icon provides a pointer for installation from the setup disk. The installation experience for Windows Vista is not final and is subject to change for future beta releases.

The Windows Presentation Foundation is also available for installation on Windows XP and Windows Server 2003 by means of the WinFX Runtime Components, a redistributable that can be obtained from MSDN. Installing this add-on pack provides backwards compatibility for applications written for the Windows Presentation Foundation.

New Features

The Beta 1 release of the WinFX Runtime Components is compatible with the Community Technology Preview released in May (known as Beta 1 RC). There are no breaking changes between the two releases or new features; the major differences between the two releases are extra documentation, a number of bug fixes, and work to integrate with Windows Vista.

The major new features included in the Beta 1 release, compared to other earlier preview releases, are as follows:

  • "Express" Applications. The Windows Presentation Foundation application model now supports two distinct modes of execution: standalone executables and "Express" applications. Standalone applications can derive from NavigationApplication or Application, have access to all privileges granted to the current user context, and are installed to a user's machine. Express applications must derive from NavigationApplication, are hosted in a browser window, run in a security-constrained partial trust sandbox, and offer a zero-footprint install model.
  • "Metro" document and print infrastructure. At WinHEC 2005, Microsoft unveiled a set of technologies code-named "Metro". At the core is a specification for an open document format and a set of conventions anyone can use to store, manage, and digitally sign content. The specification also defines a format (called Metro Reach in the SDK) for electronic paper, based on XAML. Supporting Metro technologies for applications include a viewer to view, manage, and print Metro Reach files, and a set of APIs that enable integration of Metro technologies and documents with traditional applications, the Web, and hardware. Metro is also used in Windows as a foundation technology for the printer pipeline and spool format.
  • Media. In this release, new constructs are introduced to enable display and basic manipulation of audio and video media elements. With the Windows Presentation Foundation you can play multiple videos simultaneously, overlay one video on top of another, and even add alpha-blending or geometries to change the way a video displays.
  • Speech. Both speech recognition and speech synthesis are now included as part of the Windows Presentation Foundation. You can use these classes to improve the accessibility of your applications, customize them further to improve handling of domain-specific jargon, and even splice pre-generated and dynamically-generated audio together to build a more sophisticated solution.
  • Other features. An expander control and a status bar control are now included, as part of a focus on increasing the range and breadth of controls supplied with the Windows Presentation Foundation. The typography capabilities in the Windows Presentation Foundation are extended to now include support for Adobe CFF fonts. A number of areas of the object model see performance improvements, with further work planned for future releases.

WinFX SDK

The distribution for this release includes an initial release of the WinFX SDK, which includes documentation, tools, and samples for building Windows Presentation Foundation managed applications, along with support for building services based on the Windows Communication Foundation (formerly known as "Indigo"). Since this is an interim pre-beta release, expect the documentation to be partially incomplete and some samples to be broken. Check the release notes for known issues if you encounter problems.

The SDK also includes Visual Studio 2005 tools support for developing against the Windows Presentation Foundation and the Windows Communication Foundation, including updated templates for building applications running both inside and outside the browser as well as Windows Presentation Foundation controls. IntelliSense is provided for both code and markup, and build and debug support is enabled along with integrated help. Again, the release notes provide information on the required components and the correct install order to ensure everything gets set up correctly.

This release also includes the WinFX Runtime Components, which includes the .NET Framework 2.0 Beta 2 and the Windows Presentation Foundation and Windows Communication Foundation runtimes. You can use the runtime for internal deployment of an in-development application; bear in mind that the end-user setup experience is not final.

Exploring the New Features

This section goes into greater detail on the new features introduced since the March 2005 CTP. This document provides samples of how to use the new features present in Beta 1, along with links to the relevant portions of the WinFX SDK documentation.

Introducing "Express" Applications

One of the biggest challenges today with building client applications is the infrastructure issues of deploying and managing applications. In both business and consumer scenarios, application developers are looking for a platform that makes it easier to deploy applications to the desktop and to upgrade them seamlessly. The uptake of Web-based applications has been to a great extent due to these benefits, but people are increasingly also looking for applications that more fully exploit the speed and interactivity of the local PC. For example, AJAX applications have attracted attention lately, but the difficulty in building and debugging such applications leaves developers continuing to search for a better solution.

Enter the "Express" Application, a model that builds on top of ClickOnce (introduced with Visual Studio 2005) and provides a safe security model for applications deployed to a local cache that offers much of the power of the Windows Presentation Foundation combined with a lightweight path for maintenance and upgrade of an application.

Express applications run in a security-constrained sandbox and are hosted in the browser, running in the Internet zone. They deploy silently to a machine without an interactive security prompt and are locally cached. This is in contrast to regular trusted applications that typically have full access to the machine, run outside a browser window, and are installed into a \Program Files directory rather than being cached.

Application designers should select the optimum model for their needs based on the depth of their integration with the underlying platform. Applications that need to take full advantage of the client system such as large storage, start menu presence, offline capability, and so on should be full-trust applications. An application where a more Web-like experience is desired may be a good candidate for the Express application model (for example, visualizations, data-driven apps, and interactivity where the data comes from the server). The following flowchart highlights the major model choices:

Aa480177.hgtomayavalonctp1(en-us,MSDN.10).gif

Figure 1. Selecting an application model

The simplest way to create an Express application is to use the built-in Express application template from within Visual Studio. This creates a project based on the NavigationApplication object. This template includes a number of project settings of note in the .csproj or .vbproject file that set the application to run in the Internet zone, not be installed, execute within a browser, and select the application's manifest .xapp extension. Further details can be found in the documentation under the topic heading "A Sample Project File for XAML-based Avalon Express Applications."

Developing an Express application is similar to developing any other application, except that some capabilities aren't available in this environment. For example, you can't show a standalone window, you can't use services built to use the Windows Communication Foundation ("Indigo") (although you can use the existing ASMX client model), and you can only write to a quota-limited private area of the file system. Be aware that the Express sandbox in the current Beta 1 release is not complete. Some new application scenarios will be enabled for use with the Windows Presentation Foundation by 1.0, including the ability to create a flow document.

When you build an Express application, an .xapp manifest file is created, and this can be executed directly from the local machine simply by double-clicking it. More likely, however, you will deploy this file to a Web server along with the application executable, manifest, any dependent DLLs, and optionally the debug symbols (.pdb files). Finally, you should be aware that if you are planning to deploy an Express application to a Windows Server 2003 machine, you will need to manually add a few MIME types and extension handlers to the (secure) default configuration to enable Express applications to be successfully deployed. Details can be found in the documentation under the topic heading "Configure IIS to Deploy Avalon Applications."

Introducing "Metro"

Click here for larger image

Click here for larger image

Figures 2a and 2b. Installing and running an Avalon Express application (click for larger image)

Documents with "Metro"

At the WinHEC 2005 conference for independent hardware vendors, Microsoft announced a major new effort around building integrated document lifecycle applications. "Metro" is a series of technologies that are intended to revolutionize the document workflow lifecycle from screen to printer. Metro provides a common infrastructure to unify document lifecycle components and to transport content around your organization.

Metro consists of:

  • An open document format, that has two parts: 1) a container based on the ZIP cabinet format, which provides a consistent way to store both content and the rights management and digital signature metadata that pertains to that content; and 2) a definition of electronic paper known as the Metro Reach package, which is based on XML.
  • A set of developer APIs integrated with the Windows Presentation Foundation to allow seamless integration of document scenarios into Web and traditional applications.
  • A rich document viewer to view, manage, and print Metro Reach files. The viewer is implemented as a browser plug-in for Internet Explorer.
  • A new print pipeline that directly integrates Metro as a spool format and a new printer page description language that enables higher quality and better performance printing.

The Metro container is a mechanism for any application's data files to be managed, shared, and validated in a common way. Metro provides a set of conventions that ISVs can use for content packaging and application of rights management, digital signatures, and metadata across disparate data files.

The Metro Reach package unambiguously describes how a document should look, and describes how all the resources in the document should be packaged so it can be used on any platform. Metro Reach is easy to create, modify, and render because it uses openly available technologies. Specifically, it uses XML to describe how a document should be rendered, specifies resources using openly available fonts and images, and describes how it should be packaged with ZIP.

From a developer standpoint, Metro and the Windows Presentation Foundation are complementary technologies. Metro is a subset of the new Windows Presentation Foundation display model and, therefore, Metro Reach documents are an ideal way to display content from WinFX-based applications. You can work with Metro Reach documents from both managed WinFX applications and also from unmanaged Win32 applications.

Lastly, the Metro print pipeline will improve the quality of rendered output via printers. Graphics-centric ISVs are adding advanced graphics effects such as soft shadows, specular highlights, gradients, and transparencies to modernize their look and output. The native support for some of these requirements in Windows today is limited, and this often results in a disparity between displayed and printed output. The Windows Presentation Foundation will output data as Metro Reach documents natively that can be directly interpreted by the Windows Vista spooler, yielding very high screen-to-print fidelity for the most complex graphics requirements.

Metro will be included in Windows Vista along with the rest of the Windows Presentation Foundation. Visit the WHDC Metro site for the current Metro specification. Metro will be covered in detail from a software development perspective at PDC 2005 in Los Angeles this September.

Media

The Windows Presentation Foundation includes support for audio and video as integrated elements within a layout. For this Beta 1 release, we have enabled a set of features that allows developers to include media in their applications for simple, one-time playback. These features include:

  • Composited video
  • Audio / video playback for .WMV and .WMA files
  • A MediaElement class
    • that you can use from code and markup
    • that you can use in a panel or control
    • to which you can apply Clip, Opacity, Transforms, and Stretch properties
    • that you can use in an animation
  • MediaTimeline and MediaClock classes, with limited (play / pause / stop) control of video
  • Limited multivideo support

Further work on media is forthcoming between now and the Beta 2 release to add support for more complex requirements and better polish. An example of the limitations in this release is that there is no way to automatically loop a piece of media when it reaches the end, or to rewind or forward through the media.

As an example of what you can do simply with media in the Windows Presentation Foundation, check out the following screenshot. Note the way that the uppermost video is composed with alpha-blending onto the underlying screenshot; also note that it is clipped to an elliptical geometry.

Click here for larger image

Figure 3. Windows Presentation Foundation media support (click for larger image)

This was created with just the code you see below:

<Grid xmlns="https://schemas.microsoft.com/winfx/avalon/2005" >
   <MediaElement Name="myVideo" Source="\media\The_Magic_of_Flight_720.wmv"
                 Stretch="Fill" />
   <MediaElement Name="myVideo" Source="\media\Start Something.wmv" 
                 Width="480" Height="320" Opacity="0.7">
      <MediaElement.Clip>
         <EllipseGeometry Center="200, 100" RadiusX="150" RadiusY="100" />
      </MediaElement.Clip>

   </MediaElement>

   <TextBlock FontFamily="Global User Interface" FontSize="84pt" 
              Foreground="#ffff00" 
              TextAlignment="center" VerticalAlignment="bottom" 
              RenderTransform="rotate -5" Opacity=".35">
      Windows Presentation Foundation Media Support
   </TextBlock>

</Grid>

Using the lower-level Visual API, you could use video as a Drawing object thanks to the VideoDrawing class.

It should be noted that video is not operational in Windows Vista Beta 1, but will be enabled in a future release.

Speech

The System.Speech namespace allows both speech recognition and speech synthesis to be incorporated into an application. Speech recognition can be used to allow spoken-language commands to be used to operate your Windows Presentation Foundation application; speech synthesis allows a Windows Presentation Foundation application to "read" some text via the audio subsystem.

Speech Recognition

The main classes supporting speech recognition are:

  • DesktopRecognizer: abstracts the recognizer shared by apps on the desktop
  • SpeechRecognizer: abstracts a recognition engine for exclusive use by your app
  • RecognitionResult: examine text and semantics returned by a recognizer
  • SrgsDocument: used to build recognition grammars (the rules for what phrases a recognizer should listen for in your app)

For example, to load a grammar containing your app's commands into the shared desktop recognizer:

DesktopRecognizer desktopRecognizer = new DesktopRecognizer();
desktopRecognizer.LoadGrammar(new Grammar(new Uri(grammarPath)));
desktopRecognizer.SpeechRecognized += delegate(object sender, RecognitionEventArgs e)
    {
        // Do appropriate handling when we get a recognition
        // Console.WriteLine("User said {0}", e.Result.Text);
    };

To use speech recognition services from the Windows Presentation Foundation, you'll also need to have a speech recognition engine installed, but bear in mind that this is not distributed with the base-level OS, except for the Windows XP Tablet PC Edition. More recent releases of Microsoft Office also include the speech recognition engine, and you can always download an engine from the Microsoft Speech API Web site at the following location: https://www.microsoft.com/speech/download/sdk51/. Finally, bear in mind that speech recognition engines are language-specific, and are not available for all supported Windows languages.

Speech Synthesis

The main classes for speech synthesis are:

  • SpeechSynthesizer: abstracts a synthesis engine
  • PromptBuilder: build a prompt string containing emphasis, loudness, pre-recorded sounds, and other characteristics.

For example, if you want your app to say "hello world", just write:

SpeechSynthesizer synth = new SpeechSynthesizer();
synth.Speak("Hello world!");

You can easily splice this with a wave file by using the PromptBuilder, for instance:

PromptBuilder builder = new PromptBuilder();
builder.AddAudio (new Uri (@"file://\windows\media\ding.wav"));
builder.AddText("Hello world!");

SpeechSynthesizer synth = new SpeechSynthesizer();
synth.Speak(builder);

In contrast to speech recognition, all versions of Windows compatible with the WinFX Runtime Components (Windows XP, Windows Server 2003 and Windows Vista) include a speech synthesis engine.

In conclusion, it should be noted that the speech services described here use the W3C standard formats for recognition grammars (SRGS) and synthesis (SSML).

New Controls

Expander is a new control that you can use wherever you have some data that you want to be able to collapse and expand upon demand. By default, its user experience mimics the task lists that are present on the left side of an Explorer window in Windows XP, but you can restyle it for almost any purpose where you want to hide and then show content.

Aa480177.hgtomayavalonctp4(en-us,MSDN.10).gif

Figure 4. The Expander control

To use the Expander control, simply create an Expander.Header region for the title area, and then add some content within the body of the expander (you can optionally use a ScrollViewer to prevent the expanded area growing too large), as follows:

<StackPanel xmlns="https://schemas.microsoft.com/winfx/avalon/2005"
            xmlns:x="https://schemas.microsoft.com/winfx/xaml/2005" >
   <StackPanel.Resources>
      <XmlDataSource x:Key="BookData" XPath="/Books">
         <Books >
            <Book ISBN="0-2010-3812-9" Stock="in">
               <Title>Surreal Numbers</Title>
            </Book>
            <Book ISBN="1-5758-6327-8" Stock="in">
               <Title>Things a Computer Scientist Rarely Talks About</Title>
            </Book>
            <Book ISBN="0-4650-6710-7" Stock="in">
               <Title>The Design of Everyday Things</Title>
            </Book>
            <Book ISBN="0-0609-2656-2" Stock="out">
               <Title>The Lost Heart of Asia</Title>
            </Book>
         </Books>
      </XmlDataSource>
      <Style TargetType="{x:Type ListBox}">
         <Setter Property="BorderBrush" Value="Transparent" />
      </Style>
      <Style TargetType="{x:Type ListBoxItem}">
         <Setter Property="Margin" Value="1" />
         <Setter Property="Cursor" Value="Hand" />
      </Style>
   </StackPanel.Resources>
   <Expander Margin="0,0,0,10" DockPanel.Dock="Top" Background="Transparent">
      <Expander.Header>
         <TextBlock Margin="10,0,0,0" FontFamily="Tahoma" FontWeight="Bold">
            Books
         </TextBlock>
      </Expander.Header>
      <ScrollViewer VerticalScrollBarVisibility="Auto"
                    HorizontalScrollBarVisibility="Disabled">
         <ListBox FontFamily="Tahoma" 
                  DataContext="{Binding Source={StaticResource BookData},
                                XPath=/Books/Book/Title}"
                  ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True"  />
      </ScrollViewer>
   </Expander>
</StackPanel>

The StatusBar control provides arbitrary status information in a series of panels and is typically docked to the bottom of a window. It's a fairly straightforward control to use: simply create a StatusBarItem within the StatusBar.Items collection for every individual portion of the status bar. StatusBarItems can contain other complex elements, for example a StackPanel, as follows:

<Window xmlns="https://schemas.microsoft.com/winfx/avalon/2005">
   <DockPanel>

      <StatusBar DockPanel.Dock="Bottom">
         <StatusBar.Items>
            <StatusBarItem>
               <TextBlock Name="Info">
               Welcome to the new features of 
                              <Bold>Windows Presentation Foundation</Bold>!
               </TextBlock>
            </StatusBarItem>
            <StatusBarItem Name="WordButtons">
               <StackPanel Orientation="Horizontal" Margin="20 0 0 0">
                  <Button Name="REC">REC</Button>
                  <Button Name="TRK">TRK</Button>
                  <Button Name="EXT">EXT</Button>
                  <Button Name="OVR">OVR</Button>
               </StackPanel>
            </StatusBarItem>
            <StatusBarItem Name="General" HorizontalAlignment="Right">
This item is right-aligned.
</StatusBarItem>
         </StatusBar.Items>
      </StatusBar>
      <Label />
   </DockPanel>
</Window>

Also note that the Toolbar control has been extended to support overflow (in the same manner as Office 2003), with expanders being used to enable selection of an overflowed toolbar button. There have been a number of miscellaneous improvements to the menu system, and support has been added to Windows Presentation Foundation for the silver and olive versions of the Windows XP default theme.

New Codec Support

Using Windows Presentation Foundation, images can be easily integrated with graphics, media, text, and application UI. Applications building on top of the Windows Presentation Foundation will also be able to recognize, display, manipulate, and save images in new or proprietary image formats without having to recompile or redistribute their application. As long as an application uses the Windows Presentation Foundation imaging APIs, the underlying codec platform will automatically discover and invoke the appropriate codec for any image format for which support has been installed at runtime.

Several feature additions and a good deal of extra documentation have been added to the imaging codec section. The current base platform capabilities include built-in codecs for common formats such as JPEG, PNG, TIFF, and GIF. The platform also provides metadata readers and writers (so that, for instance, you could edit the EXIF metadata contained within a JPEG file and resave the updated version). Avalon also provides pixel format converters between different graphics formats, and an extensible pipeline for each of these three areas, allowing you to build your own custom converters, metadata readers, or codecs.

In post-Beta 1 releases, Windows Presentation Foundation will also add support for an extensible image effects pipeline, enabling application developers to dynamically add effects like blurring or drop shadow to a graphical image. Again, this model will be extensible to allow for custom image effects to be included.

Typography

One new feature added in the area of typography with this release is Adobe CFF support. This extension to OpenType allows for more ornate and complex fonts to be supported, and allows graphics designers to access the full range of discretionary and contextual ligatures present in a typeface. The following graphic sample shows off the capabilities of text support in the Windows Presentation Foundation. This typeface is Adobe Bickham Script Pro, and through the use of discretionary and contextual ligatures and stylistic variant glyphs provided within the font files, you can achieve impressive effects that are hard to achieve on Windows today.

Aa480177.hgtomayavalonctp5(en-us,MSDN.10).gif

Figure 5. Using Adobe CFF support from within Windows Presentation Foundation

Feature and API Changes

To enumerate every API change in this release is beyond the scope of this document; however, in this section, we provide a brief guide to the major conceptual and syntax changes that will affect developers who are attempting to port code from the previous March CTP release to the Beta 1 bits.

Styles

The styling model in Avalon has been refactored in this release. Styles no longer contain instances of the controls inside them, but instead include property setters and getters. The new format is slightly more verbose but offers somewhat greater flexibility.

The following sample shows the new syntax for setting a style:

   <Page.Resources>
      <Style TargetType="{x:Type Paragraph}">
         <Setter Property="FontFamily" Value="Palatino Linotype" />
         <Setter Property="FontSize" Value="16pt" />
         <Setter Property="Margin" Value=".25in" />
      </Style>
   </Page.Resources>

Data Templates

In previous releases, Windows Presentation Foundation distinguished between the logical element tree and a visual tree, which controlled the representation of a logical tree. Visual trees were embedded as part of styles. Now styles and visual trees have been separated as concepts; you can instead embed a template either within the parent control or as part of a resource dictionary.

The following sample shows the new and old syntax side-by-side:

Old (March CTP syntax) New (Beta 1 syntax)
<Page.Resources>
   <Style x:Key="MessageTemplate">
      <Style.VisualTree>
         <StackPanel>
            <TextBlock 
          TextContent="{Bind 
Path=From}" />
            <TextBlock
          TextContent="{Bind 
Path=Body}" />
         </StackPanel>
      </Style.VisualTree>
   </Style>
</Page.Resources>
...
<ListBox 
ItemsSource="{StaticResource 
MessageData}" 
ItemStyle="{StaticResource 
MessageTemplate}" />
<ListBox 
ItemsSource="{StaticResource 
MessageData}">
   <ListBox.ItemTemplate>
      <DataTemplate>
         <StackPanel>
            <TextBlock 
          TextContent="{Binding 
Path=From}" />
            <TextBlock 
          TextContent="{Binding 
Path=Body}" />
         </StackPanel>
      </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>

Changeables and Freezables

In previous releases of the Windows Presentation Foundation, many common types derived from a base class called Changeable. The changeable model was introduced to allow immutable types to be used as if they were mutable, with the base class doing work behind the scenes to create clones of objects as required. For instance, applications could create a brush object, set its color to red, and use it; as they made changes to the object, it was only cloned on the usage of that object. Having immutable values is an important part of creating a high performance system: the bookkeeping work required for mutable objects imposes an unacceptable load, but creating mutable copies is also important for programmatic manipulation and animation. The changeable pattern provides a model that supports both requirements.

In this release, we've made a number of refinements to this model to make it more understandable, reduce the number of unanticipated copies that are made, and create a formalized pattern for changeable collections. Within the new Freezable model, there are just two states: Frozen and Unfrozen. When you create an object, it is unfrozen by default. You can modify the object, for example, setting the brush color, and then freeze it. Once the object is frozen, it is frozen for good, although you can create a new unfrozen deep clone by using the Copy() method. The big simplification within this model is that an application itself takes responsibility for freezing an object, rather than this happening on usage.

Removal of SqlDataSource

SqlDataSource was designed to connect to a SQL Server or other .NET data provider database, and for all practical purposes was limited to corporate network scenarios. The complexity and range of configuration options required to provide full support for customer needs meant that an alternative approach has been adopted. The data binding engine in Windows Presentation Foundation is still fully capable of binding to data from any ADO.NET source; however the purely declarative method of retrieving data has now been deprecated.

Without the SqlDataSource XAML element, create ADO.NET command and data set objects in the code-behind file to populate a DataSet and assign the DataSet or DataTable to the DataContext property of a UI element. For example, to load an Access (.mdb) file, typical code could look like this:

    string mdbFile = Path.Combine(AppDataPath, "db1.mdb");
    string connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbFile);
 
    OleDbConnection conn = new OleDbConnection(connString);
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    adapter.SelectCommand = new OleDbCommand("SELECT * FROM ExecsTable;", conn);
    DataSet ds = new DataSet();
    adapter.Fill(ds, "ExecsTable");
 
    // assign data set to a panel's DataContext:
    myPanel.DataContext = ds;

API Changes

There are a number of API changes where objects have been renamed; the full list is beyond this article, but it's worth highlighting two small but significant changes that will affect almost every application. First, the FrameworkElement.ID property that was previously used to identify an object has been renamed to Name for consistency with Windows Forms and compliance with FxCop. Second, the data binding syntax has been changed so that {Bind} is now {Binding}. For more details on the syntax changes, please consult the documentation.

Conclusion

Windows Presentation Foundation continues its trajectory towards release to manufacture, and the Beta 1-based releases provide a good opportunity for companies seeking to explore enhanced data visualization, immersive Web experiences, or other rich media applications to evaluate usage scenarios and create working prototypes of Windows Presentation Foundation-based applications.

There are a number of great resources out on the Web to help you learn more about Windows Presentation Foundation:

 

About the author

Tim Sneath works as a Windows Client Technical Evangelist at Microsoft. For someone with an interest in unreleased technologies, it's somewhat ironic that he also maintains a complete museum of Virtual PC images covering Windows 1.0 to the present day. Until recently Tim lived and worked in the UK, and he's still trying to fight off the need to stop work at 3pm for afternoon tea and scones, as well as a supposedly impenetrable accent. His blog can be found at https://blogs.msdn.com/tims.