アプリケーションにセカンダリタイルを実装したので、ユーザーはセカンダリタイルをスタート画面に固定し、それに応じてアプリケーションのそれぞれのページに移動できます。この実装は、ユーザーが固定されたセカンダリタイルから特定のページに移動した後にハードウェアに戻るボタンを押した場合を除いて、問題なく機能します。何も起こりませんか?実際、ユーザーはスタート画面から表示されていますが、アプリケーションの前のページが実際に表示されます。ユーザーが期待するように実際にスタート画面に戻るための適切な方法は何でしょうか(これが適切なバックスタックナビゲーションであると想定しています)?
私が持っているのは次のとおりですが、ユーザーがスタート画面の固定タイルから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イベントでクエリ文字列がチェックされ、クリックされたセカンダリタイルに基づいてそれぞれのページが読み込まれます。これが実行され、それぞれのページがロードされると、標準のバックスタック動作に従うためにスタート画面に戻るために戻るボタンを押すことができなくなります。どうすればこれを修正できますか?