public partial class Page : UserControl
{
QA qa = new QA();
public Page()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
foreach (UIElement ui in QA.Children)
{
RadioButton rb = ui as RadioButton;
if (rb != null&&rb.IsChecked==true)
{
if (rb.Content.ToString() == qa.Answer)
{
MediaElement1.Play();
this.QA.Visibility = Visibility.Collapsed;
}
else {
HtmlPage.Window.Alert("错了!");
}
}
}
}
}
public class QA : INotifyPropertyChanged
{
string _question;
string _first;
string _second;
string _answer;
public string Question
{
get { return _question; }
set
{
_question = value;
Notify("Question");
}
}
public string First
{
get { return _first; }
set
{
_first = value;
Notify("First");
}
}
public string Second
{
get { return _second; }
set
{
_second = value;
Notify("Second");
}
}
public string Answer
{
get { return _answer; }
set
{
_answer = value;
Notify("Answer");
}
}
void Notify(string propertyName) {
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;