locked
Alternate values from observablecollection RRS feed

  • Question

  • User386578 posted

    I'm trying to change the label text property I'm receiving from my binding depending on the language without making a different page, is this possible? let's say if I have {Binding textes} and {Binding texten}

    How can I alternate them? thought about having the two labels and setting isEnable true or false depending on the language but the bindingcontext is set to the viewmodel and can't access the back code to make it, what are the options here?

    Is it possible to change the values from the observable collection? for example if I receive a month in 1,2,3,4,5... change it to jan,feb.mar or ene.feb,mar... and so on depending on the language?

    Saturday, September 14, 2019 7:36 PM

Answers

  • User386578 posted

    So far just included 2 string values in the model something like spanish and english and did:

        for (int i = 0; i < Newses.Count; i++)
                    {
                        if (Preferences.Get("Spanish", true))
                        {
                            Newses[i].english = "False";
                            Newses[i].spanish = "True";
                        }
                        else
                        {
                            Newses[i].english = "True";
                            Newses[i].spanish = "False";
                        }
    

    And placed that value in the isVisible through {Binding english} and {Binding spanish} for each label :/ it works but can't say if it's the best way

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, September 14, 2019 10:16 PM

All replies

  • User386578 posted

    So far just included 2 string values in the model something like spanish and english and did:

        for (int i = 0; i < Newses.Count; i++)
                    {
                        if (Preferences.Get("Spanish", true))
                        {
                            Newses[i].english = "False";
                            Newses[i].spanish = "True";
                        }
                        else
                        {
                            Newses[i].english = "True";
                            Newses[i].spanish = "False";
                        }
    

    And placed that value in the isVisible through {Binding english} and {Binding spanish} for each label :/ it works but can't say if it's the best way

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, September 14, 2019 10:16 PM
  • User379860 posted

    If the value in the observablecollection, it is a good way to achieve it. If the value not in the observablecollection, Localization is a best way.

    Please mark your reply as answer, it will help others who have similar issue.

    Monday, September 16, 2019 6:02 AM