c# - MVVM Pattern, ViewModel DataContext question -


I need to understand how to interact between ViewModels. I'm new on MVVM so please be kind.

Here is an example

Definitions of class (say I have given birth to child. Event by changing property in parentViewModel):

  public Class Guardian Model: See Modelsbase {Receive {Child Balance Model Child}; Set; }} Public class childview model: see modellbase {string _FirstName; Public string firstname {back {back _FirstName; } Set {_FirstName = value; OnPropertyChanged ("First"); }}}  

In the Resource dictionary you will see

  & gt; DataTemplate DataType = "{x: Type VM: ParenViewModel}" & gt; & Lt; VW: ParentView / & gt; & Lt; / DataTemplate & gt; & Lt; DataTemplate DataType = "{x: Type VM: ChildView Model}" & gt; & Lt; VW: ChildView / & gt; & Lt; / DataTemplate & gt;  

and the code-behind ChildView:

  public partial square Child Scene: UserControl {public QueueView () {InitializeComponent (); Datacontex = new child marriage model (); }}  

The obvious problem is that when ChildView gets instant (via selection from DataTemplate), it creates a new ChildViewModel class and ParentViewModel does not have access to it.

How can I install Datatente to see the original view model, due to which Datamat template was to be selected?

An obvious improvement in the childhood model is Mishra in the parent model, but I want to separate it because for reuse,

I'm sure the answer is trivial, I just want to know what it is. thank you in advanced.

You just need to draw a line:

/ P>

  Datacentext = New Child Marriage Model ();   

The view will be set by the DataContext automatically data templates is always the data data set on the data for the template (this See case modell):

   

The end result is that you can make your visual model objects separately (both parents and child class) and then simply plugging them into content controls to display them later You can.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -