I am working on Xamarin forms project targeting iOS/Droid/UWP. We are building the app in a reactive manner and use direct model bindings. For instance, let's imagine we have the following code
public class Product : RealmObject
{
public string Name { get; set; }
}
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public static string LocalPath = "";
public MainPage()
{
InitializeComponent();
var realm = Realm.GetInstance(Path.Combine(LocalPath, "RealmSample.realm"));
realm.Write(() =>
{
realm.Add(new Product()
{
Name = "Test"
});
});
BindingContext = realm.All<Product>().FirstOrDefault();
}
}
And the following xaml file
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="RealmBindingSample.MainPage">
<StackLayout>
<Entry
Text="{Binding Name}"/>
</StackLayout>
</ContentPage>
Nothing is special in here. And this code works just fine on iOS/Droid and the data is persisted as soon as value of the Entry changes. However, on UWP as soon as the page is loaded I get the following exception
Cannot modify managed objects outside of a write transaction.
Is this expected behavior in UWP? Am I missing something.
I have installed the Realm.Database nuget version 3.4.0, and the FodyWeavers.xml files are present in all of the projects.