on c# MAUI The <TabBar> stop working if I call Shell.Current.GoToAsync("//Notificaciones"); from App.xaml.cs

huangapple go评论68阅读模式
英文:

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:

&lt;TabBar&gt; 
    &lt;Tab Title=&quot;Saldo&quot;
        Icon=&quot;Cat.png&quot;&gt;
        &lt;ShellContent
        Route=&quot;Saldo&quot; 
        ContentTemplate=&quot;{DataTemplate local:Saldo}&quot;
        /&gt;
   &lt;/Tab&gt;
    &lt;Tab Title=&quot;Pontos&quot; 
        Icon=&quot;dog.png&quot;&gt;
        &lt;ShellContent
        Route=&quot;Pontos&quot;
        ContentTemplate=&quot;{DataTemplate local:Pontos}&quot;
        /&gt;
    &lt;/Tab&gt;
    &lt;Tab Title=&quot;Postos&quot;
        Icon=&quot;mapa.png&quot;&gt;
        &lt;ShellContent
        Route=&quot;Postos&quot; 
        ContentTemplate=&quot;{DataTemplate local:Postos}&quot;
        /&gt;
    &lt;/Tab&gt;
    &lt;Tab Title=&quot;Notificaciones&quot;
        Icon=&quot;elephant.png&quot;&gt;
        &lt;ShellContent
        Route=&quot;Notificaciones&quot;
        ContentTemplate=&quot;{DataTemplate local:Notificaciones}&quot;
         /&gt;
    &lt;/Tab&gt;
&lt;/TabBar&gt; 

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) =&gt;
	{
	    Shell.Current.GoToAsync(&quot;//Notificaciones&quot;);
	};

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 &lt;TabBar&gt; for &lt;FlyoutItem Route="Home"&gt; and use the address "//Home/Notificaciones" but are always the same problem.

Any idea?

Regards

答案1

得分: 1

首先,更改 Shell XAML。

...
&lt;Tab Title=&quot;通知&quot;
    Route=&quot;通知&quot; &lt;&lt; 在此处添加路由
    Icon=&quot;elephant.png&quot;&gt;
    &lt;ShellContent
    //Route=&quot;通知&quot; &lt;&lt; 删除此部分
    ContentTemplate=&quot;{DataTemplate local:通知}&quot;
     /&gt;
&lt;/Tab&gt;

其次,更改导航为:

Shell.Current.GoToAsync(&quot;///通知&quot;);

编辑:

为了澄清,您需要为选项卡设置路由。除此之外,每个阅读它的人都会知道您试图做什么。

要导航到选项卡,您必须使用三个斜杠。每个选项卡都有自己的导航堆栈,您可以像这样从一个切换到另一个。如果不使用三个斜杠,页面将覆盖您当前的导航堆栈。

实际上,这并不是坏事。有时我故意这样做。但在您的情况下,我99.99%确定您实际上是要选择另一个选项卡。

英文:

First, change the Shell XAML.

 ... 
 &lt;Tab Title=&quot;Notificaciones&quot;
    Route=&quot;Notificaciones&quot; &lt;&lt; route goes here
    Icon=&quot;elephant.png&quot;&gt;
    &lt;ShellContent
    //Route=&quot;Notificaciones&quot; &lt;&lt; remove this
    ContentTemplate=&quot;{DataTemplate local:Notificaciones}&quot;
     /&gt;
&lt;/Tab&gt;

Second, change navigation to:

Shell.Current.GoToAsync(&quot;///Notificaciones&quot;);

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.

huangapple
  • 本文由 发表于 2023年6月12日 17:00:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455059.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定