我在我的應用程序中實現了次要圖塊,因此用戶可以將次要圖塊固定到開始屏幕,然後相應地導航到我的應用程序中的相應頁面。這個實現工作正常,除了當用戶在從固定的次級磁貼導航到特定頁面後點擊後退硬件按鈕時,什麼都沒有發生?事實上,儘管用戶來自開始屏幕,但實際上只顯示應用程序中的上一頁。真正返回到開始屏幕的正確方法是什麼,因爲用戶會期望會發生(我認爲這將是適當的後退堆棧導航)?如何在從次要圖塊導航到頁面時管理返回堆棧
我有如下,但只適用於正常頁面導航的情況下,而不是當用戶從開始屏幕固定瓷磚導航到SharePage時。
MainPage.xaml.cs中
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string _title = null;
NavigationContext.QueryString.TryGetValue("Param", out _title);
if (_title != null)
{
switch (_title)
{
case "status":
this.NavigationService.Navigate(new Uri("/Views/ShareStatusPage.xaml", UriKind.Relative));
break;
case "link":
this.NavigationService.Navigate(new Uri("/Views/ShareLinkPage.xaml", UriKind.Relative));
break;
}
}
}
private void CreateLiveTile(TileItem item)
{
string tileParameter = "Param=" + item.Title.ToString();
ShellTile Tile = CheckIfTileExist(tileParameter); // Check if Tile's title has been used
if (Tile == null)
{
try
{
var LiveTile = new StandardTileData
{
Title = item.TileName,
//BackgroundImage = ((System.Windows.Media.Imaging.BitmapImage)hubtile.Source).UriSource,
BackgroundImage = new Uri(item.ImageUri.ToString(), UriKind.Relative),
//Count = 1,
BackTitle = item.TileName,
//BackBackgroundImage = new Uri("", UriKind.Relative),
BackContent = item.Message,
};
ShellTile.Create(new Uri("/MainPage.xaml?" + tileParameter, UriKind.Relative), LiveTile); //pass the tile parameter as the QueryString
}
catch (Exception)
{
MessageBox.Show("This tile could not be pinned", "Warning", MessageBoxButton.OK);
}
}
else
{
MessageBox.Show("This tile has already been pinned", "Notice", MessageBoxButton.OK);
}
}
private ShellTile CheckIfTileExist(string tileUri)
{
ShellTile shellTile = ShellTile.ActiveTiles.FirstOrDefault(tile => tile.NavigationUri.ToString().Contains(tileUri));
return shellTile;
}
SharePage.xaml.cs
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
//return to the previous page in the phones back stack?
if (NavigationService.CanGoBack)
{
e.Cancel = true;
NavigationService.GoBack();
}
//else
//{
// ??
//}
}
到目前爲止,CreateLiveTile()
方法創建瓷磚二次,然後當按下該圖塊,被的MainPage導航到並然後在MainPage OnNavigatedTo事件中檢查查詢字符串,然後根據單擊的次級磁貼加載相應的頁面。一旦執行此操作並且各個頁面已經加載,我就不能再按回退按鈕返回到開始屏幕以遵循標準的堆疊行爲。我怎樣才能解決這個問題?
@感謝您的優秀建議,它的效果非常好! – Matthew 2012-08-16 20:55:21