MVVM: how to open a lookup window

This forum is meant for questions and discussions about the X# language and tools
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

MVVM: how to open a lookup window

Post by wriedmann »

Hi Phil,

thank you very much for taking the time to build your samples.

MVVM or MVMV how do you call it seems to me to be the right structure for clean data applications. Where I have my doubts is how to interconnect the windows together. In VO, I have my Shell and its children, sometimes also modal selection dialogs.

In X#, my Shell will be replaced by another structure: the child windows will be replaced by tab pages:
mvvmapp.png
mvvmapp.png (10.02 KiB) Viewed 564 times
What is already working is the load of single modules at runtime - I plan to have an empty shell and load the functionality based on settings.

I hope to finish this structure as early as possible and publish it for everyone that needs such a structure and is not happy with large and complex kits like Prism and prefers a smaller solution that is understandable.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

MVVM: how to open a lookup window

Post by NickFriend »

Hi Wolfgang,

I'm going to be a bit busy today, so this evening I'll sit down and post a response with a bit more detail.

But in short, the idea is that all the opening/closing of View/ViewModels is managed by the central message processor. This is the first thing you start up in app.xaml.cs, it starts the shell window, and is responsible for opening/closing windows (or usercontrols or whatever, each one representing a View/ViewModel pair).

Moving data (such as the selected customer id from your lookup) and other notifications, can be direct from one VM to another, but again by messaging, not by direct reference. The trick is that each VM must have a unique identifier (a Guid) so that the correct target for data can be found.

1. VM sends a message saying "I want to select a customer, and here's my VM Id XXX".
2. Central processor gets the message, opens a View/ViewModel of your lookup classes.
3. User selects a customer, lookup VM sends a message saying "customer selected, VM Id XXX asked for it".
4. Original VM is looking out for messages with it's Id, gets the message and extracts the data.

I'll explain better later on, but this sort of scheme leaves a totally decoupled system. You can update your lookup implementation without worrying about VMs that call it for example.

Nick
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

MVVM: how to open a lookup window

Post by wriedmann »

Hi Nick,

thank you very much! With this answer I'll be able to go further, I hope.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

MVVM: how to open a lookup window

Post by Phil Hepburn »

Hi Wolfgang,

I see that Nick will help you with the 'inversion of control' so you can de-couple each and every View (and supporting ViewModel), from the others. This is great and the modern way to do things - Nick has been doing it successfully for years.

However, please remember that any business related data ought to be help in 'Model' classes and not in the VM properties. And remember that the Model object(s) can still be scoped such that they are available to be used as input objects when VMs are instantiated by the Controller system.  

Nick got me (and others) to keep the VM code as clean and as simple as possible, just enough to service the View. And it works, works well, and I like it that way ;-0)

If there is one reason I need to criticise myself (and I am sure there are many!) is for NOT making more of the data 'Model' object as a data provider to support my VM to support my Views. I am working on improving this side of my application design and coding.

All the BEST,
Phil.
Oh! - and Good Luck too.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

MVVM: how to open a lookup window

Post by Phil Hepburn »

Hi Wolfgang,

Although I encourage you to follow Nick's advice on inversion of control and how Views are opened, you said you had little time, and had to deliver something to your customer.

I suggest that moving over to this new design structure may not be a good idea if you are 'up against it' time-wise ;-0) Take CARE !!!

If it is done correctly, then the new control system should affect all of your code, and that means each and every View/VM.

Ask Nick if he thinks it is possible for you to make these changes and also deliver - without losing your Christmas break ;-0)

Good Luck,
Phil.
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

MVVM: how to open a lookup window

Post by wriedmann »

Hi Phil,

I don't think I'll save any time doing things wrongly unfortunately (or fortunately - it depends on the view....)

Therefore I have not the time to try things, but I need the time to do the correct things.

Thank you very much for your wishes!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

MVVM: how to open a lookup window

Post by Frank Maraite »

Hi Wolfgang,

look into the session material I provided in cologne.
You should find a sample on how to transform an application from old to new way. And it is a XIDE sample.

Frank
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

MVVM: how to open a lookup window

Post by wriedmann »

Hi Frank,

I'll look a it.

Thank you!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

MVVM: how to open a lookup window

Post by NickFriend »

Hi Wolfgang,

Ok, things have quietened down a bit now.... were you able to make any useful sense of what I wrote hurriedly this morning, or can I clarify anything in particular now?

Nick
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

MVVM: how to open a lookup window

Post by wriedmann »

Hi Nick,

your message was clear to me.... Only a small question: how do you open a window from a ViewModel? The ViewModel of a View normally is assigned in the constructor of the view.

Wolfgang

P.S. I have no codebehind as I have no XAML - my windows are all built by code using enhanced classes.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply