Net maui runtime loading problem ?

Sami 881 Reputation points
2023-06-02T16:18:57.21+00:00

I have created languageconverter as above binding from C# listing...Firstly binding values by Text="{DynamicResource Key=welcome}" like that.. it is working as expected but when loaded page with custom collectionview is not changing language runtime... when scrolling left or right that all changes done. What do you think the problem?

    public class LanguageConverter : IValueConverter
    {
        public string ReturnValue { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {

            ReturnValue = "";
            var txt = value as string;
            var currentLang = MultiLanguages.CurrentLang;
            if(currentLang.ContainsKey(txt))
            {
                ReturnValue = currentLang[txt].ToString();
            }

            return ReturnValue;
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    void PopulateData()
        {
            CategoryList.Clear();
            CategoryList.Add(new Category() { CategoryId = 1, CategoryName = "shopping", CategoryColor = Color.FromArgb("#C19434"), Icon = "\x3c" });
            CategoryList.Add(new Category() { CategoryId = 2, CategoryName = "fashion", CategoryColor = Color.FromArgb("#12c998"), Icon = "\xe81e" });
            CategoryList.Add(new Category() { CategoryId = 3, CategoryName = "food", CategoryColor = Color.FromArgb("#339933"), Icon = "\x5e" });

    }

CategoryName = "shopping" < shopping is the key for language convert the language

<control:CategoriesCollectionView ItemsSource="{Binding CategoryList}" />

Inside CategoriesColectionView


    <ContentView.Resources>
        <conv:LanguageConverter x:Key="langConverter" />
    </ContentView.Resources>

<Label  FontSize="{StaticResource XXSFontSize}" Text="{Binding CategoryName,Converter={StaticResource langConverter}}" TextColor="{DynamicResource SecondaryTextColor}"  VerticalOptions="Center" HorizontalOptions="Center"  LineBreakMode="TailTruncation"/>
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,207 questions
{count} votes