Alex Gordon
Alex Gordon

Reputation: 60691

What is the difference between WPF and WinForms?

I am programming simple Windows apps. I don't need DB support. Why would I use WPF instead of WinForms?

Upvotes: 41

Views: 68690

Answers (8)

Muhammad Hamada
Muhammad Hamada

Reputation: 11

  • The single most important difference between WinForms and WPF is the fact that while WinForms is simply a layer on top of the standard Windows controls (e.g. a TextBox), WPF is built from scratch and doesn't rely on standard Windows controls in almost all situations.

  • A great example of this is a button with an image and text on it. This is not a standard Windows control, so WinForms doesn't offer you this possibility out of the box. Instead, you will have to draw the image yourself, implement your own button that supports images or use a 3rd party control. With WPF, a button can contain anything because it's essentially a border with content and various states (e.g. untouched, hovered, pressed).

check this article it will help you: https://www.wpf-tutorial.com/about-wpf/wpf-vs-winforms/#:~:text=The%20single%20most%20important%20difference,controls%20in%20almost%20all%20situations.

Upvotes: 1

Chris O
Chris O

Reputation: 5037

WPF can utilize hardware acceleration to some degree, but that is expected to improve over time.

Also, because of XAML, you have more options for "doing stuff", declarative vs. programmatic, or a mixture of both.

Microsoft no longer does active development on WinForms, they are strongly pushing WPF, and for good reason.

WPF allows for much easier "resolution agnostic" designing. To achieve that in WinForms, it is a lot more work.

The MVVM pattern was already mentioned in one of the comments, this allows one to do real unit testing vs. GUI-based testing on your code, that is a big win, in my experience.

Upvotes: 5

jrista
jrista

Reputation: 32950

WPF is the current platform for developing Windows desktop applications. It is a modern, advanced, hardware accelerated framework for developing applications that maintain separation of concerns. It supports advanced rendering of 2D vector and 3D graphics, providing an immense range of capabilities for building rich, interactive, and quality user interfaces.

WinForms, on the other hand, provides a basic platform for developing "classic" Windows apps with your standard look and feel using standard controls. It does not offer the rich, hardware accelerated, vector 2D and 3D capabilities that WPF offers. WinForms applications tend to have much greater coupling between application behavior and UI (view), which presents a less flexible platform upon which to develop applications.

As for which one you choose, it entirely depends on your needs. If you need vector graphics, 3D rendering, the ability to create rich, interactive, animated, modern user interfaces, and/or wish to maintain separation of concerns, WPF is definitely the right choice. If you need none of that, and just need to create a simple UI that solves a simple problem, WinForms will meet your needs just fine.

Upvotes: 20

ChrisF
ChrisF

Reputation: 137128

One obvious answer is that WPF offers a richer user experience than WinForms, allowing for animations (even 3D) in the user interface, for example.

From a development perspective, it goes a long way to enforce the separation of the User Interface (in the XAML) from the business logic (in VB.NET or C#), which is always a good thing.

A Google search for "WPF vs WinForms" brings up lots of pages that discuss this issue. I won't repeat all their findings here, but this page raises some interesting points:

  1. Databinding in WPF is superior to what Windows Forms offers.
  2. UI and C# business logic can be cleanly separated in WPF
  3. Storyboard
  4. Data/control templates – a much cleaner way than anything Windows Forms can offer.
  5. Styles – cool and simple. Its so easy to style all your buttons in an application to have the same look and feel.
  6. Even if the VS designer breaks, its easy to code XAML.
  7. UI virtualization – I’ve got grids with 100K rows, ticking off a moving market. Performance would be dreadful if it wasn’t for UI visualization which come for free.
  8. 3D support.
  9. Nothing scientific but, UI development feels quicker in WPF – maybe its just because a WPF application looks cooler at the end of an iteration, or maybe its because development really is quicker.
  10. I can add a User Experience engineer to my team, and with no C# knowledge he can work magic in Expression Blend and give the front-office trading application a makeover that is guaranteed to win over the business users.

Upvotes: 64

CaptainDeveloper
CaptainDeveloper

Reputation: 23

A

Anywhere Execution due to XAML.

Can be used as WinApp, WebApp, Mobile.

Whereas WindowsForm Internal UI representation is in C#.

B

Binding -->Simple object to object data transfer.

C

Common look and feel(Styles) -->can define look and feel styles commonly and use it for bunch of controls.

D

Directive Programming -->Binding objects in XAML.

E

Expression blend and Animation-->WPF uses DirectX, and DirectX can be used for animation.

F

Faster Execution(Hardware Rendering)

WPF internally uses DirectX (Hardware rendering) while Winform internally uses GDI (mostly uses Software rendering).

There are two ways by which a computer renders display on monitor.

1) (CPU) Software rendering -->In case of CPU rendering ,the CPU drives the whole logic of rendering display on monitor.CPU also does other operations like running applications,performing memory management,running OS. So on top of it its extra load to display things on monitor.

2)(GPU) Hardware rendering -->Its Specialized kinda processor, specifically meant for rendering and display faster on monitor.

Now in WPF, this rendering is further optimised in

>Tier 0 mode (Software rendering) uses DirectX7 internally,

>Tier 1 mode (Partial Hardware rendering) uses DirectX7 to DirectX9 internally,

>Tier 2 mode (Hardware rendering) uses DirectX9 internally. 

G

Graphic Independence (DIP) -->Means resolution independence

Resolution --> Total number of pixels that fits into screen/monitor

Pixel --> Simple dot on screen.

Windows form uses pixels as a measurement unit, so when pixel changes then win forms has to adjust itself that means we have to write logic for it.

But WPF does not use pixels as a measurement unit but uses DIP(Device independent pixels)

1 DIP = 1/96th of the inch.

At last Testing --> Better unit testing with use of MVVM pattern.

Upvotes: 2

Budda
Budda

Reputation: 18343

Nobody mentioned about better testing capabilities of the WPF applications (if they are written in the correct way, for example based on the MVVM pattern).

Upvotes: 2

Meta-Knight
Meta-Knight

Reputation: 17845

If you want to have a rich user interface like the image posted in your previous question, I'd recommend going with WPF. Aside from making it easier to create a nice-looking application, it's also the technology Microsoft will push in the future. There's almost no new development for Winforms.

Upvotes: 1

Benjol
Benjol

Reputation: 66531

  • To learn.
  • To have greater (i.e. any) control over the appearance of your program
  • To benefit from easier data binding, triggers, styles

(I don't see what DB support has got to do with it)

Upvotes: 13

Related Questions