WinForms - MVVM Enhancements (v20.1)

WinForms Team Blog
30 April 2020

In recent months, we've noticed a spike in customer questions regarding our WinForms MVVM Framework. This increase in demand could not come at a better time as we’ve been hard at work updating demos and documentation. First things first though – I want to mention WinForms MVVM Framework-related changes we expect to ship in v20.1.

New Services

MVVM pattern suggests that you keep data management code separated from the UI - inside ViewModels that are independent from Views. This recommendation means that if you need to open a View as a tab, or close a currently open dialog, or do anything else on a View layer - the ViewModel code that executes these actions should be kept independent from a View. In other words, the "open a new tab" command should not refer to a View control instance. Instead, the application should be able to automatically locate an appropriate UI element that fits the action (for instance, a Document Manager component that displays tabs).

DevExpress MVVM Framework allows you to implement this logic with the help of Services. All you need to do is register the appropriate Service, and call its public methods in a ViewModel. The Framework will automatically find an appropriate View control and "translate" Service methods into specific control commands.

With v20.1, we've extended our existing Service collection with three additional Services:

  • WindowService - allows you to open Views as separate XtraForms, RibbonForms or Flyouts.
  • CurrentWindowService - allows you to manage windows (forms) from the ViewModel layer. The Service provides methods to change the form's window state or close any active window.
  • CurrentDialogService - use this Service to manage open dialogs. Allows you to close a dialog with a specific DialogResult.

To learn more about our WinForms MVVM Services, please refer to the following help topic: Services.

New Tutorial Demo Module

We understand that MVVM can be challenging for those unfamiliar with its underlying concepts. To simplify the learning curve, we've added a "Simple ToDo Application" module to our "MVVM Best Practices" demo. This module uses a sample app to demonstrate basic MVVM concepts, such as data binding and ViewModel communications. The "Walkthrough" demo breaks the process down into "bite-sized" steps. Each step is supplied with a description and related code, so you can easily track how empty forms turn into Views, data management code becomes ViewModel classes, and separate layers communicate with one another.

You can also download both C# and Visual Basic versions of this sample app from the Simple TODO Application repository on GitHub.

Documentation Enhancements

In addition to the new walkthrough demo module, we've begun to update our other learning resource. Previous versions focused on a thorough description of what's possible. With v20.1, we’ve shifted focus to clarity and brevity. Our Data Bindings help section now outlines the difference between "regular" and "data" bindings, and demonstrates the best way to implement both. Each binding technique is followed by a demo example. We’ve also overhauled our API Samples section to fit this new pattern.

"Data Bindings" is the first completely reworked section. We expect to update other sections as time allows.

As we work to perfect things, we’d love to get feedback from those currently using MVVM or considering it in a future WinForms project. Let us know if the changes outlined above are of value to your business.

What’s New in v20.1

To explore the scope, breadth and capabilities of our new products/features, please visit: https://www.devexpress.com/Subscriptions/New-2020-1.xml.
4 comment(s)
Martin Pelletier
Martin Pelletier
Any MVVM enhancements in the WPF area?
30 April 2020
PETE N
PETE N
Yes, I would like to echo Martin's question on MVVM enhancements for WPF?
3 May 2020
Dalibor Stys
Dalibor Stys
I also thought that new templates (like DI + MVVM) should come to WPF. WinForms has tons of templates, but WPF in 20.1.3 still only 5.
3 May 2020
Alex Chuev (DevExpress)
Alex Chuev (DevExpress)

@Martin, Pete, and Dalibor:


Services described in this post are already available in WPF:
WindowService
CurrentWindowService
CurrentDialogService
You can find a complete list of WPF services in this help topic: Services - Predefined Set. In v20.1, we added SplashScreenManagerService that controls a new set of splash screens and wait indicators.


To see WPF services and other MVVM features in action, open the MVVM Framework category in our Demo Center (the link requires installation of WPF Subscription v20.1).

If you have any suggestions on new MVVM features, project templates, or documentation enhancements, feel free to post them here or contact me at wpfteam@devexpress.com.

Thanks,

Alex

6 May 2020

Please login or register to post comments.