Home > Net >  Communication between the WPF MVVM pattern viewmodel
Communication between the WPF MVVM pattern viewmodel

Time:09-30


Do not use the Prism event aggregator framework, how to realize the communication between the ViewModel

CodePudding user response:

In your program design, what is the relationship between them?

CodePudding user response:

I may say don't quite understand, programming: click on the button, the view1 view2 the background color of the change!
The view1 binding viewmodel1 the button in the Press command, how to Press commissioned tell View2 command

CodePudding user response:

Use the singleton pattern in ViewModel1, 2, direct call in ViewMode1 ViewModel2 set colors method,

CodePudding user response:

CodePudding user response:

Public MainWindow ()
{
InitializeComponent ();

Enclosing DataContext=new V2 ();
//uninstall the current object (this) registered all MVVMLight news
Enclosing Unloaded +=(sender, e)=& gt; Messenger. The Default. The Unregister (this);
}
Another page of the click event
Private void Select_Color (object sender, MouseButtonEventArgs e)
{
Border Border=(Border) sender;
Var source=(V1) DataContext;
Source. SendInfo=border. Background. The ToString ();
Source. ExcuteSendCommand ();
}

CodePudding user response:

If you don't use Messenger, then instantiate the View1 in MainView and View2

Then the View1 click event trigger in the Main, and then you can directly set View2 background;
  •  Tags:  
  • C#
  • Related