简体   繁体   中英

MVVM light multiple instances of usercontrol

How can I get multiple instances of a usercontrol without the viewmodel being shared? Each usercontrol (and thus viewmodel) should be an instance of its own.

I have read a solution in this question: MVVMLight UserControl View Model-Create new Instance of User control for each view but I cannot get it to work!

I have a listview and a tabcontrol. When I click an item of the listview a new tab must be created with as content the usercontrol which holds information from the selected listitem. The problem is that when selecting multiple items all the items contain the information from the last selected item.

This is my viewmodellocator:

        public DossierDetailViewModel DossierDetail
    {
        get
        {
            return new DossierDetailViewModel();
        }
    }

And I call the new usercontrol like this:

        DossierDetailViewModel newDossier = new DossierDetailViewModel();
        newDossier.TabName = SelectedDossier.Omschrijving;
        this.OpenDossiers.Add(newDossier);
        Messenger.Default.Send<DTO.Dossier.Dossier>(SelectedDossier, "SetDossier");

EDIT: Is there no one who can help me or put me in the right direction? :(

这个问题的答案可以在这里找到: https : //mvvmlight.codeplex.com/discussions/577555

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM