In several online examples I found this:
public partial class ForecastPage : PhoneApplicationPage
{
Forecast forecast;
public ForecastPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// code here
}
}
but in others I found the use of the Load
event like
public partial class Person : PhoneApplicationPage
{
private PersonViewModel _ViewModel;
public Person()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(SearchView_Loaded);
}
void SearchView_Loaded(object sender, RoutedEventArgs e)
{
// code here
}
}
I know that OnNavigatedTo
fires before the Load
event, but both fire before the UI is drawn into the phone, so my question is Is there any advantage in use one method from the other?
I'd disagree with Tigran.
public View()
{
InitializeComponent();
personList.ItemsSource = PersonDataSource.CreateList(100);
Loaded += (sender, args) => Debug.WriteLine("Loaded");
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Debug.WriteLine("Navigated");
}
While jumping forward-backward, output is
Navigated Loaded Navigated Loaded Navigated Loaded
So, OnNavigated
is called when page navigation is done, but before(during) page controls are loaded, while Loaded
is called when page is ready and all controls are loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With