Warm tip: This article is reproduced from stackoverflow.com, please click
.net c# silverlight wpf

How to access resource file's value in code behind

发布于 2020-05-14 13:18:38

In the xml I am able to access resource file's value by providing the corresponding key. First I have added the namespace as following

xmlns:res="clr-namespace:WpfApplication3.Properties"

And then bind the Text using following way

Text="{x:Static res:Resources.city}"

But in my same application I have to use it in code behind. What should I do it to access my resource file?

When I count the key of my resource file I found it 0 that does not make any sense as I have many keys in my resource file.

Questioner
Sunil Singh
Viewed
27
Adrian Fâciu 2013-02-19 23:49

This should be as simple as:

var cityName = Properties.Resources.city;