Reputation: 1395
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?
Upvotes: 0
Views: 99
Reputation: 3286
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.
Upvotes: 1