Reputation: 3980
Why when I use do I loose the shell menu items i.e the hamburger menu
private async void btnAddBill_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("NewBillItemPage");
}
You will see on this screen I have the menu
But once I call the above when I click add it loosing the menu, also when i click the back button it should reinstate the menu but it does not leaving me with
Because i also used this to move back to the listing page.
private async void btnCancel_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("BillsPage");
}
How does one retain the menu through out the navigation experience seems as if shell is a bit broken in 5.0.0.2012
Only code changed in the AppShell is.
<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>
To show my Bills page no other code has been changed from File New.
Edit 2 These are my roots registers in 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));
}
Edit 3
The New bill item page is off a toolbar item on the master listing page of bills.
<ContentPage.ToolbarItems>
<ToolbarItem Text="Add" Clicked="btnAddBill_Clicked" x:Name="btnAddBill" />
<ToolbarItem Order="Primary" IconImageSource="" x:Name="btnclearTestData" Clicked="btnclearTestData_Clicked" />
</ContentPage.ToolbarItems>
The code here above is called from the btnAddBill_Clicked event of the add toolbar
This is the code of the 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>
And now the code behind.
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;
}
}
}
Upvotes: 0
Views: 219
Reputation: 3980
For anyone else who is stuck on this the answer is quite simply the double dot notiation.
await Shell.Current.GoToAsync("..");
The above answer by a so called MSFT staff member as laughable and was not the correct approach at all.
Upvotes: -2