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.
Features
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 SetWPF 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- <ListBox Margin=”5,0,5,0” selectionMode=”Multiple” Name=”lstDemmy”>
- <StackPanel Orientation=”Horizontal”>
- <Image Source=”Happyface.jpg” Width=”30” Heght=”30” />
- <Label VerticalContentAlignment=”Center” Content=”A Happy Face” /> </StackPanel>
- <StackPanel Orientation=”Horizontal”>
- <Image Source=”redex.jpg” Width=”30” Heght=”30” />
- <Label VerticalContentAlignment=”Center” Content=”A Warning sign” /> </StackPanel>
- </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- <CheckBox Grid.Column=”0” Grid.Row=”3”>
- <CheckBox.ToolTip>
- <StackPanel>
- <Label FontWeight=”Bold” Content=”The Check Box” />
- <TextBlock Padding=”10” TetWrapping=”wrapWithOverflow” Width=”200”> Check Box with a fancy Tip Control </TextBolck>
- <Line Stroke=”Black” StrokeThickness=”1” X2=”200” />
- <StackPanel Orientation=”Horizontal”>
- <Image Margin=”3” Source=”help.gif”/>
- <Labe Content=”Press F1 for more help.”/> </StackPanel>
- </StackPanel>
- </CheckBox.ToolTip>
- </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.- <Expander Header=”Subject” Grid.ColumnSpan=”4” Grid.RowSpan=”1” Margin=”0,5,5,5”>
- <StackPanel>
- <CheckBox Content=”English” />
- <CheckBox Content=”Maths” />
- <CheckBox Content=”Computer Science” /> </StackPanel>
- </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.
Example,- <ListBox Name=”LstChkLst”>
- <CheckBox Margin=”5”>Windows Presentation Foundation</CheckBox>
- <CheckBox Margin=”5”>Windows Communication Foundation</CheckBox>
- <CheckBox Margin=”5”>Windows Workflow Foundation</CheckBox>
- </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.- <ComboBox>
- <!-- ITEM #1 -->
- <StackPanel Orientation=”Horizontal” Margin=”5”>
- <Image Source=”Image1.png” />
- <StackPanel Width=”200”>
- <TextBlock Margin=”5,0,5,0” FontSize=”14” fontWeight=”Bold”>WPF Styles</TextBlock>
- <TextBlock Margin=”5,0,5,0” FontSize=”14” fontWeight=”Bold”>WPF Styles, it is collection of properties and actions </TextBlock>
- </StackPanel>
- </stckPanel>
- <!-- ITEM #2 -->
- <StackPanel Orientation=”Horizontal” Margin=”5”>
- <Image Source=”Image1.png” />
- <StackPanel Width=”200”>
- <TextBlock Margin=”5,0,5,0” FontSize=”14” fontWeight=”Bold”> Control Template </TextBlock>
- <TextBlock Margin=”5,0,5,0” FontSize=”14” fontWeight=”Bold”>Control Template defines the appearance of the control. </TextBlock>
- </StackPanel>
- </stckPanel>
- </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”.

Join the conversation! Your thoughts help the community grow.