Search code examples
visual-studio-2022maui

How do you pass parameters in MAUI without using a ViewModel?


I have this on one page:

await Shell.Current.GoToAsync(nameof(Pages.StartPage), true, new Dictionary<string, object>
{
    { "LoginData", result }
});

result is an object/class

In my Pages.StartPage I want to get that object. I have tried using [QueryProperty... but that always returns a null. E.g.

[QueryProperty(nameof(GetLoginData), "LoginData")]
public partial class StartPage : ContentPage

...

private JsonApiResult GetLoginData { set { _loginData = value; }  }

I've just started using MAUI, and I am converting an app from Xamarin to MAUI. The pages I have built take care of themselves, so I don't want to use ViewModels, I just need a value from that passed-in object for the page to do its stuff. I don't want to have to rewrite all my pages unless there is no other way

Any help would be much appreciated. I've watched loads of videos on this, and I can't make it work, what am I missing?

UPDATE

I should add that to make matters more complex for myself, I am also using Dependency Injection (DI)


Solution

  • private JsonApiResult _loginData;
    public JsonApiResult LoginGetData { 
        get  => _loginData; 
        set { _loginData = value; } 
    }
    

    It seems this was the solution though I can't see why. I'll dig into it another time but right now its working so I can crack on