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

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

    I found the answer here

    https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/how-to-use-a-resourcedictionary-to-manage-localizable-string-resources

    • create a ressource dictionary "ColorResources.xaml"
    • add to it: Blue

    • edit your app.xml and add:

    • use the color from your code

      var color = (System.Windows.Media.Color)Application.Current.FindResource("ButtonColor1");

    and voilà

    ps : admin can you fix the code? it does not show up, thanks

提交回复
热议问题