我有一個影院列表,我從應用程序創建了一個輔助磁貼,以直接導航到特定的影院。我通過劇院的id在查詢字符串:來自磁貼錯誤的Windows Phone鏈接
我加載從WCF服務劇院在文件「MainViewModel.cs」
在我的主頁,我有劇院的名單,我可以瀏覽到詳細信息頁面。
但是,當我想從瓦導航,我有一個錯誤...
磁磚:
ShellTile.Create(new Uri("/TheaterDetails.xaml?selectedItem=" + theater.idTheater, UriKind.Relative), tile, false);
我TheaterDetails頁:
public partial class TheaterDetails : PhoneApplicationPage
{
theater theater = new theater();
public TheaterDetails()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
if (DataContext == null)
{
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
int index = int.Parse(selectedIndex);
theater = (from t in App.ViewModel.Theaters
where t.idTheater == index
select t).SingleOrDefault();
DataContext = theater;
....
....
....
錯誤:
https://dl.dropboxusercontent.com/u/9197067/error.png
如果數據未加載,就像...
您是否知道問題的來源?
的解決辦法是容易的,但我是一個初學者...也許是因爲我異步加載的數據和應用程序不等到它完成...
感謝
編輯:
我LoadData()方法:
public void LoadData()
{
client.GetTheatersCompleted += new EventHandler<ServiceReference1.GetTheatersCompletedEventArgs>(client_GetTheatersCompleted);
client.GetTheatersAsync();
// Other get methods...
this.IsDataLoaded = true;
}
private void client_GetTheatersCompleted(object sender, ServiceReference1.GetTheatersCompletedEventArgs e)
{
Theaters = e.Result;
}
坦克你非常多的答案,我編輯我的問題,你能不能幫我用異步/等待的方法?我不知道該怎麼做,因爲這是一個無效的方法 – user2157493