Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

DataBinding to result of API Call MVVM

Steve1000Steve1000 Member ✭✭✭
edited May 2019 in Xamarin.Forms

Hi I've written the folllowing code to tie the View ViewModel and Model - just wanted to check if this is best practice or if it could be improved in anyway?

I've had a quick look at some MVVM frameworks but i find them pretty complex to understand and not sure if would be required just yet so would prefer to stick with standard xamarin mvvm if possible.


public class ProfileModel   
    public string Name {get; set;}

    // other profile properties e.g. Age, Location, About, etc.  



   public class ProfileViewModel : INotifyPropertyChanged
        private ProfileModel {get;set;}

        public ProfileViewModel ()
            profileModel = new ProfileModel();

        public async void LoadData()
            Api api = new Api();
                ProfileModel p = await api.GetMyProfile();
                profileModel = p;




<Label Text = "{Binding ProfileModel.Name, Mode=TwoWay}" />


  • onurcanyilmazonurcanyilmaz Member ✭✭
    edited May 2019

    @Steve1000 use Binding context ur xaml.cs
    ProfileViewModel vm;
    public MainPage()
    vm = new ProfileViewModel ();
    BindingContext = vm;
    and your xaml page;
    < Label Text="{Binding Id Mode=TwoWay}">< /Label>

  • jezhjezh Member, Xamarin Team Xamurai

    Have you resolved this question?

Sign In or Register to comment.