Difference in display of WPF and Windows Forms applications

In fact, I started learning WPF. I have several months of experience developing Windows Forms applications. Although, I understand the meaning of the WPF application, but still I can not distinguish the difference between the two, based on their output.

Regarding this Link: Device Independent Pixel (DPI) , I learned that whenever an operating system creates a WPF application, it controls its size by its own resolution.

So, to check this difference, I created two demo applications in both frameworks and also changed the permissions ... but I did not find a satisfactory difference. This may explain that this is a WPF application, and this is a Windows Forms application.

It does not create a single scrollbar at maximization and does not make the button large or small when changing the resolution.

I read somewhere that Visual Studio 2010 has been rewritten in WPF. But in my experiments, I saw that (when changing the resolution of the desktop) it makes the text and graphics unreadable / blurry. When recalibrating the window, everything was hidden except for the menu bar. And the contents of the menu bar changed its positioning, for example. the rightmost menu item moved down. Why?

Please make me correct and explain a little more (this display problem) too.

+7
winforms wpf
source share
2 answers

To answer this question correctly, I may have to write a whole chapter here, but I keep it short. From what I have learned so far, there are three key differences between a WPF application and a Windows Forms application.

  • Layout: WPF gives us great flexibility in organizing our visual elements. It has smart mechanics behind the scenes that automatically and dynamically find a place for each element without having to manually update the layout. For example:
    • Like a custom type in a TextBox, its width can increase and push other elements, or it can insert some elements in a new line (for example, the menu bar you observed)
    • As the size of the control changes, it affects the available space for other elements, so their size and location may change accordingly.
    • When you resize the window or change the resolution, it immediately updates the layout and resizes the elements to fill or place the space. (Don't expect the button to be doubled in size if you halve the resolution. That doesn't work. Basically, it measures each element first and then arranges them).

Here you will learn more about layouts.

  1. Rendering: Try a grid of 30x30 text fields in a Windows Forms application and a WPF application. No matter how messy you write WPF, it is still much faster than Windows Forms, and it won’t flash for a second if you write it correctly. Imagine a few animations, effects, triggers and a hierarchy of styles on them, still much faster than Windows Forms.

    • It also uses the double type for Sizings, and therefore you can sometimes see blurred edges, but it can be avoided (SnapToDevicePixels). Note. To avoid slowing down and blinking in a Windows Forms application, you must set the DoubleBuffer of the form to true.
  2. Last and most important: Focus on presentation: It may seem a little strange, but when you choose WPF, you should stop thinking in Windows Forms (numerous events and controls with names and a lot of code behind) and start thinking in WPF (binding, commands , resources, styles, templates, converters, DependencyProperties and their callbacks).

    • The real power of WPF lies in the separation of "View" and "Logic", once you hang it, there is no limit to how you can present "View".
    • Moreover, the MVVM pattern makes the most visually sophisticated applications fairly simple and easy to develop.

If you plan to switch to WPF, you have made the right decision. Always stick to the plan! , i.e. Avoid coding behind (coding in .xaml.cs files), XAML names (unless they are only used in XAML), and user interface events as much as possible. Use WPF features instead.

+14
source share

Windows Forms (WinForms) and Windows Presentation Foundation (WPF) are two different ways to create a user interface for your application. Windows Forms is an older technology and its controls are in the System.Windows.Forms namespace . WPF is a newer technology and its controls are located in the System.Windows.Controls .

WPF

Pros:

  • Powerful style and skinning structure.
  • Easy to create your own look.
  • Does Windows Forms Support
  • Future technology for developing Windows Vista applications.
  • Ability to reuse existing code
  • Extended data transfer possible

Minuses:

  • Declarative or procedural code
  • Requires .NET Framework 3.0
  • Compared to Windows Forms, still under development
  • Requires a Dx9 compatible graphics card for advanced graphics.

Windows forms

Pros:

  • Extensive online documentation
  • Many examples
  • Does WPF support

Minuses:

  • How long will this be maintained? (I read somewhere that Microsoft is only now developing WPF, for Windows Forms only).
  • Create your own look in the app - it's a lot of work.
+5
source share

All Articles