Reference custom resource defined in another xaml file

前端 未结 2 869
后悔当初
后悔当初 2020-12-28 08:42

I am trying to create a new resource in one xaml file and reference it in another xaml file. i.e I define


    

        
2条回答
  •  眼角桃花
    2020-12-28 09:21

    In WPF, the resource references works as a tree. Each control have resource, and children control can access parent's resources. The global application resource dictionary is in the App.xaml file. In this file you can include several resource dictionaries as a Merged Dictionary. See this code sample:

    
    
        
            
                
                
                    
                
            
        
    
    

    The SomeFileDictionary.xaml is located in the View folder of my project structure. And has looks like this:

    
    
    
        
    ...
    

    And each dictionary key or data template defined in this file (or App.xaml), can be referenced in any place of your project. Hope this helps...

提交回复
热议问题