I need to pass parameter between page but Programmatic Navigation with a Pack URI (https://learn.microsoft.com/en-us/dotnet/framework/wpf/app-development/navigation-overview#programmatic-navigation-with-a-pack-uri)
Note: I don't want to use the constructor to pass the parameter
Currently I do this:
Uri uri = new Uri("AnotherPage.xaml", UriKind.Relative);
this.NavigationService.Navigate(uri, parameter);
but once again microsoft forgot to put an example on how to receive the data in the other page.
I try this in the second page to receive the parameter:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
NavigationService.LoadCompleted += NavigationService_LoadCompleted;
}
private void NavigationService_LoadCompleted(object sender, NavigationEventArgs e)
{
throw new NotImplementedException();
}
but it's not working.
In this post (How to pass values (parameters) between XAML pages?) in the second point use
example: 2. Using NavigationEventArgs
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
// NavigationEventArgs returns destination page
Page destinationPage = e.Content as Page;
if (destinationPage != null) {
// Change property of destination page
destinationPage.PublicProperty = "String or object..";
}
}
but OnNavigatedFrom doesn't exist
In this post use a global variable like(How to pass values between two pages in WPF)
string myText = (string)Application.Current.Properties["test"];
maybe this is the solution if there does not exist a better way
here (Passing data between pages in wpf) no example
I don't know maybe I'm missing something about WPF Navigation (https://learn.microsoft.com/en-us/dotnet/framework/wpf/app-development/navigation-overview) Can someone point me in the right direction or am I just wasting my time and this is impossible to do.
I'm sorry for my English, I don't speak