Overview Of WPF Features

Windows Presentation Foundation (WPF)

  • It is a new graphical subsystem that provides the functionality to create next generation Windows applications.
  • It combines user interface, 2D and 3D graphics, documents, and multimedia.
  • It is an API for building rich Windows client applications with visually stunning user experiences.
  • It contains the capabilities of preceding technologies such as MFC, Windows Forms including GDI, GDI+, HTML, and etc.


XAML (Extensible Application Markup Language)

XAML is an XML based language used for designing presentation logic in WPF. With the declarative programming model enabled by XAML, the presentation logic and business logic can be split. The designer can use XAML to design the page. After finishing, the design of page can be handed to a developer for integration with his or her business logic, it is more readable yet shorter than the code.

Rich Control Set

WPF has plenty of standard sets of controls that enable quick assembling of traditional user interfaces. Most of the controls are similar to Win.forms controls with little additional changes, as shown below.

  • ListBox
    In WinForm, the list box can have only text values. It cannot display a list of images with the text next to it.

    Example of List box in WPF

    1. <ListBox Margin=”5,0,5,0” selectionMode=”Multiple” Name=”lstDemmy”>  
    2.     <StackPanel Orientation=”Horizontal”>  
    3.         <Image Source=”Happyface.jpg” Width=”30” Heght=”30” />  
    4.         <Label VerticalContentAlignment=”Center” Content=”A Happy Face” /> </StackPanel>  
    5.     <StackPanel Orientation=”Horizontal”>  
    6.         <Image Source=”redex.jpg” Width=”30” Heght=”30” />  
    7.         <Label VerticalContentAlignment=”Center” Content=”A Warning sign” /> </StackPanel>  
    8. </ListBox>  

  • CheckBox/RadioButton
    Both, WinForm and WPF, provide checkbox and radio button controls to give the user an option, such as true/false. WPF supports tooltip property while the controls in WinForm do not support such property. Additionally, the tooltip can be customized to include text and image or a multiline text.

    Example in WPF

    1. <CheckBox Grid.Column=”0” Grid.Row=”3”>  
    2.     <CheckBox.ToolTip>  
    3.         <StackPanel>  
    4.             <Label FontWeight=”Bold” Content=”The Check Box” />  
    5.             <TextBlock Padding=”10” TetWrapping=”wrapWithOverflow” Width=”200”> Check Box with a fancy Tip Control </TextBolck>  
    6.                 <Line Stroke=”Black” StrokeThickness=”1” X2=”200” />  
    7.                 <StackPanel Orientation=”Horizontal”>  
    8.                     <Image Margin=”3” Source=”help.gif”/>  
    9.                     <Labe Content=”Press F1 for more help.”/> </StackPanel>  
    10.         </StackPanel>  
    11.     </CheckBox.ToolTip>  
    12. </CheckBox>  

    The CheckBoxes or Radio buttons in WPF or WinForms can be grouped using GroupBox container. The WPF provides an additional control called Expander. This Expander also like Group Box, but contains a button that enables expanding and collapsing the inner content. The expander can be used as shown markup below.

    1. <Expander Header=”Subject” Grid.ColumnSpan=”4” Grid.RowSpan=”1” Margin=”0,5,5,5”>  
    2.     <StackPanel>  
    3.         <CheckBox Content=”English” />  
    4.         <CheckBox Content=”Maths” />  
    5.         <CheckBox Content=”Computer Science” /> </StackPanel>  
    6. </Expander>  

  • CheckBox List Control
    WPF allows adding multiple checkbox list controls inside ListBox. Additionally, the layout of these checkbox list controls can also be controlled by using WPF standard layouts.


    1. <ListBox Name=”LstChkLst”>  
    2.     <CheckBox Margin=”5”>Windows Presentation Foundation</CheckBox>  
    3.     <CheckBox Margin=”5”>Windows Communication Foundation</CheckBox>  
    4.     <CheckBox Margin=”5”>Windows Workflow Foundation</CheckBox>  
    5. </ListBox>  

  • ComboBox
    The comboBox supports binding to in-memory collection or ADO.NET objects. They always display a single text value. They cannot display images or image with text like ListView control. However, WPF provides a ComboBox that helps display items where these items make the ComboBox look like a Microsoft Office-style “gallery”, showing a preview and description for each item as shown in the markup below.

    1. <ComboBox>  
    2.     <!-- ITEM #1 -->  
    3.     <StackPanel Orientation=”Horizontal” Margin=”5”>  
    4.         <Image Source=”Image1.png” />  
    5.         <StackPanel Width=”200”>  
    6.             <TextBlock Margin=”5,0,5,0” FontSize=”14” fontWeight=”Bold”>WPF Styles</TextBlock>  
    7.             <TextBlock Margin=”5,0,5,0” FontSize=”14” fontWeight=”Bold”>WPF Styles, it is collection of properties and actions </TextBlock>  
    8.         </StackPanel>  
    9.         </stckPanel>  
    10.         <!-- ITEM #2 -->  
    11.         <StackPanel Orientation=”Horizontal” Margin=”5”>  
    12.             <Image Source=”Image1.png” />  
    13.             <StackPanel Width=”200”>  
    14.                 <TextBlock Margin=”5,0,5,0” FontSize=”14” fontWeight=”Bold”> Control Template </TextBlock>  
    15.                 <TextBlock Margin=”5,0,5,0” FontSize=”14” fontWeight=”Bold”>Control Template defines the appearance of the control. </TextBlock>  
    16.             </StackPanel>  
    17.             </stckPanel>  
    18. </ComboBox>  

  • Button Control
    The shape of the Button control cannot be changed in Win Form, but WPF can create buttons that are elliptical in shape or button with shaded background and foreground.

  • TextBox
    Similar to WinForm application, WPF also provides a TextBox that helps display editable text control. And WPF control additionally supports spell check by using SpellCheck.IsEnabled=”True”.
WPF Resources

WPF Resource means to define and reuse frequently required objects and values called resources. These resources are often styles or bindings. It can be defined at application level, window level, and container level or at control level.

There are Two types of Resources,

  1. StaticResource
    A resource defined and used at design time.

  2. DynamicResources
    A resource that provides a value for a property by referencing the resource values at run time.
WPF Styles

Styles are sets of properties and actions to associate with an element. These styles are similar to CSS styles. Styles in WPF can do more than CSS style can. Based on user interaction or on content, they can make the control look or behave differently, using triggers. Styles can be defined declaratively in XAML Using <Style> with <Setter> tag or programmatically using Style class instance.

WPF Templates

WPF supports managing the look and feel of a control that is a look-less control. A template, allows completely replacement of an element’s visual tree with anything that can be required, while keeping all of its functionality intact.

There are two types of templates

  1. Control Template
    It allows Changing the structure and appearance of a control by defining a new control template for the control For example, it can be used for creating an elliptical button instead of dull gray rectangular button.
  1. Data template
    It is used to define the visual representation of data. It determines what the data looks like in the rendered application. it is a XAML markup that defines how a bound data object should be displayed.
Layout Panels

Layout Panels are used to position the elements within a window.

  1. Canvas
    It is the most basic panel. The elements can be positioned in a Canvas using its attached properties: Left, Top, Right , and Bottom.

  2. StackPanel
    It is the panel that allows stacking its child elements sequentially either horizontally or vertically.

  3. WrapPanel
    It is similar to StackPanel. In addition to stacking its child elements, it wraps them to additional rows or columns when there is not enough space for a single stack. This is useful for displaying an indeterminate number of items with a more interesting layout than asimple list, much like Windows Explorer does.

  4. DockPanel
    It enables easy docking of elements to an entire side of the panel, stretching it to fill the entire width or height. It also enables a single element to fill all the remaining s space unused by the docked elements. It has a Dock attached property, so child elements can control their docking with one of four possible values: Left, Top, Right, and Bottom.

  5. Grid
    It enables arranging elements in a tabular fashion and provides a number of features to control the rows and columns in interesting ways
Audio and Video

WPF supports media integration using audio/video files. It supports wide variety of media files like Windows Media Video (.WMV), MPEG, AVI.

For example,

  1. <MediaElement Source=”album\songEx.WMV” width=”400” Height=”300” />   
WPF Interoperability

WPF lacks some features that Win Forms already had such as WPF does not include controls like report viewer, DateTimePicker, MonthCalender, NumericUpDown, MaskedTextBox, NotifyIcon, dataGridView etc., and MDI applications. For this WPF provides a solution to meet this requirement in the form of System.Windows.Forms.Integration namespace that Provides two key classes,
WindowsFormsHost and ElementHost. A WPF application permits hosting Windows Forms Controls in WPF using WindowsFormsHost. A Windows Forms can host a WPF element by using ElementHost Class.

WPF supports documents

WPF supports documents like

  • Fixed Documents
    It maintains the precise positional placement of content elements independent of the display or print device in use.
  • XML Paper Specification (XPS) Document
    It is a cross platform, XML schema based, electronic paper that can be read by humans, hardware and software.
  • Flow Document
    It is designed to reflow content depending on the container or the device where it is displayed.