---
title: "Radio Button Control Errors In WP8"  
description: "Radio Button Control Errors In WP8"  
author: "Anonymous User"  
published: 2014-10-20  
updated: 2014-10-20  
canonical: https://www.mindstick.com/forum/2425/radio-button-control-errors-in-wp8  
category: "c#"  
tags: ["c#", "exception"]  
reading_time: 3 minutes  

---

# Radio Button Control Errors In WP8

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to add a [radio button](https://www.mindstick.com/articles/12743/radio-button-in-android) check to my project but [finding it difficult](https://answers.mindstick.com/qa/98657/why-is-turkey-finding-it-difficult-to-join-the-european-union), can someone kindly help

Xaml

......................

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">\
<ScrollViewer>\
<StackPanel>\
<TextBlock x:Name="lblQuestion" Height="100" TextWrapping="Wrap" Margin="0,10,0,547"/>\
<[RadioButton](https://www.mindstick.com/blog/233/get-checked-radiobutton-using-javascript) x:Name="radA" Height="100" Margin="0,-570,0,389" />\
<RadioButton x:Name="radB" Height="100" Margin="0,-520,0,184"/>\
<RadioButton x:Name="radC" Height="100" Margin="0,-460,0,34"/>\
<RadioButton x:Name="radD" Height="100" Margin="0,-373,0,-116"/>\
\
<Button x:Name="btnStart" [Visibility](https://www.mindstick.com/blog/301300/how-to-improve-your-visibility-in-zero-click-search-results)="Visible" IsEnabled="True" Content="Start" HorizontalAlignment="Left" Margin="70,-70,0,0" VerticalAlignment="Top" Click="Button_Click" Grid.ColumnSpan="2"/>\
<Button x:Name="btnSubmit" Visibility="Visible" IsEnabled="True" Content="Submit" HorizontalAlignment="Right" Margin="0,-70,70,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2" Click="btnSubmit_Click" />\
\
<TextBlock x:Name="txtScore" TextWrapping="Wrap" Height="61" Width="378"/>\
\
</StackPanel>\
</ScrollViewer>\
\
</Grid>

Xaml.cs

........................

int score = 0;\
int i = -1;\
int a = 0;\
\
string[] [questions](https://www.mindstick.com/blog/124895/hp-hpe0-s54-cheat-sheet-exam-questions-bank-for-guaranteed-success) = new string[]\
{\
"1. Which Use of English [Question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) Paper Type is given to you?", \
"2. According to the writer, the exciting thing about Spaceship Earth is that it ",\
"3. The absence of instruction manual in Spaceship Earth has ",\
" 4. From the passage, it can be deduced that man ",\
"5. The writer's mood in the passage is that of ",\
};\
\
string[] answers = new string[] {\
"A TypeA ", "B. Type B ", "C. Type C ", "D. Type D ", \
"A has no instruction manual ", "B. is not difficult to maintain ", "C. is peculiar to other automobiles ", "D. is relatively easy to operate ", \
"A made the [operation](https://www.mindstick.com/forum/33917/how-to-callback-operation-using-delegate-in-c-sharp) of the Spaceship Earth difficult. ", "B. forced man to devise other means \r\n of travelling in Spacecraft", "C. challenged man's inquisitiveness", "D. made man helpless.", \
"A learns by [experiment](https://answers.mindstick.com/qa/43405/who-created-the-holy-experiment) and deduction ","B. learns by chance and accidentally ","C. is incapable of solving \r\n all his problems ","D. by his nature is in \r\n [constant](https://www.mindstick.com/forum/34714/difference-between-statics-vs-constant-in-c-sharp) search of knowlege ",\
"A non - commital ", "B. pessimism ", "C. optimism ", "D. frOstration ",\
\
};\
\
string[] quizAnswers = new string[] { "A TypeA", "A has no instruction manual", "C. challenged man's inquisitiveness", "A learns by experiment and deduction", "C. optimism ", };\
\
private void Button_Click(object sender, RoutedEventArgs e)\
{\
if (i < questions.Length)\
i++;\
//txtScore.Text = score;\
\
lblQuestion.Text = questions[i];\
\
radA.Content = answers[a];\
a++;\
radB.Content = answers[a];\
a++;\
radC.Content = answers[a];\
a++;\
radD.Content = answers[a];\
a++;\
\
\
btnStart.IsEnabled = true;\
\
btnSubmit.IsEnabled = true;\
\
\
}\
\
private void btnSubmit_Click(object sender, RoutedEventArgs e)\
{\
if (getSelectedAnswer().Equals(quizAnswers[i]))\
{\
MessageBox.Show("Correct");\
score++;\
txtScore.Text = Convert.ToString(score);\
btnSubmit.IsEnabled = false;\
\
\
btnStart.IsEnabled = true;\
btnStart.Content = "Next";\
}\
\
else\
{\
MessageBox.Show("Incorrect");\
score--;\
txtScore.Text = Convert.ToString(score);\
btnSubmit.IsEnabled = false;\
\
\
btnStart.IsEnabled = true;\
btnStart.Content = "Next";\
}\
\
}\
\
string getSelectedAnswer()\
{\
if (radA.Checked)\
return radA.Text.ToString();\
if (radB.Checked)\
return radB.Text.ToString();\
if (radC.Checked)\
return radC.Text.ToString();\
if (radD.Checked)\
return radD.Text.ToString();\
return "";\
}

## Replies

### Reply by Anonymous User

I'm not familiar with WP8 programming as such but, based on my knowledge of WPF, I'd guess that your getSelectedAnswer method should be coded as follows:\
string getSelectedAnswer(){ if (radA.IsChecked) // IsChecked rather than Checked return radA.Content.ToString(); // Content rather than Text if (radB.IsChecked) return radB.Content.ToString(); if (radC.IsChecked) return radC.Content.ToString(); if (radD.IsChecked) return radD.Content.ToString(); return "";}


---

Original Source: https://www.mindstick.com/forum/2425/radio-button-control-errors-in-wp8

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
