MVVM (with WPF) - Binding Multiple Views to the Same ViewModel

前端 未结 4 1978
旧巷少年郎
旧巷少年郎 2020-12-24 14:54

I have recently started investigating the MVVM pattern with WPF for an upcoming project. I started with Josh Smith\'s MSDN article. I have a question (well many, but let\'s

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 15:38

    So you need 2 different views based on a property value. One thing to consider is to refactor your presentation code, so instead of the values of a property you could have real subclasses. Then you can use 2 different DataTemplate for each class.

    
      
    
    
    
      
    
    

    If you think that is an overkill, you could use a trigger and wrap your specific views into a ContentPresenter.

    
      
    
    
    
      
    
    
    
      
        
          
        
      
    
    

提交回复
热议问题