Xamarin MVVM passing data to other view

后端 未结 3 992
温柔的废话
温柔的废话 2021-01-27 09:57

I want to pass the data to another view page. So far I can get the data I need to pass. My problem is how do I pass the data in MVVM. I used Application.Current.MainPage.Navigat

相关标签:
3条回答
  • 2021-01-27 10:25

    If you want to send the int. First declare that in your DatabaseSyncPage Like below

    public partial class DatabaseSyncPage : ContentPage
    {
        public DatabaseSyncPage( int Id)
        {
        }
    }
    

    & when you are pushing your page in your code else block do like this

    if (content.Equals("[]") || string.IsNullOrWhiteSpace(content) || string.IsNullOrEmpty(content))
    {
        MessagingCenter.Send(this, "Http", Username);
    }
    else
    {
        var result = JsonConvert.DeserializeObject<List<LoggedInUser>>(content);
        var contactId = result[0].ContactID;
        Application.Current.MainPage.Navigation.PushAsync(new DatabaseSyncPage(contactId), true);
    }
    
    0 讨论(0)
  • 2021-01-27 10:34

    I'm assuming that contactID is an int.

    Create an additional constructor in your DatabaseSyncPage:

    public DatabaseSyncPage (int contactID)
    {
        // TODO: Do something with your id
    }
    

    But this passes the data to the page, not the page model. Are you using any kind of framework? It would probably be worth looking into that.

    0 讨论(0)
  • 2021-01-27 10:38

    You can use xamrin.plugins.settings nuget package.

    0 讨论(0)
提交回复
热议问题