Julien Duprat
Julien Duprat

Reputation: 75

In Xamarin Forms application in MVVM, i use FreshMvvm framework and want to navigate to targetPageModel and pass data from commandParameter

xaml extract :

<Button ... Command="{Binding NextPageButtonCommand,  Mode=OneWay}" CommandParameter="wallet" />

In This code command callback with parameter works well :

NextPageButtonCommand = new Command<string>(parameter => Debug.WriteLine(parameter));

But with this this code with async and PushPageModel is not working...

NextPageButtonCommand = new Command<string>(async typeOfCase => await CoreMethods.PushPageModel<TargetPageModel>(typeOfCase));

TargetPageModel

public class TargetPageModel : FreshBasePageModel
    {
        public TargetPageModel(string parameter)
        {
            CreateYourCodeText = "Créez votre code :";
        }
    }

Thank you for your help :)

Upvotes: 1

Views: 124

Answers (1)

ToolmakerSteve
ToolmakerSteve

Reputation: 21223

Expanding on Shaw's comment:
At FreshMvvm Important Methods, see public virtual void Init(object initData) { }.

Override that method, to use the data you pass in. Something like:

public class TargetPageModel : FreshBasePageModel
{
    ...
    public override void Init(object initData)
    {
        var typeOfCase = (string)initData;
        ...
    }
}

Upvotes: 1

Related Questions