How to make a Style that only exists within the context of a ResourceDictionary

前端 未结 1 1114
终归单人心
终归单人心 2021-01-13 11:47

How can I create a style that only exists within the context of a ResourceDictionary, but not in the context of controls that include that ResourceDictionary?

For in

1条回答
  •  耶瑟儿~
    2021-01-13 12:27

    One way to get quite close to what you are looking for is to move the "private" styles from ControlTemplates.xaml into their own ResourceDictionary, and then reference that resource dictionary from within the control templates in ControlTemplates.xaml:

    ControlTemplates.xaml:

    
    
        
        
            
                
            
    
            
        
    
    
    

    ControlTemplatePrivateStyles.xaml:

    
    
        
    
    
    

    Then the xaml for the window would look like this:

    
    
        
            
        
    
        
            
            
    
            
            
        
    
    

    This way you could not use the "private" styles unless you explicitly reference that resource dictionary. They will not be accessible by just referncing the ControlTemplates.xaml resource dictionary.

    0 讨论(0)
提交回复
热议问题