0
I’m looking up examples of browsing between pages in a desktop application. Let’s assume that the navigation is done from a Listbox always visible in 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 in this case is about memory management. Won’t this type of approach create an undetermined number of instances of the various invoked page? I ask this because, by activating the navigation bar, I find the different instances of the same class. Something like this won’t be right anymore?
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();