0

I am trying to create a bottom nav bar with the NuGet:ThriveGmbH.BottomNavigationBar.XF

I hope that I am thinking correctly but this is my setup.

This is the code that is linking to my profile page, here I get the error

Severity    Code Description    Project File    Line    Suppression State
Error   CS1729  'BottomNavPage' does not contain a constructor that takes 1 arguments   DoggaLogg.Android, DoggaLogg.iOS, DoggaLogg.UWP C:\Users\mawil3\source\repos\DoggaLogg\DoggaLogg\DoggaLogg\View\HomePage.xaml.cs    40  Active
Error   CS1729  'BottomNavPage' does not contain a constructor that takes 1 arguments   DoggaLogg.Android, DoggaLogg.iOS, DoggaLogg.UWP C:\Users\mawil3\source\repos\DoggaLogg\DoggaLogg\DoggaLogg\View\HomePage.xaml.cs    40  Active)
async void ProfileList_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
    if (e.SelectedItem != null)
    {
        await Navigation.PushAsync(new BottomNavPage(BindingContext = e.SelectedItem));
    }
}

Here is my bottomnavbar xaml page:

<xf:BottomBarPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="DoggaLogg.View.BottomNavPage"
         xmlns:xf="clr-namespace:BottomBar.XamarinForms"
         xmlns:pages="clr-namespace:DoggaLogg.View">


<pages:ProfilePage Title="Profile" Icon="icon" />

<pages:GoalPage Title="Goalse" Icon="icon" /></xf:BottomBarPage>

And here Bottomnavbar.cs

namespace DoggaLogg.View{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BottomNavPage : ContentPage
{
    public BottomNavPage ()
    {
        InitializeComponent ();
    }
}}

From my understanding e.selecteditem should pass through the selected item, or am I wrong?

What could cause the error?

TZHX
  • 5,291
  • 15
  • 47
  • 56

1 Answers1

1

You are creating a new BottomNavPage like this: new BottomNavPage(BindingContext = e.SelectedItem), but there is no constructor that takes one argument.

It seems you are trying to set the BindingContext property of your new page directly. Either pass in your selected item as an argument which requires you to change or add a constructor to your BottomNavPage object:

public BottomNavPage (object yourItem)
{
    InitializeComponent ();

    BindingContext = yourItem;
}

Or, declare the first line like this:

await Navigation.PushAsync(new BottomNavPage()
{
    BindingContext = e.SelectedItem
});

This instantiates a new BottomNavPage with the parameterless constructor but assigns your selected item to the BindingContext immediately after creating the new instance.

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100