c# - Shell 在 File New xamrain forms 应用程序中未按预期运行
问题描述
为什么当我使用时我会丢失外壳菜单项,即汉堡菜单
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");
}
如何在整个导航体验中保留菜单似乎外壳在 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>
为了显示我的账单页面,没有从 File New 更改其他代码。
编辑 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 工作人员的上述回答很可笑,根本不是正确的方法。
推荐阅读
- python - 为什么我的单滤波器卷积神经网络无法学习简单的高斯核?
- mysql - MySQL 中所有行的 count(*) 总和
- javascript - Angular 5 - 反应形式 - 有没有办法使用变量来修补值?
- c++ - 为什么不建议在空间/辐射环境中使用 C++ 模板?
- angular - 从 Angular 6 升级到 Angular 8 时出错
- ldap - 如何使用该用户的 UPN 更新用户的属性,我正在使用该特定用户的“dn”来更新属性密码
- javascript - 如何将 dataurl 转换回图像并在画布上显示
- angular - 是否有任何方法可以自动安装角度依赖项?
- asp.net-mvc - URL 重写问题 - IIS 和 MVC
- python - 如何绘制非数值数据的日期时间和 value_counts()?