返回第一页后,第二页不刷新数据

时间:2015-05-07 13:02:50

标签: c# windows-phone-8.1 winrt-xaml win-universal-app

我在页面1上有一个列表,使用MVVM模式填充第2页的详细信息。最初,当我在第1页上选择一个项目时,它可以导航到第2页并显示详细信息。点击“返回”按钮后,如果我从第1页中选择了另一个项目,它将导航到第2页,但会显示以前的数据,而不是新选择项目的数据。

有谁能告诉我我做错了什么?

以下是代码,第1页

private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
    var getscoreDataGroups = await GetScoreDataSource.GetGroupsAsync();
    this.DefaultViewModel["Groups"] = getscoreDataGroups;         
}

private void lvLiveMatch_ItemClick(object sender, ItemClickEventArgs e)
{
    var itemId = ((LiveDataItem)e.ClickedItem).MatchID;
    if (!Frame.Navigate(typeof(MatchPage), itemId))
    {
       //throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage"));
    }
}

以下是第2页的代码

private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {
        string matchid = e.NavigationParameter.ToString();
        if (matchid != "")
        {
            var getscoreMatchGroups = await GetScoreMatchSource.GetGroupsAsync(matchid);
            this.DefaultViewModel["Groups"] = getscoreMatchGroups;
        }
    }

在调试时,我得到了正确的值,但第2页没有刷新新数据。

1 个答案:

答案 0 :(得分:1)

解决方案是在重新加载页面时引发ViewModel的PropertyChanged

您可以在msdn

中找到一个简单的示例here