I'm searching for examples of browsing between pages in a desktop application. Let's assume that navigation is done from a ListBox always visible in the Ui. Most examples do something like this to switch to a particular page:
private void myListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = myListBox.SelectedIndex;
switch(index+1)
{
case 1:
mainFrame.Content = new Page1();
break;
case 2:
mainFrame.Content = new Page2();
break;
case 3:
mainFrame.Content = new Page3();
break;
}
}
My question here is about memory management. This kind of approach will not create an undetermined number of instances of the multiple page invoked? I ask this because, by activating the navigation bar, I find the different instances of the same class. Is not something more correct?
private void myListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = myListBox.SelectedIndex;
switch(index+1)
{
case 0: mainFrame.Content = p0;
break;
case 1:
mainFrame.Content = p1;
break;
case 2:
mainFrame.Content = p2;
break;
case 3:
mainFrame.Content = p3;
break;
}
}
Page0 p0 = new Page0();
Page1 p1 = new Page1();
Page2 p2 = new Page2();
Page3 p3 = new Page3();