WPF Overview — Introduction

Disclaimer: This introduction assumes that you are not a complete beginner and you have at-least read an overview of WPF on the official docs.

WPF — Windows Presentation Foundation is a framework for building desktop application for windows platforms. It has been around since ‘2006?’ and it is widely used for business line desktop applications along side WinForms.

Recently Microsoft announced another framework, UWP(Universal Windows Platform) which aims to provide a unified dev platform for modern Microsoft devices such as Xbox, Mobile, TVs, Desktops etc. However given that UWP is relatively new and unstable, WPF is still the number one choice for many developers.

WPF uses XAML to defne the UI and C# to define business and interaction logic(or behavior). A typical WPF application contains one main window, with nested layout panels followed by UI elements(or Controls) as shown below.

Sample WPF application

Architectural patterns

1. Code behind

  • By default the interaction logic is placed in the code-behind which is easier to work with for new developers(More on this later).
  • This pattern is rarely used due to relatively high coupling between the view and the back-end making the application harder to test among many other disadvantages.

2. MVVM — Model View ViewModel

  • Structures the app such that the views get their state from view models instead of using “code-behind”.
  • This means that Commands are used instead of events to handle user actions.
  • The data is passed into the views through Data binding. It is also possible to pass data from the view to the back-end via two way data binding.
A sample WPF MVVM application
  • A typical enterprise WPF application uses the N-layer MVVM architecture as shown in the figure above.
  • Veteran developers argue that this pattern is more maintainable, scalable and testable(Learn more)

In my personal opinion, I believe code behind is easier to work with when starting out compared to MVVM where you actually need to dig deeper to get it working correctly. Despite this, I believe that large MVVM apps are more maintainable and thus MVVM is better suited for Enterprise scale apps.

--

--