Monday, March 26, 2012

XBAP stands for XAML Browser
Application. XBAP allows for WPF applications to be used inside a browser. The .NET
framework is required to be installed on the client system. Hosted applications
run in a partial trust sandbox environment. They are not given full access to
the computer's resources and not all of WPF functionality is available.

WPF supports the creation of
applications that run directly in a web browser. (So willWPF/E,
when it is released.) They are called XAML Browser Applications (XBAPs), andhave
a.xbapfile extension.

The power of this WPF support is
that the exact same programming model is used for aXAML
Browser Application as for a standard Windows application. Therefore, creating
anXBAP isn’t much different than creating a standard Windows
application. The maindifferences are as follows:

.Not all features in WPF or the .NET
Framework are accessible (by default).

.Navigation is integrated into the
browser (for Internet Explorer 7 or later).

Thursday, March 15, 2012

When you create a WPF Windows
Application in Visual Studio, the generated project has no Main method, yet it
still runs as expected! In fact, even attempting to add a Main method
gives a compilation error telling you that it is already defined.
Application is special-cased when it is compiled from XAML, because Visual
Studio assigns
the XAML file a Build Action of ApplicationDefinition. This causes a Main
method to be
autogenerated.

All
absolute measurements, such as the numbers used in this section’s size-related
properties,
are specified in device-independent pixels. These “logical pixels” are meant to
represent
1/96th of an inch, regardless of the screen’s DPI setting. Note that device-independent
pixels are always specified as double values, so they can be fractional.
The exact measurement of 1/96th of an inch isn’t important, although it was
chosen
because on a typical 96 DPI display, one device-independent pixel is identical
to one physical
pixel. Of course, the notion of a true “inch” depends on the physical display
device. If an
application draws a one-inch line on my laptop screen, that line will certainly
be longer than
one inch if I hook up my laptop to a projector!

Setting AcceptsReturn to true allows
users to press the Enter key to create a new line of
text. Note that TextBox always supports multiple lines of text
programmatically. If its Text is
set to a string containing NewLine characters, it displays the multiple lines regardless
of the
value of AcceptsReturn. Also, the multiline support is completely independent
from text
wrapping. Text wrapping only applies to individual lines of text that are wider
than the
TextBox.

Sorting can be done via a mechanism
on theItemsCollectionobject, so it applies equallyto
allItemsControls. ItemsCollection has a SortDescriptionsproperty
that can holdany number ofSystem.ComponentModel.SortDescription
instances. EachSortDescriptiondescribes which property of the
items should be used for sorting andwhether the sort is ascending or
descending. For example, the following code sorts a bunchofContentControl
items based on their Content property:

By default, ListBox scrolls on an
item-by-item basis. Because the scrolling is based on each
item’s height, it can look quite choppy if you have large items. If you want
smooth scrolling,
such that each scrolling action shifts the items by a small number of pixels
regardless of
their heights, the easiest solution is to set the ScrollViewer.CanContentScroll
attached
property to false on the ListBox.
Be aware, however, that by making this change you lose ListBox’s virtualization
functionality.
Virtualization refers to the optimization of creating child elements only when
they become
visible on the screen. Virtualization is only possible when using data binding
to fill the
control’s items, so setting CanContentScroll to false can negatively impact the
performance
of data-bound scenarios only.