Equivalent of CSS in XAML

前端 未结 2 1082
北恋
北恋 2021-02-08 01:52

In web development, styles sheets are very commonly used. In Swing there are layout managers for handling of the GUI. Am I correct in the assumption that XAML applies one of tho

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-08 02:33

    What you're looking for is ResourceDictionary. This is much more flexible than just putting styles in your App.Resources Element and gives you much more control of the scope of your styles.

    Putting Styles in your App.Resources has a number of disadvantages:

    • It can fill up really quickly and turn into a large, bloated list
    • Every style there is globally available. You may not want that.

    Using A ResourceDictionary largely fixes this:

    • Styles can be kept in one or more assemblies and be re-used across appplications
    • By including resourcedictionaries (or not) you can control what styles are added to a page
    • You can group and organise your styles and templates in a way that is logical to you

    A resource dictionary maps pretty closely to a CSS file. Basically, you use these to store a mix of things:

    • Styles
    • ControlTemplates and DataTemplates
    • Brushes, etc

    And, like stylesheets you can apply them across entire control types or to controls that use the named style

    
            
                
                    
                    
                    
                    
                
            
    
    

    Definining a ResourceDictionary:

        
    
            
                
                
                
                
            
        
    

提交回复
热议问题