Search code examples
c#xamarin.formsxamarin.androidxamarin.iosrealm

Databinding in Xamarin.Forms using a RealObject


Apps running very smoothly but I have decided to add to it. I currently have an APR Calculator but I want users to be able to save APRs. so I currently had my app all in the one class as it was pretty small. The way it was set out was using MVVM. Like I said I now want users to be able to save APRs so I installed RealmDB, I've created a class "APR" and pasted my whole MainWindowViewModel code in to that class I've created. APR class inherits Realm Object I have created an instance of the APR class in MainWindowViewModel but the current bindings in my XAML cannot find my properties... Below is the code for my MainWindowViewModel.

namespace APRooved.ViewModels {

public class MainWindowViewModel : ViewModelBase
{

    APR InstanceOne = new APR();

}

}

I'm sure this is just something silly I'm missing, If someone can point me in the right direction It would be much appreciated.


Solution

  • Another way to do this would be initialise your APR class in the constructor

    public class MainWindowViewModel : ViewModelBase
    {
        public APR InstanceOne { get; set; }
    
        public MainWindowViewModel(){
            InstanceOne = new APR();
        }
    }