Andreas Hohn
Andreas Hohn

Reputation: 3

Secondary Tile Navigation Windows Phone 8

i have a problem when i navigate from a secondary tile into my app. The tile is created and has a navigation uri. Now i have a problem:

On "navigateTo" i test the navigationcontext for a specific string. If the string has the number i call this number. The first problem i have is when i navigate to an other page inside the app (after first click on secondary tile) and then return back to mainpage, it also tries to call the number, because the navigationcontext is the same as when i click the secondary tile. If i clear the navigationcontext after the first click on secondary tile the navigation works. But if i pause the app and than click the secondary tile again the navigationcontext is empty and so no number is called.

Create of tile

IconicTileData tileData = new IconicTileData
{
    Title = App.MainViewModel.SelectedPOI.Name,
    SmallIconImage = new Uri("/Assets/Images/feature.phone.png", UriKind.Relative),
    WideContent1 = App.MainViewModel.SelectedPOI.Name,
    WideContent2 = App.MainViewModel.SelectedPOI.Telefonnumber,
    WideContent3 = App.MainViewModel.SelectedPOI.Street
};
if (App.MainViewModel.SelectedPOI.Id == -1)
    tileData.BackgroundColor = Helper.GetColorFromHexString("#E46D1D");
else
    tileData.BackgroundColor = Helper.GetColorFromHexString("#4FAE32");

string SecondaryTileUriSource = String.Format("Source={0}&ID={1}", TILESTATUS, App.MainViewModel.SelectedPOI.Id);

//check if tile exist
ShellTile tile = Helper.FindTile(SecondaryTileUriSource);
if (tile == null)
{
    // having a unique NavigationUri is necessary for distinguishing this tile
    string tileUri = string.Concat("/MainPage.xaml?", SecondaryTileUriSource);
    ShellTile.Create(new Uri(tileUri, UriKind.Relative), tileData, true);
}

OnNavigateTo - MainPage

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    string status = String.Empty;
    if (NavigationContext.QueryString.TryGetValue("Source", out status))
    {
        MainPivot.SelectedItem = AlarmPivotItem;
        //App.MainViewModel.StartAlarm();
        //or
        //get the number from source/status...
        App.MainViewModel.CallNumber(12345);
        //NavigationContext.QueryString.Clear();
    }
}

Has anybody an example where e.g. a Number is called from a secondary tile and there are maybe at least 2 pages inside the app? Any other sugestion where the problem can be?

Thank you

Upvotes: 0

Views: 1912

Answers (1)

Kevin Gosse
Kevin Gosse

Reputation: 39007

Rather than clearing the navigation context, you can use the NavigationMode property to know whether it's a new navigation to the page (for instance, form the secondary tile) or if the user went back from another page:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
    {
        if (NavigationContext.QueryString.TryGetValue("Source", out status))
        {
            MainPivot.SelectedItem = AlarmPivotItem;
            //App.MainViewModel.StartAlarm();
            //or
            //get the number from source/status...
            App.MainViewModel.CallNumber(12345);
        }
    }
}

Upvotes: 1

Related Questions