英文:
on c# MAUI The <TabBar> stop working if I call Shell.Current.GoToAsync("//Notificaciones"); from App.xaml.cs
问题
I'm working on one c# MAUI App on the AppShell.xaml file I have a TabBar with 4 Tab:
<TabBar>
<Tab Title="Saldo"
Icon="Cat.png">
<ShellContent
Route="Saldo"
ContentTemplate="{DataTemplate local:Saldo}"
/>
</Tab>
<Tab Title="Pontos"
Icon="dog.png">
<ShellContent
Route="Pontos"
ContentTemplate="{DataTemplate local:Pontos}"
/>
</Tab>
<Tab Title="Postos"
Icon="mapa.png">
<ShellContent
Route="Postos"
ContentTemplate="{DataTemplate local:Postos}"
/>
</Tab>
<Tab Title="Notificaciones"
Icon="elephant.png">
<ShellContent
Route="Notificaciones"
ContentTemplate="{DataTemplate local:Notificaciones}"
/>
</Tab>
</TabBar>
All work fine but the problem is when I receive a notification I try to open the Notifications from the App.xaml.cs and work but after this the 4 tabs stop navigating
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
Shell.Current.GoToAsync("//Notificaciones");
};
if I use the same code Shell.Current.GoToAsync("//Notificaciones"); from inside of any of the 4 pages all continue working, I read the Xamarin.Forms Shell navigation (https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation) and try all the possible options like "Notificaciones" ; "/Notificaciones" ; "//Notificaciones" ; "///Notificaciones" and or don't go to "Notificaciones" or go and stop working the 4 Tab.
I try too replace the <TabBar> for <FlyoutItem Route="Home"> and use the address "//Home/Notificaciones" but are always the same problem.
Any idea?
Regards
英文:
I'm working on one c# MAUI App on the AppShell.xaml file I have a TabBar with 4 Tab:
<TabBar>
<Tab Title="Saldo"
Icon="Cat.png">
<ShellContent
Route="Saldo"
ContentTemplate="{DataTemplate local:Saldo}"
/>
</Tab>
<Tab Title="Pontos"
Icon="dog.png">
<ShellContent
Route="Pontos"
ContentTemplate="{DataTemplate local:Pontos}"
/>
</Tab>
<Tab Title="Postos"
Icon="mapa.png">
<ShellContent
Route="Postos"
ContentTemplate="{DataTemplate local:Postos}"
/>
</Tab>
<Tab Title="Notificaciones"
Icon="elephant.png">
<ShellContent
Route="Notificaciones"
ContentTemplate="{DataTemplate local:Notificaciones}"
/>
</Tab>
</TabBar>
All work fine but the problem are when I receive a notification I try to open the Notifications from the App.xaml.cs and work but after this the 4 tabs stop navigating
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
Shell.Current.GoToAsync("//Notificaciones");
};
if I use the same code Shell.Current.GoToAsync("//Notificaciones"); from inside of any of the 4 pages all continue working, I read the Xamarin.Forms Shell navigation (https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation) and try all the possible options like "Notificaciones" ; "/Notificaciones" ; "//Notificaciones" ; "///Notificaciones" and or don't go to "Notificaciones" or go and stop working the 4 Tab.
I try too replace the <TabBar> for <FlyoutItem Route="Home"> and use the address "//Home/Notificaciones" but are always the same problem.
Any idea?
Regards
答案1
得分: 1
首先,更改 Shell XAML。
...
<Tab Title="通知"
Route="通知" << 在此处添加路由
Icon="elephant.png">
<ShellContent
//Route="通知" << 删除此部分
ContentTemplate="{DataTemplate local:通知}"
/>
</Tab>
其次,更改导航为:
Shell.Current.GoToAsync("///通知");
编辑:
为了澄清,您需要为选项卡设置路由。除此之外,每个阅读它的人都会知道您试图做什么。
要导航到选项卡,您必须使用三个斜杠。每个选项卡都有自己的导航堆栈,您可以像这样从一个切换到另一个。如果不使用三个斜杠,页面将覆盖您当前的导航堆栈。
实际上,这并不是坏事。有时我故意这样做。但在您的情况下,我99.99%确定您实际上是要选择另一个选项卡。
英文:
First, change the Shell XAML.
...
<Tab Title="Notificaciones"
Route="Notificaciones" << route goes here
Icon="elephant.png">
<ShellContent
//Route="Notificaciones" << remove this
ContentTemplate="{DataTemplate local:Notificaciones}"
/>
</Tab>
Second, change navigation to:
Shell.Current.GoToAsync("///Notificaciones");
Edit:
To clarify, You need to route your tabs. Besides everything else, everyone reading it will know what you are trying to do.
And to navigate to a tab you have to use triple slash. Each tab has its own navigation stack, and you can switch from one to another like that. If you do not do triple, pages will go over your current navigation stack.
This is not bad actually. Sometimes this is something I do on purpose.
But in your case I am 99.99% sure that you are trying to actually select the other tab.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论