How XAML Differs in Windows 8

If you have experience with previous versions of XAML, you need to know about some key differences in Windows 8 XAML from previous versions. There are missing elements, some of which simply don't have an analog in Windows 8, and others which have a functional replacement.

Missing Elements

Some of your old friends from those platforms are not present in Windows 8. Some were left out because they are not easy to fit into a touch-optimized experience. Because this is a version 1.0 product, some desirable features didn't make it into the released product simply because of lack of time.

The differences are too extensive to present a comprehensive list, but here are the panels and controls you are most likely to miss:

  • TreeView
  • DataGrid
  • TabControl
  • Expander
  • DatePicker and MonthCalendar
  • DockPanel
  • WrapPanel
  • UniformGrid

Except for WrapPanel, these missing elements have no replacement element that supplies near-equivalent functionality. The user interaction patterns for TreeView, DataGrid, and TabControl are not easy to translate to a touch-first mode, so analogs were not attempted in the first version of Windows 8 XAML. DockPanel and UniformGrid are lesser used panels, and that's probably why they didn't make the cut.

Expander, DatePicker, and MonthCalendar are missing as well. With Expander, it is an open question of whether it fits the Windows 8 UI conventions. However, it's clear that line-of-business apps need date controls, so you'll probably see those in a future version. For the present, the lack of date controls is one of the most compelling reasons to obtain a package of third-party controls. Some of them do have date controls, and writing one yourself would certainly be tedious.

For layout panels, the most important omission is the WrapPanel. However, two replacement panels with somewhat similar functionality are available—WrapGrid and its cousin VariableSizedWrapGrid. They are more restrictive than WrapPanel, however, because they can only be used inside ItemControls. You will see VariableSizedWrapGrid used in an example later in the chapter.

Old Elements Replaced by Functional Equivalents in Windows 8

There are several other missing elements that have replacements with similar functionality, but adapted for the Windows 8 environment:

  • ContextMenu—replaced by PopupMenu.
  • MessageBox—replaced by MessageDialog.
  • Common dialogs—replaced by “pickers”; for example, the OpenFileDialog is replaced by FilePicker.
  • RichTextBox—replaced by RichEditBox.

Pickers are discussed in the section below on new Windows 8 elements, and the example for a picker shows the MessageDialog in use.

Syntax Differences

The last chapter mentioned that there are variations between Windows 8 XAML and previous versions in both XAML syntax and certain APIs. In case you skipped that chapter because you have XAML experience, the two examples mentioned in that chapter were the way XAML namespaces were declared (with “using” instead of “clr-namespace”), and the different method signature for the IValueConverter interface. If you're experienced with WPF or Silverlight, you will find a number of other minor API differences as you attempt to apply familiar capabilities.

Using Page as the Root Visual Element

In WPF, the most commonly used root visual elements are Window and UserControl. Window (or its subclass NavigationWindow) is almost always used as the entry point for an application. Silverlight applications more commonly use UserControl as the root visual element, though Window is available for some out-of-browser scenarios.

In Windows 8, by contrast, the most common root visual elements are Page and other classes that inherit from Page. As you'll see, the standard application templates in Visual Studio offer a subclass of Page called LayoutAwarePage that you will likely use a lot. It adds more functionality to Page for scenarios such as snapped views.

UserControl is still used a lot in Windows 8, but not as a root class that takes over the whole screen. Typically, a UserControl is used for sections of screens that need to contain a reusable arrangement of elements, such a UserControl to hold all the fields to enter an address.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset