【问题标题】:Nested property changed notifications for a Realm object领域对象的嵌套属性更改通知
【发布时间】:2017-10-25 07:52:14
【问题描述】:

我在我的 Xamarin Forms 项目中使用 Realm 和 PropertyChanged Fody。我有两个模型 - PersonFriend,如下所示。 person 对象具有对 friend 对象的引用。我已将personfriendAge 绑定到两个单独的标签。现在,当我使用PropertyChanged Fody 时,每当Age 更改时,它都应该更新标签。但只有第一个标签 (person's Age) 更新,第二个标签 (person's friend's Age) 不会。当朋友的年龄发生变化时如何发出通知?

    [ImplementPropertyChanged]
    public class Person : RealmObject
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public Friend friend { get; set; }
    }

    [ImplementPropertyChanged]
    public class Friend : RealmObject
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }

我将它们绑定在 Xaml 中,如下所示。

    <Label Text="{Binding person.Age}" />
    <Label Text="{Binding person.friend.Age}" />

【问题讨论】:

    标签: data-binding xamarin.forms realm inotifypropertychanged fody-propertychanged


    【解决方案1】:

    您不需要 PropertyChanged.Fody,因为 Realm 内置了通知。我的猜测是它干扰了 Realm 的逻辑,因为您所描述的应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-12
      • 1970-01-01
      • 2021-10-27
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多