我尝试使用我的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);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)