Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

MVVM: How to pass data between ViewModels

$
0
0

I'm a relative newbie to WPM MVVM, and I'm rewriting a Winform app to WPF. The original design is a window containing only a single tab control. Each tab in-turn hosts various controls and functions as a separate "form" (input data, click button, view results).  The business functions of each tab are only loosely related to the other tabs.

Unfortunately, the code for ALL the tabs is presently "glommed together" (like spaghetti) in a single C# source file. But after analysing it, I found there's not really very much code that's actually actually shared between the various tabs.  

So I decided to segregate each "form" into separate Views (UserControls) each with an associated ViewModel. The new design will be a main View containing only the tab control (and its associated main iewModel)  plus a View (a UserControl) and associated ViewModel for each tab. 

But I'm stuck on what would seem to be a simple thing: I need to pass a startup argument "down" the hierarchy from the "main" ViewModel to the "lower-level" ViewModel(s)

How do I do this in an MVVM-friendly way?  And more generally, how does one share "data" (and perhaps methods?) between ViewModels?

(examples would be most welcome, since I'm sort of a noob).

DadCat


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>