BCA / B.Tech 9 min read

Windows Presentation Foundation (WPF)

Windows Presentation Foundation (WPF) in .NET in Hindi | What is Windows Presentation Foundation (WPF) in .NET?


  • Windows Presentation Foundation (WPF) is an important part of the .NET Framework, introduced by Microsoft.
  • It is a modern and flexible user interface (UI) framework, which is mainly used to create desktop applications.
  • Using WPF, developers can create attractive, interactive, and data-based applications.
  • It is supported on the .NET Framework, .NET Core, and now .NET 6/7.
  • WPF is a powerful and modern UI framework that provides developers with the facility to create better, interactive, and data-centric applications.
  • Its XAML-based design, graphics support, and data binding features make it a suitable choice for desktop applications.
  • If you are interested in desktop application development, then learning WPF can be an important step for you.

Introduction to WPF:

  • WPF was launched in 2006 with .NET Framework 3.0. It is the next version of Windows Forms, which was designed to overcome the limitations of the old UI framework.
  • WPF is based on XAML (Extensible Application Markup Language), which provides the facility to separate UI design and code.
Main features of WPF:

  • XAML-based design: In WPF, XAML (Extensible Application Markup Language) is used for UI design. XAML is a markup language that is based on XML.
Example:

<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="My WPF App" Height="350" Width="525">
    <Grid>
        <Button Content="Click Me" Width="100" Height="30"/>
    </Grid>
</Window>

  • Data binding: WPF has a data binding feature, which creates a direct connection between the UI and backend data. This updates the data in real time.
  • Styling and Templating:  In WPF, the look and feel of the UI can be easily customized using styles and templates.
  • Styles can be used like CSS.
  • Graphics and multimedia: WPF supports 2D and 3D graphics, video, audio, and animation. It uses DirectX, which provides better performance.
  • Flexibility: WPF can be used to create applications on various types of devices such as desktops, tablets, etc.
  • Event-driven programming: WPF uses an event-driven model, which makes it easy to program any interaction on the UI.
Advantages of WPF:

  • Modern UI: It is easy to create attractive and rich user interfaces through WPF.
  • Resolution Independent: WPF does not depend on device pixels and works well on any screen resolution.
  • Data binding and MVVM pattern: It supports the MVVM (Model-View-ViewModel) architecture, which makes it easy to manage code.
  • Customization: In WPF, the UI can be fully customized through styles and templates.
Uses of WPF:

  • Desktop applications: Such as inventory management systems, medical software, and other desktop applications.
  • Multimedia applications: Video editing tools, music players, etc.
  • Graphics and animation based applications: Such as CAD tools and gaming applications.
  • Create a new project: Choose "WPF App (.NET Core)" or "WPF App (.NET Framework)".
  • Write code through XAML and C#.