1

I'm trying to make a quiz program. I've got the questions an answers in lists and trying to a create a popup box for each question, let the user make a choice, and then go onto the next popup question.

Here's my C#:

public partial class Test

{

Popup p = new Popup();

  public Test()

  {

    InitializeComponent();
    testvalues = GetQuestions();

    int numberofquestions;
    numberofquestions = testvalues.Count / 6;

    for (int i = 0; i < numberofquestions; i++)
    {
    runtest(i, numberofquestions);
    }
  }

  private void runtest(int questionnumber,int numberofquestions)
  {

    StackPanel testpanel = new StackPanel();
    TextBlock textblockquestion = new TextBlock();
    TextBlock textblockscore = new TextBlock();

    RadioButton buttona = new RadioButton();
    RadioButton buttonb = new RadioButton();
    RadioButton buttonc = new RadioButton();
    RadioButton buttond = new RadioButton();

....blah blah blah fill stuff into buttons and boxes...

    testpanel.Children.Add(textblockscore);
    testpanel.Children.Add(textblockquestion);
    testpanel.Children.Add(buttona);
    testpanel.Children.Add(buttonb);
    testpanel.Children.Add(buttonc);
    testpanel.Children.Add(buttond);
    border.Child = testpanel;

    p.Child = border;
    p.IsOpen = true;

....blah blah blah I do if tests to see if they button they choose corresponds to the correct answer or not.... For example I have things like this for each of the four buttons depending on my if statements

    (if right)
     buttonb.Click += new RoutedEventHandler(Right_Click);
     else
     buttonb.Click += new RoutedEventHandler(Wrong_Click);

  }

  void Wrong_Click(object sender, RoutedEventArgs e)
  {
    countwrong++;
    p.IsOpen = false;
  }

  void Right_Click(object sender, RoutedEventArgs e)
  {
    countright++;
    p.IsOpen = false;
  }

}

So right now the program shows the first popup box. I click on an answer choice, the popup box closes, and then nothing. I don't understand why it is not advancing in my for loop at the beginning to create the next popup box. Is there something wrong with the organization of my code or is it a syntax problem? Do I need to break down my popup into smaller steps?

tshepang
  • 12,111
  • 21
  • 91
  • 136

1 Answers1

0

The Popup may not be actually closing. Have you tried, instead of the loop, opening the next Popup in the closed event of the current popup?

I've found something that can help you, at least, I know it's not the exact answer to your question, but it may help: How to close popup in silverlight?

Community
  • 1
  • 1
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • No that wasn't what I needed. I finally had to restructure my code. I put a call for "runtest" inside my Right_Click and Wrong_Click subroutines and eliminated the for loop. This way each click of the radio button generates the next question. – Samantha Guillot Jul 03 '11 at 17:30