I'm a new developer and I'm developing a xamarin forms app. I have some issues in my app.
I didn't use AppShell navigation at first, I used PushModalAsync() method to navigate between pages but now when user want to go home screen of phone then come back later to my application, it restarts the application. I tried another application and I saw that app uses appshell and it works good I mean it works as I want. When navigate from background It continue where it stay.
So now I want to add AppShell Navigation to my xamarin forms app but this InitializeComponent() missing in my AppShell.xaml.cs file.
Should I open a new project or is there any way to add this to my existing app easyly ?
AppShell.xaml
<Shell xmlns:xaml="http://xamarin.com/schemas/2014/forms/design"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:view="clr-namespace:İdaServis.View"
FlyoutWidth="400"
FlyoutHeight="200">
<Shell.Resources>
<ResourceDictionary>
<Style TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.ForegroundColor" Value="White" />
<Setter Property="Shell.TitleColor" Value="White" />
<Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
</Style>
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
<Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
<!--
Default Styles for all Flyout Items
https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyoutitem-and-menuitem-style-classes
-->
<Style Class="FlyoutItemLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="White"></Setter>
</Style>
<!--
Custom Style you can apply to any Flyout Item
-->
</ResourceDictionary>
</Shell.Resources>
<FlyoutItem Title="About" Icon="icon_about.png">
<ShellContent Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
</FlyoutItem>
<FlyoutItem Title="Browse" >
<ShellContent Route="ItemsPage" ContentTemplate="{DataTemplate local:ItemsPage}" />
</FlyoutItem>
<FlyoutItem Title="ProfilePage" >
<ShellContent Route="ProfilePage" ContentTemplate="{DataTemplate view:ProfilePage}" />
</FlyoutItem>
<FlyoutItem Title="AdminPage" >
<ShellContent Route="AdminPage" ContentTemplate="{DataTemplate view:AdminPage}" />
</FlyoutItem>
<FlyoutItem Title="BarkodOzetTabbedPage" >
<ShellContent Route="BarkodOzetTabbedPage" ContentTemplate="{DataTemplate view:BarkodOzetTabbedPage}" />
</FlyoutItem>
<FlyoutItem Title="DepoAktarmaPage" >
<ShellContent Route="DepoAktarmaPage" ContentTemplate="{DataTemplate view:DepoAktarımBarkodPage}" />
</FlyoutItem>
<FlyoutItem Title="RaporSecimPage" >
<ShellContent Route="RaporSecimPage" ContentTemplate="{DataTemplate view:RaporSecimPage}" />
</FlyoutItem>
<FlyoutItem Title="RaporDetailpage" >
<ShellContent Route="RaporDetailpage" ContentTemplate="{DataTemplate view:RaporDetailPage}" />
</FlyoutItem>
<FlyoutItem Title="SayimEvrakSec" >
<ShellContent Route="SayimEvrakSec" ContentTemplate="{DataTemplate view:SayimGirisEvrakSec}" />
</FlyoutItem>
<FlyoutItem Title="SayimEvrakPage" >
<ShellContent Route="SayimEvrakPage" ContentTemplate="{DataTemplate view:SayimGirisEvrak}" />
</FlyoutItem>
<TabBar>
<ShellContent Route="LoginPage" ContentTemplate="{DataTemplate local:LoginPage}" />
</TabBar>
Your AppShell.xaml is missing the
x:Class
attribute specifying the class name. This is required for thepartial
class to have the XAML as a complementary part:Just replace the "YourAppNamespace" with the actual namespace where the C# part of your
AppShell
class lives.After this, the
InitializeComponent()
method should become available.