Forum Xamarin.Forms

Localization problem with picker text !

solymansolyman Member ✭✭
edited March 31 in Xamarin.Forms

Hi , simply the problem is with calling the app resources , in a regular text it is working fine but in a picker text like this


<Picker.ItemsSource>

              <x:String>{x:Static resources:AppResources.iftar_s}</x:String>
              <x:String>{x:Static resources:AppResources.suhoor_s}</x:String>
              <x:String>{x:Static resources:AppResources.if_su_s}</x:String>

            </x:Array >
          </Picker.ItemsSource>
        </Picker>

its taking it literally like in the picture

I will be happy if someone knows what to do .

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    You can define the Picker's ItemsSource in the xaml.cs. For example:

               var typeList = new List<string>();
                typeList.Add(AppResources.iftar_s);
                typeList.Add(AppResources.suhoor_s);
                typeList.Add(AppResources.if_su_s);
    
                picker.ItemsSource = typeList;
    

    And xaml

          <Picker x:Name="picker"
            Title="Select a type"
            TitleColor="Red">
            </Picker>
    
  • solymansolyman Member ✭✭

    @jezh said:
    You can define the Picker's ItemsSource in the xaml.cs. For example:

               var typeList = new List<string>();
                typeList.Add(AppResources.iftar_s);
                typeList.Add(AppResources.suhoor_s);
                typeList.Add(AppResources.if_su_s);
    
                picker.ItemsSource = typeList;
    

    And xaml

          <Picker x:Name="picker"
            Title="Select a type"
            TitleColor="Red">
            </Picker>
    

    Thank you , that actually solve the problem :) , but can I ask if there a difference if you initilise an instance in xaml and xaml.cs ? maybe fastness or performance , or there is no different ? thank you again.

  • jezhjezh Member, Xamarin Team Xamurai

    This is a common approach that has little impact on our codes.

    When we use code as follows:

     <x:String> XXXstring</x:String>
    

    We should put a string between <x:String> and </x:String>.

    Hope it can help you.
    Best Regards!

  • jezhjezh Member, Xamarin Team Xamurai

    @solyman hey friend , if my reply is useful for you, could you please mark it as an answer?

Sign In or Register to comment.