我正在使用Windows 8 Metro Newsreader-App(使用C#和XAML)。我在Grouped Items Page
(模板)上顯示飼料項目。點擊將用戶轉發到詳細信息頁面,我將其作爲Split Page
實施。因此,我有一個Image-Gallery,用戶可以從這個DetailPage導航(並返回)。這工作正常。在ItemDetailPage上,我必須分配LoadState
函數中的數據。模板我提供以下解決方案:在使用SplitPage的LoadState中的錯誤行爲
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// TODO: Assign a bindable group to this.DefaultViewModel["Group"]
// TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
if (pageState == null)
{
// When this is a new page, select the first item automatically unless logical page
// navigation is being used (see the logical page navigation #region below.)
if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null)
{
this.itemsViewSource.View.MoveCurrentToFirst();
}
}
else
{
// Restore the previously saved state associated with this page
if (pageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null)
{
// TODO: Invoke this.itemsViewSource.View.MoveCurrentTo() with the selected
// item as specified by the value of pageState["SelectedItem"]
}
}
}
我所做的是以下幾點:
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
if (pageState == null)
{
// When this is a new page, select the first item automatically unless logical page
// navigation is being used (see the logical page navigation #region below.)
if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null)
{
this.itemsViewSource.View.MoveCurrentToFirst();
}
}
else
{
// Restore the previously saved state associated with this page
if (pageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null)
{
this.itemsViewSource.View.MoveCurrentTo(pageState["SelectedItem"]);
}
}
var item = ArticleDataSource.GetItem((int)navigationParameter);
if (item != null)
{
this.DefaultViewModel["Group"] = item.Group;
this.DefaultViewModel["Items"] = item.Group.Items;
if (this.itemsViewSource.View != null) this.itemsViewSource.View.MoveCurrentTo(item); // remove?
// Register this page as a share source.
this.dataTransferManager = DataTransferManager.GetForCurrentView();
this.dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.OnDataRequested);
}
}
- 如果我從OverviewPage導航到DetailsPage所選擇的項目(A)所示。
- 我從列表中選擇一個其他項目並顯示正確的詳細信息(B)。
- 如果我從DetailsPage導航到GalleryPage,則會顯示正確項目(B)的圖像。
- 如果我現在回到(DetailsPage)而不是最後選擇的項目(B),但是我選擇了(A)進入DetailsPage的項目。
我意識到我更改了訂單(由模板建議)並添加了if (this.itemsViewSource.View != null) this.itemsViewSource.View.MoveCurrentTo(item);
這一事實,我可能會更好地刪除它。
我認爲問題(在步驟4中描述)是this.itemsViewSource.View
爲空,因此(邏輯上)this.itemsViewSource.View.MoveCurrentTo(pageState["SelectedItem"])
沒有得到執行。不幸的是,我無法找出爲什麼或如果這是錯誤。
任何幫助或鏈接到教程(這可以解決我的問題)非常感謝!謝謝。