gorokizu
gorokizu

Reputation: 2588

Accessing a parameter passed between UWP Pages

Currently developing an Universal Windows Platform Application, can't access the parameter on the navigatedto page

Code for passing the parameter:

var ente = this.DataGrid.SelectedItem as Ente;
            var Id = ente.Id;
            Frame.Navigate(typeof(EntiEdit), Id);

and here's the "NavigatedTo" page

protected override void OnNavigatedTo(NavigationEventArgs e) {
         string Id = e.Parameter as string;
        }

How can i use this string in my other methods? The event override is protected so i can't access its content.

Thanks in advance

Upvotes: 9

Views: 9273

Answers (1)

Vadim Martynov
Vadim Martynov

Reputation: 8892

You should save the parameter to the class field or property to have access to it:

public class EntiEdit : Page
{
    private string _entityId;

    protected override void OnNavigatedTo(NavigationEventArgs e) 
    {
        _entityId = e.Parameter as string;
    }
}

If you need to initiate some handling after navigating the page you can do it from the event handler:

protected override void OnNavigatedTo(NavigationEventArgs e) 
{
    var entityId = e.Parameter as string;
    EntityData = LoadEntity(entityId);
    DoSomeOtherRoutine(entityId);
}

Upvotes: 18

Related Questions