Hello,
Xamarin support will end on May 1, 2024, it's recommended that you migrate your Xamarin app to .NET MAUI. Please see Xamarin official support policy .
=============Update==================
You used Enterprise App Navigation, please refer to the following steps to make the navigation and fix errors.
Step 1: please open MenuPageModel.cs
, remove other content, just keep one constructor like following code.
public class MenuPageModel : PageModelBase
{
public MenuPageModel() {
}
}
Step 2: Open MenuPage.xaml
remove all of BindingContext= yourModel
like following code.
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
mc:Ignorable="d"
xmlns:pages="clr-namespace:MapleSugar.Pages"
x:Class="MapleSugar.Pages.MenuPage">
<TabbedPage.Children>
<NavigationPage Title="Collection">
<x:Arguments>
<pages:CollectionPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Tree Location">
<x:Arguments>
<pages:TreeInfoPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Check List">
<x:Arguments>
<pages:CheckListPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Map Page">
<x:Arguments>
<pages:MapPage />
</x:Arguments>
</NavigationPage>
<!-- <NavigationPage Title="File Picker">
<x:Arguments>
<pages:FilePickerPage BindingContext="{Binding FilePickerPage}"/>
</x:Arguments>
</NavigationPage>
-->
<NavigationPage Title="File IO">
<x:Arguments>
<pages:FileSystemPage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
Step 3: Open CheckListPage.xaml
, add CheckListPageModel in the ContentPage's xml. As Note, please add pageModel for other pages like FileSystemPage
, CollectionPage
, TreeInfoPage
CheckListPage
.
<ContentPage
...
add this content
xmlns:local="clr-namespace:MapleSugar.PageModels"
...
x:Class="MapleSugar.Pages.CheckListPage">
add page model here
<ContentPage.BindingContext>
<local:CheckListPageModel />
</ContentPage.BindingContext>
Step 4: open CheckListPageModel.cs
, remove navigationService in constructor like following code.
public CheckListPageModel()
{
WorkTreeLocationItems = new ObservableCollection<WorkTreeLocationItem>();
Load_Button_Clicked = new ButtonModel("Load Data", LoadCheckListAction);
OnEditCommand = new Command(OnEditCommandAction);
Close_App_Clicked = new ButtonModel("Close App", CloseAppAction);
}
And use following code to make a Navigation and send data to TreeInfoPageModel
public async void OnEditCommandAction(object SelectedObj)
{
CheckListItem checkListItem = SelectedObj as CheckListItem;
// navigationService.PushAsync(new TreeInfoPage(checkListItem));
var navService = PageModelLocator.Resolve<INavigationService>();
await navService.NavigateToAsync<TreeInfoPageModel>(checkListItem, true);
return;
}
Step 5: In this TreeInfoPageModel.cs, please chanage the TreeInfoPageModel's constructor like following code and override InitializeAsync
, you can get the navigated data by object navigationData
/* main code */
public TreeInfoPageModel( )
{
StatusMsg = "Ready";
WorkTreeLocationItems = new ObservableCollection<WorkTreeLocationItem>();
SaveLocationDataModel = new ButtonModel("Save Data", OnSaveLocationDataAction);
Close_App_Clicked = new ButtonModel("Close App", CloseAppAction);
}
public override Task InitializeAsync(object navigationData)
{
if (navigationData is WorkCollectedItem)
{
WorkCollectedItem workCollectedItem = navigationData as WorkCollectedItem;
// for testing.
TreeNumber = workCollectedItem.TreeNumber.ToString();
}
if (navigationData is CheckListItem)
{
CheckListItem workCollectedItem = navigationData as CheckListItem;
// for testing.
TreeNumber = workCollectedItem.TreeNumber.ToString();
}
return base.InitializeAsync(navigationData);
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.