Xamarin.form Page Navigation in mvvm

前端 未结 8 1067
耶瑟儿~
耶瑟儿~ 2021-02-04 03:52

I am working on xamarin.form cross-platform application , i want to navigate from one page to another on button click. As i cannot do Navigation.PushAsync(new Page2());

8条回答
  •  梦如初夏
    2021-02-04 04:19

    I looked into this, and it really depends on how you want to handle your navigation. Do you want your view models to handle your navigation or do you want your views. I found it easiest to have my views handle my navigation so that I could choose to have a different navigation format for different situations or applications. In this situation, rather than using the command binding model, just use a button clicked event and add the new page to the navigation stack in the code behind.

    Change your button to something like:

    
        
    
    

    And in your code behind, implement the method and do the navigation there.

    public void Button_Clicked(object sender, EventArgs e)
    {
        Navigation.PushAsync(new Page2());
    }
    

    If you are looking to do viewmodel based navigation, I believe there is a way to do this with MvvmCross, but I am not familiar with that tool.

提交回复
热议问题