Shell 在 File New xamrain forms 应用程序中未按预期运行

Shell not behaving as expected in File New xamrain forms app

为什么我使用时会丢失 shell 菜单项,即汉堡包菜单

private async void btnAddBill_Clicked(object sender, EventArgs e)
{
        await Shell.Current.GoToAsync("NewBillItemPage");
}

你会在这个屏幕上看到我有菜单

但是一旦我在单击“添加”时调用上面的命令,它就会丢失菜单,而且当我单击“后退”按钮时,它应该会恢复菜单,但它并没有给我留下

因为我也用这个回到列表页面。

private async void btnCancel_Clicked(object sender, EventArgs e)
{
        await Shell.Current.GoToAsync("BillsPage");
}

如何在整个导航体验中保留菜单 shell 在 5.0.0.2012

中有点损坏

只有在 AppShell 中更改的代码是。

<FlyoutItem Title="Bills" Icon="icon_feed.png">
    <ShellContent Route="Bills" ContentTemplate="{DataTemplate local:BillsPage}" />
</FlyoutItem>
<FlyoutItem Title="About" Icon="icon_about.png">
    <ShellContent Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
</FlyoutItem>

为了显示我的帐单页面,没有从文件新建中更改其他代码。

编辑 2 这些是我在 AppShell 中的根寄存器。

public AppShell()
{
        InitializeComponent();
        Routing.RegisterRoute(nameof(BillsDetailPage), typeof(BillsDetailPage));
        Routing.RegisterRoute(nameof(NewBillItemPage), typeof(NewBillItemPage));
        Routing.RegisterRoute(nameof(BillsPage), typeof(BillsPage));
        Routing.RegisterRoute(nameof(BillsHomePage), typeof(BillsHomePage));
}

编辑 3

新帐单项目页面不在帐单主列表页面上的工具栏项目中。

 <ContentPage.ToolbarItems>
    <ToolbarItem Text="Add" Clicked="btnAddBill_Clicked"  x:Name="btnAddBill" />
    <ToolbarItem Order="Primary"  IconImageSource="" x:Name="btnclearTestData" Clicked="btnclearTestData_Clicked" />
</ContentPage.ToolbarItems>

上面的代码是从添加工具栏的 btnAddBill_Clicked 事件中调用的

这是 NewBillItemPage 的代码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="BillManager.Views.NewBillItemPage"
         Shell.PresentationMode="ModalAnimated"
         Title="New Item"
         xmlns:combobox="clr-namespace:Syncfusion.XForms.ComboBox;assembly=Syncfusion.SfComboBox.XForms"
         xmlns:syncfusion="clr-namespace:Syncfusion.XForms.Pickers;assembly=Syncfusion.SfPicker.XForms"

         xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
         ios:Page.UseSafeArea="true">

<ContentPage.Content>
    <StackLayout Spacing="3" Padding="15">
        
        
        <Entry x:Name="txtDescription" FontSize="Medium"  Placeholder="Bill Name"/>
        <Grid RowDefinitions="30, 35">
            <DatePicker x:Name="billStartDate" 
            Grid.Row="1"
            Margin="0, -35, 0, 0"
            VerticalOptions="Center"
            HorizontalOptions="Start"
            WidthRequest="200"
            Format="dd-MMM-yyyy"
            TextTransform="Uppercase"
            FontSize="Body" />
            <Label Text="Start Date" 
        Grid.Row="0"
        Margin="12, 10, 0, 0"
 />
        </Grid>

        <Grid RowDefinitions="30, 35">
            <DatePicker x:Name="billEndDate" 
            Grid.Row="1"
            Margin="0, -35, 0, 0"
            VerticalOptions="Center"
            HorizontalOptions="Start"
            WidthRequest="200"
            Format="dd-MMM-yyyy"
            TextTransform="Uppercase"
            FontSize="Body" />
            <Label Text="End Date" 
        Grid.Row="0"
        Margin="12, 10, 0, 0"
         />
        </Grid>


        <Label Text="Repeat Bill:" 
       
         />

        <combobox:SfComboBox x:Name="cboOccourances" HeightRequest="40" DataSource="{Binding EmployeeCollection}"  DisplayMemberPath="Description" SelectedValuePath="Type">
        </combobox:SfComboBox>



        <Editor AutoSize="TextChanges" FontSize="Medium" Margin="0" />
        <StackLayout Orientation="Horizontal">
            <Button Text="Cancel"  x:Name="btnCancel" Clicked="btnCancel_Clicked" HorizontalOptions="FillAndExpand"></Button>
            <Button Text="Save" x:Name="btnSave" Clicked="btnSave_Clicked" HorizontalOptions="FillAndExpand"></Button>
        </StackLayout>
    </StackLayout>
</ContentPage.Content>

现在是后面的代码。

public partial class NewBillItemPage : ContentPage
 {
    public Bills Item { get; set; }
    private BillManagerDB db;
    public NewBillItemPage()
    {
        InitializeComponent();
        BindingContext = new BillDetailViewModel();
        db = new BillManagerDB();
        Setup();
    }

    private async void btnSave_Clicked(object sender, EventArgs e)
    {
        Bills bill = new Bills();
        bill.Description = txtDescription.Text;
        bill.Startdate = billStartDate.Date;
        bill.EndDate = billEndDate.Date;
        bill.isActive = true;
        bill.isDeleted = false;
        await db.SaveBillItem(bill);
        await DisplayAlert("Bill Saved", "Your build details have been saved.", "OK");
        await Shell.Current.GoToAsync("BillsPage");
    }

    private async  void btnCancel_Clicked(object sender, EventArgs e)
    {
        await Shell.Current.GoToAsync("BillsPage");
    }
    public void Setup()
    {

        List<BillOccuranceTypeViewModel> billOccuranceType = new List<BillOccuranceTypeViewModel>();
        billOccuranceType = new List<BillOccuranceTypeViewModel>()
        {
              new BillOccuranceTypeViewModel {Description="Once",Type=1},
              new BillOccuranceTypeViewModel { Description="Never",Type=2},
              new BillOccuranceTypeViewModel { Description="Weekly",Type=3},
              new BillOccuranceTypeViewModel { Description="Monthly",Type=4},
              new BillOccuranceTypeViewModel { Description="Yearly",Type=5},
              new BillOccuranceTypeViewModel { Description="Quartley",Type=6},

        };
        cboOccourances.DataSource = billOccuranceType;
    }     
}
}

对于任何坚持这个的人来说,答案很简单就是双点符号。

await Shell.Current.GoToAsync("..");

上面一位所谓的 MSFT 工作人员的回答很可笑,根本不是正确的方法。