Demo
WPF
- What isf WPF?
- Windows Presentation Foundation (WPF) is a free and open-source graphical subsystem (similar to WinForms) originally developed by Microsoft for rendering user interfaces in Windows-based applications.
- WPF vs WinForms
WPF | WinForms |
---|---|
It is based on DirectX with XAML support. | It provides access to the native windows library of common controls. |
It uses markup language for designing UI allowing the design of complex user interfaces. | It does not use a markup language for design. In fact, it uses event-driven controls for the design. |
It can render fast as compared to WinForms, complexity, and support. | It renders slow as compared to WPF. |
It can be used to develop and design both windows applications and web applications. | It can only be used to develop and design windows applications. |
It has unlimited UI customization and controls can be customized easily as it is totally written from scratch. | In this, controls are limited and difficult to customize. |
It is easier to separate UO from back-end logic. | It is tough to separate UI from back-end logic. |
It allows you to handle large data sets because of its in-built feature “user interface virtualization”. | It does not have a “user interface virtualization” feature. |
It takes up more RAM than WinForms. | It takes a smaller memory footprint. |
It is considered good when the application requires many media types, create a skinned UI, bind to XML, develop a desktop application having a web-like navigation style. | It is considered good if you want to develop an application without much added modern functionality, more online resources. |
It offers effective and fully supported data binding as compared to WinForms. | It offers data binding but in a limited way. Therefore, it’s less effective as compared to WPF. |
It also offers rich, interactive, animated, hardware accelerated, vector 2D and 3D capabilities for developing applications. | It does not offer any rich, Interactive, animated, hardware accelerated, vector 2D and 3D capabilities as compared to WPF. |
It is a little bit tough, time-consuming, and complex to use WPF as compared to WinForms. | It is simple to use WinForms as controls can be used easily, it’s less time-consuming and less tricky as compared to WPF. |
It has an inbuilt story boarding feature and animation model, it has the ability to use business objects in UI declaratively. | It does not provide such features. |
Window
xmlns
means xml name pace.Window_Loaded
invoke event when WPF window machine is loaded.- When you add event like
Window_Loaded
, function is automatically added in MainWindow.xaml.cs
Layout
Border
- Draws a border, background, or both around another element.
StackPanel
- Arranges child elements into a single line that can be oriented horizontally or vertically.
- The default value is stretch for both HorizontalAlignment and VerticalAlignment of content that is contained in a StackPanel.
Grid
- Defines a flexible grid area that consists of columns and rows.
- If a child element is added to a column within a Grid, and the column has its Width property set to
Auto
, the child will be measured without restrictions. - Columns and rows that are defined within a Grid can take advantage of
*
sizing to distribute remaining space proportionally. When*
is selected as the height or width of a row or column, that column or row receives a weighted proportion of the remaining available space. This is in contrast toAuto
, which distributes space evenly based on the size of the content that is within a column or row. This value is expressed as*
or2*
when you use Extensible Application Markup Language(XAML).
Grid.ColumnDefinitions
- Each column in the grid is defined using a Column Definition.
- Columns are positioned in the grid according to the order the Column Definitions are specified in the Grid Options.
Text
TextBlock
- Provides a lightweight control for displaying small amounts of flow content.
Input
x:name
is a name of the element referense.
Button
Click
invoke event when the button is clicked.
TextBox
TextChanged
invoke event when the text in text box is changed.
ComboBox
SelectionChanged
invoke event when selected value is changed.
CheckBox
Checked
invoke event when check box is checked.
Modal
MessageBox
- Show message box in new window.
Demo
- MainWindow.xaml
- MainWindow.xaml.cs