views:

59

answers:

2

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.

+3  A: 

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

<TextBlock Text="{x:Static Messages.WarningUserMessage}" />
Julien Lebosquain
Im new to WPF and this answer is just what i needed! Thank you.
nihi_l_ist
+2  A: 

The simplest way is probably to reference the items directly (they are static properties, internal by default):

<TextBlock x:Name="txtMessage" Text="{x:Static MyApp.Properties.Resource.TextString}"/>

If you are working on a localised WPF app though then I'd recommend taking a look at the guidance on CodePlex at http://wpflocalization.codeplex.com/ , and if you're building a composite app (using PRISM or MEF) then I have a blog post on a nice way to accomplish WPF localisation using standard bindings.

Steven Robbins