WPF: switching UserControls depending on corresponding ViewModels (MVVM)

前端 未结 2 1725
终归单人心
终归单人心 2021-02-01 06:22

I\'ll try to simplify the task I\'m working on by imagining this example:

Let\'s suppose that we have the following hierarchy of model classes:

Animal
           


        
2条回答
  •  囚心锁ツ
    2021-02-01 06:31

    Is it possible to deduce the necessary user control based on a ViewModel type?

    You mean, like this?

    
       
          
       
       
          
       
       
          
       
    
    

    See "Applying a View to a View Model" in Josh Smith's article on MVVM.

    Edit:

    Here's a trivial example of type-based template selection that you can paste into Kaxaml to prove to yourself that it really works:

    
      
        this is a string
        1234
        
          
        
        
          
        
      
        
        
        
      
    
    

提交回复
热议问题