Language dropdown with Flag in Xamarin forms

Ashwini 26 Reputation points
2021-05-17T12:22:17.803+00:00

Hi ,

I working on Xamarin forms application, I want to implement Language dropdown with Flags , as given in Example below. I need to implement both in android and iOS.

Please help me with this.

97078-7271473c-82cb-430c-a60e-3b144aa4668c.png97175-7ea23598-908c-427e-997d-bfb6e083d1e1.png

Developer technologies | .NET | Xamarin
{count} votes

2 answers

Sort by: Most helpful
  1. Alessandro Caliaro 4,196 Reputation points
    2021-05-17T12:29:31.58+00:00

    I think you can create a popup with a collection view

    for the popup you can use Xamarin-Community-Toolkit-Platform-Perfect-Popups-Part-1

    0 comments No comments

  2. Ashwini 26 Reputation points
    2021-05-25T13:28:39.623+00:00

    Hi @Alessandro Caliaro Thanks for the idea, I was able to implement the same way as you suggested.
    But i am not able to bind the image from view model.
    Scenario: I have 3 flag images. when i select the country images has to bind with respective flags. Thats not happening in my code.

    Xaml

    <Image x:Name="image" WidthRequest="25" Source="{Binding SomeImage}" HeightRequest="25" Margin="0,0,20,0">
    <Image.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding OpenLanguage}"/>
    </Image.GestureRecognizers>
    </Image

    viewModel:
    private ImageSource _someImage;
    public ImageSource SomeImage
    {

            get { return _someImage; }  
            set  
            {  
                _someImage = value;  
                OnPropertyChanged("SomeImage");  
                // better yet  
                // OnPropertyChanged(nameof(ImageBattery));  
            }  
        }  
    

    method:

    if (selected_Item.Key.ToString() == "zh")
    {
    SomeImage = ImageSource.FromFile("china_Flag.png");

            }    
            else if (selected_Item.Key.ToString() == "en")    
            {    
                SomeImage = ImageSource.FromFile("UK_image.png");    
            }    
            else if (selected_Item.Key.ToString() == "pt")    
            {    
                SomeImage = ImageSource.FromFile("pt_Flag.png");    
            }    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.