How to define and use resources in xaml so they can be used in C#

前端 未结 4 1837
时光取名叫无心
时光取名叫无心 2020-12-16 12:35

Theoretically, I think that I can define Brushes and Colors etc. in an xaml file and assign that to a button.background in c#. But how do I do that? Where do I put my linear

4条回答
  •  时光取名叫无心
    2020-12-16 13:05

    Put them in the Resources collection of one of your elements in XAML:

    
        
            
                
                
            
            
        
        
    
    

    Then get them in code by using FindResource

    var blaBrush = this.FindResource("BlaBrush") as LinearGradientBrush;
    

    See Resources Overview for more information.

提交回复
热议问题