Question in title pretty much sums it up. I have some resource object defined in XAML and I’d like to access it in code behind also. So is there a way to define x:Key for it at one place instead of hard coding x:Key (as string) in both XAML and code behind?
Share
If you want to not have to code up the string twice you can store it as a static variable, here I’ve put it in App.cs
When you want to use this key in a resource for your app you can do so like this.
And in C# you no longer need to use the exact string name because it’s in App
To use the resource in XAML you use