Accessing a resource via codebehind in WPF

后端 未结 6 814
刺人心
刺人心 2020-12-01 07:06

I have a custom collection defined in my window resources as follows (in a Sketchflow app so the window is actually a UserControl):



        
6条回答
  •  天涯浪人
    2020-12-01 07:40

    You should use System.Windows.Controls.UserControl's FindResource() or TryFindResource() methods.

    Also, a good practice is to create a string constant which maps the name of your key in the resource dictionary (so that you can change it at only one place).

提交回复
热议问题