Windows-XAML / Template10

Making Windows 10 apps great again
Apache License 2.0
1.41k stars 389 forks source link

Navigation Services Not working #1720

Open dksingh605 opened 4 years ago

dksingh605 commented 4 years ago

Hi i am using these two methods(OnNavigatedToAsync,OnNavigatedFromAsync) in the view model,

when i am navigating to NavigateService then these two method was called. but when i am navigating using Frame.Navigate method this will not work. please help

JerryNixon commented 4 years ago

Assuming you are using version 2.0.1?

I think you will need to show me a little more code.

That said, let me ask this though:

Are you implementing the interfaces? This is important.

Here's the source: INavigatedAware or INavigatedAwareAsync

It's easiest if you use the ViewModelBase class, but that's not required.

Here's a sample view-model:

public class MyViewModel : INavigationAware
{
    public void OnNavigatedFrom(INavigationParameters parameters)
    {
        throw new NotImplementedException();
    }

    public void OnNavigatedTo(INavigationParameters parameters)
    {
        throw new NotImplementedException();
    }

    public void OnNavigatingTo(INavigationParameters parameters)
    {
        throw new NotImplementedException();
    }
}

The framework only knows to call these methods if it determines the interfaces are present.

If you are interested, here's where the framework actually does that.