Home > Net >  About the WPF MVVM viewmodel multiple calls
About the WPF MVVM viewmodel multiple calls

Time:09-18

If the project has three pages, page a, b, c, each page has its own vm, if want to be in a page embedded c, b page embedded c, c page using the singleton pattern to load the vm, c page viewmodel set a name value is 1, if be in, a page to change the name value of 2, so back to page b also found for the 2 name value, I want to now is that the effect of c page corresponding to a viewmodel, how to let the vm each other, I now the question is, if a page c instantiate a vm, b instantiate a vm in a web page also can realize each other, but I registered in the vm c page message Messenger. The Default. The Register will be registered twice, so when I trigger message, the message will be executed twice, what solutions can be perfect to solve this problem

CodePudding user response:

Don't use singleton viewmodel, a viewmodel of c of c and b is not the same, the same as your c of c and b is the same, the viewmodel c every time new once again

CodePudding user response:

reference 1/f, kill matt, bull response:
don't use singleton viewmodel, a c of c and b in the viewmodel can't is the same, the same as your c of c and b is the same, the viewmodel c again every time a new
then I registered in c will register twice, that is, a command performs the message twice in the c

CodePudding user response:

refer to the second floor spy0505 response:
Quote: refer to kill 1/f, matt, bull response:

Don't use singleton viewmodel, a c of c and b in the viewmodel can't is the same, the same as your c of c and b is the same, the viewmodel c again every time a new
then I registered in c will register twice, that is, a command message twice in the c

In a c of c and b are not the same object, how is it possible to register twice? Is not the same object, how to register up to two events? C objects you can't use singleton, also want to new, respectively

CodePudding user response:

reference 3 floor killed matt, bull response:
Quote: refer to the second floor spy0505 response:

Quote: refer to kill 1/f, matt, bull response:

Don't use singleton viewmodel, a c of c and b in the viewmodel can't is the same, the same as your c of c and b is the same, the viewmodel c again every time a new
then I registered in c will register twice, that is, a command message twice in the c

In a c of c and b are not the same object, how is it possible to register twice? Is not the same object, how to register up to two events? C objects you can't use singleton, also separately new

I am a registered message in this way, to realize the interaction between the viewmodel, Messenger. Default. The Register, this way is a kind of global registration, although new two trigger this message, would trigger twice, is my registration way wrong

CodePudding user response:

Messenger. The Default. See the Register parameters or where configurable, registered out this method is single case?
  •  Tags:  
  • C #
  • Related