MVVM: how couple View and ViewModel together and open a view from a ViewModel

Public forum to share code snippets, screen shorts, experiences, etc.
Post Reply
User avatar
wriedmann
Posts: 3655
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

MVVM: how couple View and ViewModel together and open a view from a ViewModel

Post by wriedmann »

Based on what Nick Friend wrote about the coupling of View and ViewModel, I have tried to build a ViewFactory class.

It is very simple to use:

Initialize the coupling one:

Code: Select all

ViewFactory.AddCouple( TypeOf( ViewModel2 ), TypeOf( View2 ) )
and then open it from the ViewModel:

Code: Select all

ViewFactory.CreateView( typeOf( ViewModel2 ) )


Please find attached the complete sample as XIDE export file.

As I wrote before, my work is a work in progress and far from being finished - I only try to write understandable and working code, so you will not find any dependency on some MVVM frameworks.

Of course, I'm always open to suggestions or corrections.

Wolfgang
Attachments
MVVMEnhancedAppv3.zip
(8.78 KiB) Downloaded 20 times
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply