3
votes

I am building a Xamarin Forms Application and using XAML that is databound to a ViewModel that contains the model that is stored in Realm datastore.

When Two Way databinding it turned on the view will throw the error

Cannot set values outside transaction

Which includes

InnerException {Realms.RealmOutsideTransactionException: Cannot set values outside transaction at Realms.RealmObje…} Realms.RealmOutsideTransactionException

I'm not sure why the data binding is wanting to set the value back on the RealmObject when its loading the View that shows the Entry object that its databound to.

By Default the Mode=TwoWay. I have to change it to Mode=OneWay to get the view to load the databound data.

Is this a bug? According to this article, this should work.

https://blog.xamarin.com/cross-platform-development-with-xamarin-forms-and-realm/

1

1 Answers

0
votes

When you have two-way binding then the Realm needs to have an active Transaction as shown in the QuickJournal sample's JournalEntryDetailsPage.

I'm not sure why the data binding is wanting to set the value back on the RealmObject when its loading the View that shows the Entry object that its databound to.

This puzzles me too. It is a quirk of the way Xamarin Forms implement two-way bindings. If a string property is blank, then it doesn't trigger the setter. However, if there is a value in the RealmObject's property, it seems to fire a Xamarin.Forms.Platform.IOS.EntryRender:OnEditingChanged and attempt to set the same value back again. I consider this a bug in Xamarin Forms. It should not be propagating the unchanged value back as far as the viewmodel.