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

后端 未结 9 1573
[愿得一人]
[愿得一人] 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:24

    Any of the above approaches work getting the resource based on the location, if you are following MVVMm I would recommend doing it this way:

    1. create a Service like ProvideDataTemplateService, (to create a service usual inherit from Behavior )
    2. Use Container of Your choice to inject this service where you would like to have aces to DataTemple.

提交回复
热议问题