0

I've written a UWP app using VS2017 and Windows Template Studio. I've created multiple pages by using the Pivot Page Navigation Template.

Here is the basic code:

 public sealed partial class MainPage : Page, INotifyPropertyChanged
{
    public MainPage()
    {
        InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {

        ///Update controls here

        base.OnNavigatedTo(e);
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void Set<T>(ref T storage, T value, [CallerMemberName]string propertyName = null)
    {
        if (Equals(storage, value))
        {
            return;
        }

        storage = value;
        OnPropertyChanged(propertyName);
    }

    private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

I've added the "OnNavigatedTo" method, but it doesn't get called.

What am I doing wrong?

Trey Balut
  • 1,355
  • 3
  • 19
  • 39

1 Answers1

1

When you use Pivot Page Navigation Template to create the UWP project, it will create PivotPage in the View folder. And it will set the MainPage in the PivotItem in PivotPage.

The OnNavigatedTo invoked when the Page is loaded and becomes the current source of a parent Frame. When you switch the pages, the current source of a parent Frame will not change.

If you write OnNavigatedTo in the PivotPage, it will be called when you launched the app. You should be able to add Loaded event in the MainPage, it occurs when the page has been constructed and added to the object tree, and is ready for interaction.

Jayden
  • 3,276
  • 1
  • 10
  • 14
  • Thanks Jayden, I added the Page_Loaded to the Main Page and it gets called the initial load, but does not get called if I return I need to see every time Main Page is returned to from any of the individual alternate pages. – Trey Balut Oct 10 '17 at 15:14
  • @TreyBalut You should be able to use `SelectionChanged` event in `Pivot`, it occurs when the selected PivotItem changed. – Jayden Oct 11 '17 at 01:33