我正在制作Xamarin应用,并且在我的ObservableCollection
中有一个Booking
实体BookingViewModel
。
public ObservableCollection<Data.Entities.Booking> Bookings { get; set; }
然后我有一个像这样设置Bookings
数据的方法。
this.Bookings = BookingService.GetBookings(this.SearchCriteria);
然后,我在Bookings
ObservableCollection
的XAML视图上单击了行为,该行为在单击时显示了使用Rg.Plugins.Popup的Popup。弹出窗口仅包含属性Bay
的输入字段和保存按钮。
但是,此弹出代码在称为BayUpdatePopupViewModel
的单独ViewModel中进行。在这里,我可以更新所选预订中的Bay字段。这样可以正确保存,但随后我需要通知Bookings
ObservableCollection
,其中一项已被更新,而不必刷新列表。
这是我在Command
中保存的BayUpdatePopupViewModel
public ICommand OnSave => new Command(async () =>
{
var response = await BookingService.Update(this.Booking));
if (response.IsSuccessStatusCode)
{
await PopupNavigation.Instance.PopAsync();
}
});
我想在IsSuccessStatusCode
之后调用通知代码。
我的Booking
实体继承自INotifyPropertyChanged
,但我不知道如何从其他ViewModel引用Bookings
ObservableCollection
。我将如何实现?
编辑:
现在,在我的ShowPopup命令中,我将Changed
方法设置为BayUpdatePopupViewModel
。当我更新Bay值时,此Changed
方法实际上是在通过不使用新值更新UI来触发的。
public ICommand ShowPopupCommand => new Command<Data.Entities.Booking>(async booking =>
{
this.BayUpdatePopupViewModel = new BayUpdatePopupViewModel(booking);
this.BayUpdatePopupViewModel.PropertyChanged += Changed;
await PopupNavigation.Instance.PushAsync(new BayUpdatePopupPage(this.BayUpdatePopupViewModel));
});
public void Changed(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(nameof(this.Bookings));
}