Hello! I just can not understand what the problem is. Standard application with MasterDetailPage. I need the main menu items to change the text when the localization changes. The very change in the localization of text on the pages I did as described here, it works great.
MainPage.xaml looks like this:
<MasterDetailPage.Master>
<ContentPage Title="Menu" BackgroundColor="#e8e8e8">
<StackLayout Orientation="Vertical">
<!--
This StackLayout you can use for other
data that you want to have in your menu drawer
-->
<StackLayout BackgroundColor="#e74c3c" HeightRequest="75">
<Label Text="Main Menu"
FontSize="20"
VerticalOptions="CenterAndExpand"
TextColor="White"
HorizontalOptions="Center"/>
</StackLayout>
<ListView x:Name="navigationDrawerList"
RowHeight="60"
SeparatorVisibility="None"
BackgroundColor="#e8e8e8"
ItemSelected="OnMenuItemSelected"
ItemTapped="OnMenuItemTapped"
CachingStrategy = "RecycleElement"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!-- Main design for our menu items -->
<StackLayout VerticalOptions="FillAndExpand"
Orientation="Horizontal"
Padding="20,10,0,10"
Spacing="20">
<Image Source="{Binding Icon}"
WidthRequest="40"
HeightRequest="40"
VerticalOptions="Center" />
<Label Text="{Binding Title}"
FontSize="Default"
VerticalOptions="Center"
TextColor="Black"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
MainPage.xaml.sc:
public partial class MainPage : MasterDetailPage
{
public ObservableRangeCollection<MasterPageItem> MenuList { get; set; }
MyViewModel vModel = null;
MasterPageItem gamePageItem = null;
Binding gpBinding = null;
public MainPage(MyViewModel viewModel)
{
InitializeComponent();
vModel = viewModel;
gamePageItem = new MasterPageItem() { Title = vModel.Resources["LearningMenuItemText"], Icon = "learning.png", TargetType = typeof(GamePage) };
gpBinding = new Binding(path: "Resources[LearningMenuItemText]", source: vModel);
gamePageItem.SetBinding(MasterPageItem.TitleProperty, gpBinding);
// Adding menu items to menuList
MenuList = new ObservableRangeCollection<MasterPageItem>()
{
gamePageItem
};
// Setting our list to be ItemSource for ListView in MainPage.xaml
navigationDrawerList.ItemsSource = MenuList;
This works, but ONLY ONCE, with the first change in localization. With subsequent changes in localization, the text of menu items does not change.
Any idea why?