C
C#2y ago
Knightfox

❔ .NET MAUI MVVM Navigation and pass Object to new page, Throw Exception: Missing method

Program crash after this code
async Task GoApartmentDetail(Apartment apartment)
{
if (apartment is null)
{
return;
}

await Shell.Current.GoToAsync($"{nameof(ApartmentDetailPage)}", true,
new Dictionary<string, object>
{
{"Apartment", apartment}
});
}
async Task GoApartmentDetail(Apartment apartment)
{
if (apartment is null)
{
return;
}

await Shell.Current.GoToAsync($"{nameof(ApartmentDetailPage)}", true,
new Dictionary<string, object>
{
{"Apartment", apartment}
});
}
This is the ViewModel on the next page
namespace BaviHouse.ViewModel
{
[QueryProperty("Apartment","Apartment")]
public partial class ApartmentDetailViewModel : ObservableObject
{
public ApartmentDetailViewModel()
{
}

[ObservableProperty]
Apartment apartment;

}
}
namespace BaviHouse.ViewModel
{
[QueryProperty("Apartment","Apartment")]
public partial class ApartmentDetailViewModel : ObservableObject
{
public ApartmentDetailViewModel()
{
}

[ObservableProperty]
Apartment apartment;

}
}
This is the page code
public partial class ApartmentDetailPage : ContentPage
{


public ApartmentDetailPage(ApartmentDetailViewModel vm)
{
InitializeComponent();
BindingContext = vm;
}

protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);
public partial class ApartmentDetailPage : ContentPage
{


public ApartmentDetailPage(ApartmentDetailViewModel vm)
{
InitializeComponent();
BindingContext = vm;
}

protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);
5 Replies
Ikarmus
Ikarmus2y ago
I made some workaround, RelayCommand seems to be generally better practice, but if you just want to make your project work, this could help: https://github.com/ikarmus2001/brickey_maui/blob/master/brickey_maui/Pages/MainPage.xaml.cs
GitHub
brickey_maui/MainPage.xaml.cs at master · ikarmus2001/brickey_maui
Contribute to ikarmus2001/brickey_maui development by creating an account on GitHub.
Ikarmus
Ikarmus2y ago
@Knightfox
Knightfox
KnightfoxOP2y ago
Thank you. That's awesome
Ikarmus
Ikarmus2y ago
Mark thread closed if you are satisfied with my answer /close
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server