I would like to allow a user to be able to pin a ConnectionSettingsTask item to the start page, and then navigate to that specific ConnectSettingsTask by pressing the corresponding tile on the Start page. My issue is, once the user has navigated to the corresponding ConnectionSettingsTask page, the user cannot directly navigate back to the start page using the hardware back button. For some reason, the application keeps loading the same ConnectionSettingsTask page over and over. My implementation as of now is as follows:
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;
}
So, essentially the creation of the tile and pinning the secondary tile to the start screen works, as well as loading the WiFI ConnectionSettingsTask from the secondary tile. But when I try to navigate back from the ConnectionSettingsTask page, it just keeps reloading that page. How might I fix this issue according to the Windows Phone hardware back button certification requirements (must return to start screen in this scenario)?
OnNavigatedTo
method? – dotNETbeginner