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