我想让用户能够将 ConnectionSettingsTask 项目固定到起始页面,然后通过按起始页面上的相应磁贴导航到该特定的 ConnectSettingsTask。我的问题是,一旦用户导航到相应的 ConnectionSettingsTask 页面,用户就无法使用硬件后退按钮直接导航回起始页面。出于某种原因,应用程序不断地反复加载相同的 ConnectionSettingsTask 页面。我现在的实现如下:
MainPage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string _title = null;
NavigationContext.QueryString.TryGetValue("Param", out _title);
if (_title != null)
{
ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
switch (_title)
{
case "WiFi":
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
connectionSettingsTask.Show();
break;
...
}
try
{
//NavigationService.RemoveBackEntry();
//_title = null;
NavigationContext.QueryString.Remove(_title);
}
catch(InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void CreateLiveTile(TileItem item)
{
var title = item.Title.ToString();
string tileParameter = "Param=" + item.Title.ToString();
ShellTile Tile = CheckIfTileExist(tileParameter); // Check if Tile's title has been used
if (Tile == null)
{
//choose which original background tile image to use
switch (title)
{
case "WiFi":
background = new Uri("/Images/Mode/Mode_WiFi.png", UriKind.Relative);
break;
...
}
try
{
var LiveTile = new StandardTileData
{
Title = item.TileName,
BackgroundImage = background,
BackTitle = item.TileName,
//BackBackgroundImage = new Uri("/background.png", UriKind.Relative),
BackContent = item.Message,
};
ShellTile.Create(new Uri("/View/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;
}
因此,基本上可以创建磁贴并将辅助磁贴固定到开始屏幕,以及从辅助磁贴加载 WiFI ConnectionSettingsTask。但是当我尝试从 ConnectionSettingsTask 页面导航回来时,它只会不断重新加载该页面。我如何根据 Windows Phone 硬件后退按钮认证要求解决此问题(在这种情况下必须返回到开始屏幕)?