Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Taking a simple approach to localize in Xamarin Forms - Why this binding does not work?

$
0
0

I am taking the inspiration from Localization in WP8.x.

  1. Add Resx resources in a Resources folder in PCL project.

  2. Create a LocalizedResources class in PCL Project:
    `namespace MyApp
    {
    ///


    /// Provides access to string resources.
    ///

    public class LocalizedStrings
    {
    private static Resources.AppResources _localizedResources = new Resources.AppResources();

        public Resources.AppResources LocalizedResources { get { return _localizedResources; } }
    }
    

    }`

  3. Create a global LocalizedStrings static resource in App.xaml

    <Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyApp.App"> <Application.Resources> <ResourceDictionary> <local:LocalizedStrings xmlns:local="clr-namespace:MyApp" x:Key="LocalizedStrings"/> </ResourceDictionary> </Application.Resources> </Application>

  4. In the main content page xaml bind to the localized string:

    <?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyApp.MainPage"> <Label Text="{Binding Source={StaticResource LocalizedStrings}, Path=LocalizedResources.WelcomeMessage}" VerticalOptions="Center" HorizontalOptions="Center" /> </ContentPage>

  5. Running the app shows no message in the label. My understanding was that in Xamarin.Forms binding, both Source and Path with nested properties are supported. Am I doing something wrong here?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>