Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a parameter passed between UWP Pages

Tags:

c#

oop

windows

uwp

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

like image 578
gorokizu Avatar asked Jan 16 '16 21:01

gorokizu


1 Answers

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);
}
like image 186
Vadim Martynov Avatar answered Oct 05 '22 11:10

Vadim Martynov