How can I access ResourceDictionary in wpf from C# code?

后端 未结 9 1575
[愿得一人]
[愿得一人] 2020-11-30 03:04

I have a DataTemplate defined in a xaml file that I want to access via C# code. Can anyone please tell me how can I access it? I added a new ResourceDicti

9条回答
  •  温柔的废话
    2020-11-30 03:38

    For the life of me, although I was able to load my resource dictionary via XAML, I wasn't able to load it via "code behind" (in C#).

    So I resorted to have a view loading it: (MyView.xaml)

      
        
          
            
          
        
      
    

    Then access it in my UT by instanciating that view and accessing it:

    new MyView().Resources.MergedDictionaries[0]

    Hacky, but works.

提交回复
热议问题