Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get values from *.resx files in XAML

Is it possible to add some value from resource file right into the XAML markup? Or for localization we always have to make something like this in *.cs file:

txtMessage.Text = Messages.WarningUserMessage; 

Where Messages is resource, and txtMessage is TextBlock.

like image 854
0x49D1 Avatar asked May 27 '10 07:05

0x49D1


People also ask

How do I access resource files in XAML?

Right Click the Project select Add New Item -> General -> Resource File.

What is a .resx file and how do you use it?

The . resx resource file format consists of XML entries that specify objects and strings inside XML tags. One advantage of a . resx file is that when opened with a text editor (such as Notepad) it can be written to, parsed, and manipulated.

What is a .resx file?

Net Resource (. resx) files are a monolingual file format used in Microsoft . Net Applications. The . resx resource file format consists of XML entries, which specify objects and strings inside XML tags.


1 Answers

Make sure that Code Generation is set to Public in the resx editor, then you can simply use:

<TextBlock Text="{x:Static Messages.WarningUserMessage}" /> 
like image 141
Julien Lebosquain Avatar answered Sep 23 '22 06:09

Julien Lebosquain