TOC

This article is currently in the process of being translated into Malayalam (~29% done).

About WPF:

WPF vs. WinForms

ഈ അധ്യായത്തില്‍ WPF ഉം WinForms ഉം തമ്മിലൊന്നു താരതമ്യം ചെയ്യാം - അവതാര ഉദ്ദേശ്യങ്ങള്‍ ഏതാണ്ട് സമാനമെങ്കിലും ഈ രണ്ടു ചട്ടക്കൂടുകളും വളരെ വ്യത്യസ്തമാണ്. WinForms നിങ്ങള്‍ ഉപയോഗിച്ചിട്ടില്ലെങ്കില്‍, അഥവാ ഇതാദ്യമായിട്ടാണ് നിങ്ങള്‍ ഒരു GUI ചട്ടക്കൂട് ഉപയോഗിക്കാന്‍ നോക്കുന്നത് എങ്കില്‍, ഈ അദ്ധ്യായം ഒഴിവാക്കുന്നതില്‍ തെറ്റില്ല.

TextBox പോലെ Microsoft Windows ന്‍റെ അടിസ്ഥാന കണ്ട്രോളുകള്‍ ഉപയോഗിച്ച് കെട്ടിയെടുത്ത ഒരു തട്ടാണ് WinForms എങ്കില്‍ ഒന്നേയെന്ന് എഴുതിയുണ്ടാക്കിയ WPF ആവട്ടെ ആ ആശ്രയത്തം ഒഴിവാക്കി കണ്ട്രോളുകളുടെ പരിമിതികളെ മറികടന്നിരിക്കുന്നു. ഇതൊരു നിസ്സാര വ്യത്യാമെന്നു തോന്നാം, പക്ഷേ അങ്ങനെയല്ല - Win32/WinAPI യുടെ മുകളില്‍ പണിഞ്ഞവര്‍ക്കിത് പെട്ടെന്ന് മനസിലാകും.

പടവും കുറിപ്പും വെച്ച ഒരു ബട്ടണ്‍ ഇതിന് നല്ലൊരു ഉദാഹരണമാണ്. ഇതൊരു അടിസ്ഥാന കണ്ട്രോളല്ല, അതുകൊണ്ടുതന്നെ WinForms ല്‍ ലഭ്യവുമല്ല. ഒന്നുകില്‍ പുതിയൊരു ബട്ടണ്‍ കണ്ട്രോള്‍ മൊത്തമായി നിര്‍മിച്ചെടുക്കുകയോ അല്ലെങ്കില്‍ തേര്‍ഡ് പാര്‍ട്ടി കണ്ട്രോളുകള്‍ വാങ്ങുകയോ ചെയ്യണം. WPFലാവട്ടെ ബട്ടണ്‍, മറ്റ്‌ മിക്ക WPFകണ്ട്രോളുകളെയും പോലെ, സ്വതേ "അരൂപിയാണ്" - അതായത് മറ്റു കണ്ട്രോളുകളെ ഉള്ളില്‍ വഹിക്കാന്‍ (to contain) കഴിയുമെന്നര്‍ത്ഥം. അപ്പോള്‍ ബട്ടണ്‍ എന്നത് പ്രധാനമായും അതിന്‍റെ ഉള്ളടക്കത്തിനുള്ള പരിധിയും (border) അതിന്‍റെ തന്നെ പലതരത്തിലുള്ള അവസ്ഥകളും (e.g. untouched, hovered, pressed) മാത്രമാണ്. പടവും കുറിയുമുള്ള ബട്ടണ്‍ വേണോ - ഒരു Image ഉം TextBlock കണ്ട്രോളും Button ഇല്‍ ഇടുകയേ വേണ്ടൂ. ഈ ഒരു വഴക്കം സ്റ്റാന്‍ഡേര്‍ഡ് WinForms കണ്ട്രോളുകളില്‍ സാധ്യമേയല്ല.

The drawback to this flexibility is that sometimes you will have to work harder to achieve something that was very easy with WinForms, because it was created for just the scenario you need it for. At least that's how it feels in the beginning, where you find yourself creating templates to make a ListView with an image and some nicely aligned text, something that the WinForms ListViewItem does in a single line of code.

This was just one difference, but as you work with WPF, you will realize that it is in fact the underlying reason for many of the other differences - WPF is simply just doing things in its own way, for better and for worse. You're no longer constrained to doing things the Windows way, but to get this kind of flexibility, you pay with a little more work when you're really just looking to do things the Windows way.

The following is a completely subjective list of the key advantages for WPF and WinForms. It should give you a better idea of what you're going into.

WPF advantages

  • It's newer and thereby more in tune with current standards
  • Microsoft is using it for a lot of new applications, e.g. Visual Studio
  • It's more flexible, so you can do more things without having to write or buy new controls
  • When you do need to use 3rd party controls, the developers of these controls will likely be more focused on WPF because it's newer
  • XAML makes it easy to create and edit your GUI, and allows the work to be split between a designer (XAML) and a programmer (C#, VB.NET etc.)
  • Databinding, which allows you to get a more clean separation of data and layout
  • Uses hardware acceleration for drawing the GUI, for better performance
  • It allows you to make user interfaces for both Windows applications and web applications (Silverlight/XBAP)

WinForms advantages

  • It's older and thereby more tried and tested
  • There are already a lot of 3rd party controls that you can buy or get for free
  • The designer in Visual Studio is still, as of writing, better for WinForms than for WPF, where you will have to do more of the work yourself with WPF