Creating a new instance of an object each time method is called

后端 未结 3 714
野趣味
野趣味 2021-01-06 05:41
Messenger.Default.Register(this, message =>
{
    var adventurerWindowVM = SimpleIoc.Default.GetInstance();
           


        
3条回答
  •  醉梦人生
    2021-01-06 06:07

    I think you are trying to use the same instance of your ViewModel with multiple views. So the views will obviously overwrite each others viewmodel contents.

    What if you do this;

            Messenger.Default.Register(this, message =>
        {
            var adventurerWindowVM = new AdventurerViewModel();
            adventurerWindowVM.Adv = message.Argument;
            var adventurerWindow = new AdventurerView() 
            {
                DataContext = adventurerWindowVM
            };
            adventurerWindow.Show();
        });
    

提交回复
热议问题