pw94
pw94

Reputation: 401

Localizing the App

I'm creating simple Windows Phone 8 app. I've made in C# MessagePrompt object using Coding4Fun.

MessagePrompt mes = new MessagePrompt();
mes.IsCancelVisible = false;
mes.Body = new TextBlock
{
    Foreground = new SolidColorBrush(Colors.Red),
    Text = "MY TEXT!!!!!!!!!",
    FontSize = 30.0,
    TextAlignment = TextAlignment.Center,
    TextWrapping = TextWrapping.Wrap
};
mes.Show();

I want text in Body of MessagePrompt be binded from AppResources.resx. I found how to do localizing in XAML:

Text = {Binding Path=LocalizedResources.Message, Source={StaticResource LocalizedStrings}}

but I have no idea how to use it in C#.

Upvotes: 0

Views: 66

Answers (1)

AD.Net
AD.Net

Reputation: 13399

You can use the resource file directly. It should be similar to the XAML, i.e. LocalizedResources.Message and you might have to add the using reference to the namespace of that resource file.

    mes.Body = new TextBlock
    {
        Foreground = new SolidColorBrush(Colors.Red),
        Text = LocalizedResources.Message, 
   //given resource file name is "LocalizedResources" and "Message" is the key
        FontSize = 30.0,
        TextAlignment = TextAlignment.Center,
        TextWrapping = TextWrapping.Wrap
    };

Upvotes: 2

Related Questions