Skinning: Using a Color as StaticResource for another Color

后端 未结 4 2006
遇见更好的自我
遇见更好的自我 2020-12-03 00:17

I implemented skinning in my application. The application loads its Brushes.xaml resource dictionary which uses colors which reside in a skin-specific resource dictionary. S

4条回答
  •  萌比男神i
    2020-12-03 00:57

    H.B.'s answer is very interesting and I have played around with it quite a bit since I want to do exactly what this question is asking to do.

    What I've noticed is that using a DynamicResource doesn't work for WPF 3.5. That is, it throws an exception at run time (the one Amenti talks about). However, if you make colors that are referencing the color you want to share ... a StaticResource, it works on both WPF 3.5 and WPF 4.0.

    That is, this xaml works for both WPF 3.5 and WPF 4.0:

    
        
            DarkBlue
            
            
        
        
            
                
            
        
    
    

    Another thing that bears mentioning (again) is that this approach wreaks havoc with the designers out there (i.e the Visual Studio 2008 and 2010 designers, the Blend 3 and 4 designers). I speculate that this is the same reason why Kaxaml 1.7 wasn't liking H.B.'s xaml (if you're following the comment stream on H.B.'s answer).

    But while it breaks the designers for a simple test case, it doesn't seem to break the design surface for the large scale application I work on in my day job. Plain weird! In other words, if you care about things still working in the designer, try this method out anyway ... your designer may still work!

提交回复
热议问题