Hi,
in my Xamarin.Forms project I’m using two-way data binding, so I bind an entry component directly to the View Model property (which is the RealmObject). In the view which I’ve evolved from “custom” logic to two-way data binding, it works as expected (I’ve created an empty record in the db) but in the new view which was written directly with two-way data binding the record is not stored in the database.
What am I missing?
public class SettingsViewModel : ObservableObject
{
public Settings WorkingHoursSettings { get; set; }
public SettingsViewModel(IRealmConnector realmConnector)
{
var realm = realmConnector.OpenRealm();
WorkingHoursSettings = realm.ReadWorkingHours();
}
}
public class Settings : RealmObject
{
public static string WORKING_HOURS_KEY = "working-hours";
[PrimaryKey]
[MapTo("_id")]
public ObjectId Id { get; set; }
[Indexed]
public string Key { get; set; }
public string Value { get; set; }
}
public static class RealmExtensions
{
public static Entities.Settings ReadWorkingHours(this Realm instance) =>
instance.All<Entities.Settings>().FirstOrDefault(f => f.Key == Entities.Settings.WORKING_HOURS_KEY);
}
<Entry
HorizontalTextAlignment="End"
Placeholder="How long is your shift in hours"
Keyboard="Numeric"
Text="{Binding Path=WorkingHoursSettings.Value}"
/>