【发布时间】:2016-05-29 18:17:01
【问题描述】:
我尝试使用 ViewModel 中的 MessagingCenter 实现 MVVM。 我收到以下错误,因为多个线程收到相同的消息“ClearStackLayout”并且不等待回调的结束:
索引超出了数组的范围。
这是我的查看代码:
public partial class LibraryChoicePage : DefaultBackgroundPage {
private Object thisLock = new Object();
public LibraryChoicePage() {
InitializeComponent();
/* ClearStackLayout */
MessagingCenter.Subscribe<LibraryChoiceViewModel>(this, "ClearStackLayout", (sender) => {
lock (thisLock) {
this._choices.Children.Clear();
}
});
/* AddToStackLayout */
MessagingCenter.Subscribe<LibraryChoiceViewModel, View>(this, "AddToStackLayout", (sender, arg) => {
lock (thisLock) {
this._choices.Children.Add(arg);
}
});
}
}
【问题讨论】:
标签: c# xamarin xamarin.forms