Xamarin.Forms use current ContentPage as CommandProperty in XAML

315 Views Asked by At

I need the currently visible ContentPage, that is bind to a viewmodel, as a CommandParameter for a view model's command.

Like:

<Button Text="Save" 
        Command="{Binding AddObjectAndClosePage}" 
        CommandParameter={Binding MyContentPage} />

But Xamarin does not support the ElementNamebinding. How can I use now my ContentPage as parameter?

1

There are 1 best solutions below

4
Tobonaut On

Ok, it was completely my fault. My approach was breaking all rules of the mvvm pattern.

You can access the Navigationcontext in the command method in your viewmodel by writing:

Application.Current.MainPage.Navigation.PopModalAsync();

Lesson learned.