0
votes

I'm trying to use the int buttonCount to be added to listbox on another page. I used public static int buttonCount = 15; to make my butttonCount int available on the MainPage.xaml.cs, but when I try to use it on highScore.xaml.cs it seems to not show up. My name space is Potato_v2 and class is just the name of the page. Here's some of my code for gamePage.

    public static int buttonCount = 0;
    string stringButtonCount = "";
    Random rnd = new Random();
    int count = 15;



    void countDownTimerEvent(object sender, EventArgs e)
   {
    txtCountdown.Text = count + " Seconds Remaining";


        if (count > 0)
        {
        count--;
        }
        if (count == 0)
        {
            countDownTimer.Stop();
            NavigationService.Navigate(new Uri("/highScore.xaml", UriKind.Relative));
            count = 15;
            buttonCount = 0;
            stringButtonCount = "";
        }

   }

Code for MainPage: Can't get the first line to go down for some reason.

private void newToDoAddButton_Click(object sender, RoutedEventArgs e)

    {
        ToDoItem newToDo = new ToDoItem { ItemName = newToDoTextBox.Text };
        ToDoItems.Add(buttonCount);
        toDoDB.ToDoItems.InsertOnSubmit(newToDo);

    }
1

1 Answers

2
votes

You can't access a variable outside its class without Class name (static member) or instance. So this line:

ToDoItems.Add(buttonCount);

Should be:

ToDoItems.Add(ToDoItem.buttonCount);