我的視圖調用ViewModel中的方法來獲取數據。獲取數據後,我根據從ViewModel返回的數據構建View(Grid)。從ViewModel回調到視圖
getData()View Model中的方法在BackgroundWorker線程中運行。現在我的問題是如何在View完成獲取所有數據後返回View?
ViewModel
{
getData()
{
WorkerMethods()
WorkerCompletedMethod()
{
Refresh()
}
}
Refresh()
{
WorkerMethod()
WorkerCompleted()
{
data - Retrieved.
This is where all the calls are really DONE
}
}
}
從查看,我會打電話
View()
{
VM.getData()
//Before I call this method, I want to make sure Refresh() is completed
BuildUI()
}
我只想要VM.getData(後要執行的BuildUI()方法)完全執行,又與刷新完成()方法,這也是我需要能夠動態構建UI的數據。
這就是我要做的。請糾正我,如果這是不正確的做法。
在後面的視圖代碼,
View
{
public delegate void DelegateRefresh();
Init()
{
DelegateRefresh fetcher = RefreshData;
fetcher.BeginInvoke(null, null);
}
public void RefreshData()
{
_viewModel.GetData();
**while (_viewModel.IsBusy)**
{
continue;
}
BuildUI();
}
BuildUI()
{
//Code to build the UI Dynamically using the data from VM.
}
你需要明確具體的關於你的要求,否則你不會得到有用的答案。請更新您的問題。 – Bernard 2012-08-10 02:20:00
對不起,我更新了我的oroginal Post,請讓我知道如果它不明確。 – nmgans 2012-08-10 02:29:36