我是一名新开发人员,正在开发一个 xamarin 表单应用程序。我的应用程序遇到一些问题。
我一开始没有使用 AppShell 导航,我使用 PushModalAsync() 方法在页面之间导航,但现在当用户想要转到手机主屏幕然后返回到我的应用程序时,它会重新启动应用程序。我尝试了另一个应用程序,我看到该应用程序使用 appshell 并且运行良好,我的意思是它按照我的意愿运行。当从后台导航时,它会继续原来的位置。
所以现在我想将 AppShell 导航添加到我的 xamarin 表单应用程序中,但我的 AppShell.xaml.cs 文件中缺少这个 InitializeComponent() 。
我应该打开一个新项目还是有什么方法可以轻松地将其添加到我现有的应用程序中?
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>
您的 AppShell.xaml 缺少指定类名称的
x:Class
属性。这是 partial
类将 XAML 作为补充部分所必需的:
<Shell xmlns:xaml="http://xamarin.com/schemas/2014/forms/design"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:view="clr-namespace:İdaServis.View"
x:Class="YourAppNamespace.AppShell">
只需将“YourAppNamespace”替换为
AppShell
类的 C# 部分所在的实际命名空间。
此后,
InitializeComponent()
方法应该可用。