In the current page (which is contained inside a frame inside MainWindow) I have this happen when I click a button:
for (int i = 0; i < mw.pizzas.Length + 1; i++)
{
if (i == 10)
{
MessageBoxResult result = MessageBox.Show("You can't order more than 10 pizzas");
break;
}
if (mw.pizzas[i] == null)
{
mw.pizzas[i] = pizza;
break;
}
}
NavigationService.Content = new AnotherPage();
The mw.pizzas string array contains 10 (I think undefined) variables. I have defined it in MainWindow:
public string[] pizzas = new string[10];
I have defined it on the current page, like so:
MainWindow mw = new MainWindow();
This loop increments by defining these 10 slots with the contents of the variable "pizza". When all of the indexes of the array are defined, a message should pop up. However, this message never shows up. What am I doing wrong here?
Edit: This is just a wild guess. It might have to do with me creating a new CurrentPage
every time this page is navigated to. Every time one of these indexes is defined, this navigates back to the previous page, then uses NavigationService.Content = new CurrentPage();
Edit 2: Looks like there is something wrong with the second statement. mw.pizzas[0]
is null, then gets the contents of pizza in it, then somehow goes back to being null after the program exits the page and enters it once again.
Edit 3: I tried to make the pizzaIDs array static, but I get the following error: Member 'MainWindow.pizzaIDs' cannot be accessed with an instance reference; qualify it with a type name instead