WPF Caliburn.Micro/mvvm Navigation

前端 未结 2 1130
感动是毒
感动是毒 2021-02-09 05:39

I\'m building a project, and one of the biggest problems I\'ve come across until now is navigation.
I\'ve been looking for some time now for examples of caliburn.micro/mvvm

2条回答
  •  生来不讨喜
    2021-02-09 06:37

    In ShellView you use a content control like this:

    
         
               

    ShellViewModel:

    public class ShellViewModel : Screen
    {
         private object Child;
    
         public object Child
         {
               get{ return child; }
               set
               {
                    if(child == value)
                         return;
                    child = value;
                    NotifyOfPropertyChange(() => Child);
               }
         }
    
         public ShellViewModel()
         {
             this.Child = new MainViewModel();
         }
    
         public void ShowOtherView()
         {
               this.Child = new FooViewModel();
         }
    }
    

    So this is a very basic example. But as you see, your ShellView provides a ContentControl, which shows the child view. This ContentControl is bound via View.Model to the Child property from your ShellViewModel.

    In ShellView, I used a button to show a different view, but you can also use a menu or something like that.

提交回复
热议问题