F4Ke
F4Ke

Reputation: 1751

c# UWP - Tiles OnNavigatedTo doesn't keep variables in MainPage

I've just integrated the Tile creation within my application.

The Tiles are created just fine. I set a string parameter to use when the app is launched from the Tile.

in my Class.xaml.cs :

            string tileActivationArguments = "test_params";

            SecondaryTile s = new SecondaryTile(name_clean,
                                                                name,
                                                                name,
                                                                tileActivationArguments,
                                                                TileOptions.ShowNameOnLogo,
                                                                logo);


            s.DisplayName = name;
            s.ForegroundText = ForegroundText.Dark;
            bool isPinned = await s.RequestCreateForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Below);

And it's pinned with succes.

But when I click on the Tile from the startup menu, I arrive on MainPage.OnNavigatedTo and here, the params are existing, and I set them on a local variable.

MainPage.xaml.cs

    private string params;

    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        var parametters = e.Parameter as string;
        if (parametters != null && parametters != "")
        {
          params = parametters ; // WORKS: here params has the good parameter string
           ....
         }
     }

then, it goes into MainPage()

    public MainPage()
    {
        this.InitializeComponent();

       // here the params seems to be reset
       Debug.WriteLine(params); // Exception
       // params == null 
    ... 
     }

Any Ideas ?

Upvotes: 0

Views: 66

Answers (1)

thang2410199
thang2410199

Reputation: 1942

The constructor always called first, before OnNavigatedTo At this point in time, params still null

Upvotes: 0

Related Questions