how to load wpf usercontrol in MVVM pattern

前端 未结 6 1731
刺人心
刺人心 2021-02-06 12:36

I\'m creating a wpf user control which is in mvvm pattern. So we have : view(with no code in codebehind file), viewmodel,model,dataaccess files.

I have MainWindo

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 13:09

    You can use a ContentControl, with a DataTemplate to bind the UserControl (View) to the ViewModel :

    
        
    
    
    ...
    
    
    

    WPF will pick the DataTemplate automatically based on the type of the Content

提交回复
热议问题