Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a resource String in the c# code in WP7?

I followed this tutorial to localize my app: http://msdn.microsoft.com/en-us/library/ff637520%28v=vs.92%29.aspx#Y1210

So I created the class:

namespace Foo
{
    public class LocalizedStrings
    {
        public LocalizedStrings()
        {
        }

        private static Foo.AppResources localizedresources = new Foo.AppResources();

        public Foo.AppResources Localizedresources { get { return localizedresources; } }

    }
}

When I use {Binding Path=Localizedresources.String1, Source={StaticResource LocalizedStrings}} in the XAML files it works great, but

how can I access to the String1 in the source code e.g. to set a textBlock.Text

like image 506
ewggwegw Avatar asked Dec 07 '22 21:12

ewggwegw


1 Answers

In C# you can just do:

textBlock.Text = AppResources.MyLocalizedString;

or in XAML:

<TextBlock Text="{Binding Path=LocalizedResources.MyLocalizedString, Source={StaticResource LocalizedStrings}}" >
like image 200
Matt Lacey Avatar answered Dec 09 '22 11:12

Matt Lacey