How to extend instead of overriding WPF Styles

后端 未结 2 1382
长发绾君心
长发绾君心 2020-12-28 13:26

I want to use custom theme in my application and as far as I know I can accomplish this by using resource dictionary and referencing it in App.xaml. Styles would override th

2条回答
  •  旧时难觅i
    2020-12-28 14:11

    Wpf has different levels of styles, that are applied in order of global > local. A style set directly on a control will override a style set globally, like in your example. I was trying to find a list of all the different places that a control looks for its styles but I cannot find one at the moment. As far as I know, you will have to use the BasedOn property to inherit a style and not completely override the properties of that style with the style you set locally.

    Here is an example of a resource dictionary that has styles based on another style, so that you don't have do repeat the BasedOn binding over and over, you can just set the style on the specific element you want to have that style.

    
      
        
          
          
        
      
      
        
        
    
    

提交回复
热议问题