0

Let's say I have a specific page, SecondaryTile.xaml. From this page I pin a secondary tile to the startscreen. Now if I tap on the secondary tile I want it to open the SecondaryTile.xaml.

In WP8.0 this was possible by setting the URI of Shell.Create. E.g.:

ShellTile.Create(new Uri("/SecondaryTile.xaml?Parameter=FromTile", UriKind.Relative), NewTileData);
        }

But it looks like this is not supported anymore in WinRT.

I saw a sample that uses the parameter to launch (it fetches the parameter in the OnNavigatedTo on the Mainpage.xaml.cs), but with the new app behaviour the app is being suspended so OnNavigatedTo does not always trigger.

Hope someone can help.

Kind regards, Niels

Niels
  • 2,496
  • 5
  • 24
  • 38

2 Answers2

0

Shouldn't this be done as application logic?

Examine the LaunchActivatedEventArgs parameter within the OnLaunched method of your app's code-behind:

protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
    ApplicationData.Current.LocalSettings.Values[Constants.APP_PARAMETERS] = args.Arguments;

    // Do not repeat app initialization when already running, just ensure that
    // the window is active
    if (args.PreviousExecutionState == ApplicationExecutionState.Running)
    {
        Window.Current.Activate();

        await ViewManager.Instance.LaunchView();

        return;
    }

Consider implementing some type of ViewManager for managing the startup view:

public class ViewManager
{
    #region Singleton
    private ViewManager()
    {
    }

    static ViewManager _viewManager = null;

    public static ViewManager Instance
    {
        get
        {
            if (_viewManager == null)
            {
                _viewManager = new ViewManager();
            }

            return _viewManager;
        }
    }
    #endregion

    public async Task LaunchView()
    {
        bool displaySubheader = false;
        var displayBackbutton = false;

        var arguments = ApplicationData.Current.LocalSettings.Values[Constants.APP_PARAMETERS] as string;
        var argumentsExist = !string.IsNullOrEmpty(arguments);

        if (!argumentsExist)
        {
            await UIServices.Instance.Load(typeof(HomePage), null, displaySubheader, displayBackbutton);
        }
        else
        {
            displaySubheader = true;
            displayBackbutton = false;
            await UIServices.Instance.Load(typeof(GroupPage), arguments, displaySubheader, displayBackbutton);

            var groupId = new Guid(arguments);

            await ReadPost(groupId);
        }
    }

. . .

Here's how I create secondary tiles:

SecondaryTile secondaryTile =
                    new SecondaryTile(group.GroupId.ToString(),
                                        group.Name,
                                        group.Name,
                                        group.GroupId.ToString(),
                                        TileOptions.ShowNameOnWideLogo,
                                        new Uri("ms-appx:///Assets/Logo.png"),
                                        new Uri("ms-appx:///Assets/WideLogo.scale-100.png"));

            var successful = await secondaryTile.RequestCreateAsync();
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
0

You are not able to navigate directly to another page from the OnNavigatedTo event. However you can add the navigation as a queued event on your UI thread.

In your OnNavigatedTo eventhandler, check for the following (Your test might need to be a bit more sophisticated as not all eventualities are accounted for in this example, such as for example e.Parameters beeing null).

if (e.Parameter.ToString().Contains("something_from_secondary_tile_arguments") && (e.NavigationMode == NavigationMode.New))
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Current.Frame.Navigate(typeof(Transactions), "data_for_your_sub_page"); });
}

Also, you need to specify the Arguments property when you create your SecondaryTile.

More info here: Not able to navigate to pages on Windows Metro App using c#

Community
  • 1
  • 1