Hi @Marcel Delhaye ,
the title bar and tabs are no longer displayed. The user can no longer go back or access the menu.
Because you set the initial page for the app as a NavigationPage
, try to check what is MainPage
in App
class. From your description, it may be ParametrePage
. Replace Application.Current.MainPage = new NavigationPage(new ParametreDestPage());
by Application.Current.MainPage = new ParametrePage();
For more information about TabbedPage, refer to https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/tabbed-page
How do I apply the changes (refresh the data) to the ParametreDestPage by leaving the title, tabs and the menu button visible?
You need to add value
to the resx:AppResources
file, you want to support three language, so you need to create three resx
file, and add the translation value. The translation file uses the same Name values specified in the default file but contains different language strings in the Value
column. From your Xaml
file of your ParametreDestPage
, I can see that there is no element in the ContentPage
. I add a label for testing, you could refer to the following code:
Xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TransTabPageDemo.ParametreDestPage"
xmlns:resx="clr-namespace:TransTabPageDemo.Resx"
Title="{x:Static resx:Resources.AddButton}">
<ContentPage.Content>
<StackLayout>
<Label Text="{x:Static resx:Resources.WelcomeLabel}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Picker SelectedIndexChanged ="Picker_SelectedIndexChanged">
<Picker.Items>
<x:String>1</x:String>
<x:String>2</x:String>
<x:String>3</x:String>
</Picker.Items>
</Picker>
</StackLayout>
</ContentPage.Content>
</ContentPage>
PickEvent
private void Picker_SelectedIndexChanged(object sender, EventArgs e)
{
Picker picker = (Picker)sender;
CultureInfo language = new CultureInfo(picker.SelectedIndex == 0 ? "fr" : picker.SelectedIndex == 1 ? "en" : "es");
Thread.CurrentThread.CurrentUICulture = language;
AppResources.Culture = language;
Application.Current.MainPage = new ParametrePage();
}
In my Resources.es.resx
, the Name is WelcomeLabel
, Valve is ¡Bienvenido a Xamarin.Forms!
For more details, refer to https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/text?pivots=windows#create-resx-files
---------UPDATE--------
If you want to improve Runtime Changes, refer to this blog :https://devblogs.microsoft.com/xamarin/mastering-multilingual-in-xamarin-forms/
**LocalizationResourceManager **
public class LocalizationResourceManager : INotifyPropertyChanged
{
public static LocalizationResourceManager Instance { get; } = new LocalizationResourceManager();
public string this[string text]
{
get
{
return AppResources.ResourceManager.GetString(text, AppResources.Culture);
}
}
public void SetCulture(CultureInfo language)
{
Thread.CurrentThread.CurrentUICulture = language;
AppResources.Culture = language;
Invalidate();
}
public event PropertyChangedEventHandler PropertyChanged;
public void Invalidate()
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null));
}
}
Helper
[ContentProperty("Text")]
public class TranslateExtension : IMarkupExtension<BindingBase>
{
public string Text { get; set; }
public string StringFormat { get; set; }
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
{
return ProvideValue(serviceProvider);
}
public BindingBase ProvideValue(IServiceProvider serviceProvider)
{
var binding = new Binding
{
Mode = BindingMode.OneWay,
Path = $"[{Text}]",
Source = LocalizationResourceManager.Instance,
StringFormat = StringFormat
};
return binding;
}
}
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.