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.

Showcase Your Apps on DevExpress.com

Highlight your business app and share your development experiences with the DevExpress community. To include your app in our upcoming App Showcase, please forward an application screenshot to clientservices@devexpress.com and tell us which DevExpress products you currently use within your organization.
6 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
Dmitri Peredera
Dmitri Peredera
Hello,

I am happy that you are working on the framework because there are
currently none for WinForms. And actually there is no for WPF as well (except yours :P )

And please, examples, examples, examples.

I think that one can assume that by the time of .net 5 there will be a DI in the project,
but there is no need to focus on DI frameworks that doesn't have WinForms section in their docs.

Also, please make docs and show how to write unit tests for the framework like: when user presses
this button, show dialog and i want to mock the dialog results. I had some fun time with that in WPF.

Navigation is always a hard topic. Like if there are no items in the list, show control with
description instead of disabled details control.

Another good example could be ribbon.

27 May 2020
Dmitry (DevExpress)
Dmitry (DevExpress)

@Dmitri Peredera

That sounds great, thank you :) Yes, examples are extremely important, and that's exactly why we've added the tutorial module. Unit testing seems a bit too specific, but stunt controls with descriptions instead of empty data-bound controls can be a great candidate for the "Best Practices" demo. Do you have other common use cases in mind that deserve new demo modules?

27 May 2020

Please login or register to post comments.