Caliburn.Micro : How to bind a specific Item of Conductor.Collection.AllActive to a ContentControl

前端 未结 3 985
轻奢々
轻奢々 2021-01-21 16:46

My goal is to have 4 different active ViewModels displayed in a grid on the ShellView. The issue is that I have not been able to figure out how to wire up a ContentControl to a

3条回答
  •  不要未来只要你来
    2021-01-21 17:02

    You need to create properties in your ShellViewModel something like UC1, UC2, UC3 etc. You then need to change your ShellView to bind to UC1 property.

                
                ...
    

    Caliburn Micro should do the plumbing for you.

    namespace ContentControlTest.ViewModels
    {
        public class ShellViewModel : Conductor.Collection.AllActive
        {
            // Modify to implement INotifyPropertyChanged event...
            public UC1ViewModel UC1 { get; set }
    
            public ShellViewModel()
            {
                UC1 = new UC1ViewModel();
                ActivateItem(UC1);
                ActivateItem(new UC2ViewModel());
                ActivateItem(new UC3ViewModel());
                ActivateItem(new UC4ViewModel());
            }
        }
    }
    
        

    提交回复
    热议问题