My MainPage.xaml is a pivot page with 3 PivotItems. Currently it is loading all of the necessary stuff for each of the PivotItems on the MainPage constructor. This is bad because it loads a lot of stuff that are not necessary.
Reading here and here suggests that I only load the first PivotItem and after it loads, load the rest of the items. Specifically :
Improve the performance of the pivot application by loading Pivot control content on-demand as opposed to loading everything at startup. One solution is to take the content from each PivotItem control and convert into UserControls. You can then subscribe to the LoadingPivotItem event on the root pivot control. Next, in the event handler, instantiate the proper UserControl and set it as the PivotItem content.
If I follow the suggestion:
private void OnLoadingPivotItem(object sender, PivotItemEventArgs e)
{
if (e.Item.Content != null)
{
// Content loaded already
return;
}
Pivot pivot = (Pivot)sender;
if (e.Item == pivot.Items[0])
{
e.Item.Content = new Page1Control();
}
else if (e.Item == pivot.Items[1])
{
e.Item.Content = new Page2Control();
}
else if (e.Item == pivot.Items[2])
{
e.Item.Content = new Page3Control();
}
}
I should use create class PageXControl ? Should it inherit somehow from main-page class ?
How do i take the content from each PivotItem control and convert into UserControls ?
Thanks