简体   繁体   中英

Navigate to XAML page when tile is pressed

I'm working in WP8 and I would like to know if it's possible to redirect the user to a custom page instead of the default MainPage when the application's tile is pressed.

For example, Toast Notifications have a NavigationUri that let's you enter a custom page to load after it's pressed. On tiles you can only get that information and not set it. So there is any other way or I'm missing something?

This is all covered nicely in this blog post: http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx?wa=wsignin1.0

Essentially the idea is to cancel the default navigation and then request a navigation to whichever Page you want.

When you are creating the tile, you are specifying the URL to which to navigate. Simply include an additional parameter, such as comingFrom and set it to tile - in the view OnNavigatedTo , check whether the parameter is present ( QueryString is your friend).

If it is - you navigated from a tile. If it's not - you didn't.

Sounds like you need a SecondaryTile . SecondaryTiles allow you to navigate to a different page than your "MainPage" if you so desire.

Here is an example of how to create a secondary tile

ShellTile tileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Page2.xaml"));
if (tileToFind == null) // have not pinned this page yet!
{
    // Create the tile if we didn't find it already exists.
    var tileData = new StandardTileData
    {
        Title = "Navigate To Page2",
    };

    // Create the tile and pin it to Start. This will cause a navigation to Start and a deactivation of our application.
    ShellTile.Create(new Uri("/Page2.xaml", UriKind.Relative), tileData);
}

This will place a new tile on the start screen and when you tap it, it will navigate to Page2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM