ContentTemplateSelector is only called one time showing always the same datatemplate

前端 未结 3 1359
予麋鹿
予麋鹿 2021-01-02 09:32

I have made a sample demo VS 2010 RC sample project, because in my production project I have the same error using MVVM.

In my sample demo project I use only Code-beh

3条回答
  •  臣服心动
    2021-01-02 10:06

    Note: I think this method is quite clumsy, but could work for some scenarios. I favor the method of using a trigger (from Neil) that I posted as a separate answer.


    Another possible way is to bind the Content of the ContentTemplateSelector to the property that determines the template that should be selected. For instance here I have two different toolbars chosen based upon the value of SourceSystem. I set the Content to be the sourcesystem property itself.

    
    

    The template selector simply looks at the source system and returns the necessary template.

    If the template needs access to the datacontext of the control, just use element binding to set it.

     
        
            
        
        
            
        
     
    

提交回复
热议问题