DataTemplate in Resource sets ViewModel to View, but then

前端 未结 3 1821
暖寄归人
暖寄归人 2021-01-06 04:53

I am trying to figure the many different ways of setting datacontext of a view to a viewmodel.

One I\'m oggling at this moment goes something like this:

I ha

3条回答
  •  有刺的猬
    2021-01-06 05:12

    Maybe this doesn't directly answer your question, but have you looked at using an MVVM framework? For example, in Caliburn.Micro you would do (very basic example):

    public class ShellViewModel : Conductor
    {
      public ShellViewModel()
      {
        var myViewModel = new MyViewModel();
        this.ActivateItem(myViewModel);
      }
    }
    

    ShellView.xaml

    
      
    
    

    MyView.xaml

    
      Hello world
    
    

    This is a viewmodel first approach.

提交回复
热议问题