silverlight 3 中的路由事件?

发布于 2024-12-03 12:44:16 字数 169 浏览 3 评论 0原文

我有一个控件,在控件内,在控件内。

就像这样..

QuizMaster ->问题->答案-> RadioButton

当选中其中一个答案时,我希望运行 Quizmaster 中名为 AskNextQuestion() 的函数。

我该怎么做?

I have a Control, within a control, within a control.

Like so..

QuizMaster -> Question -> Answers -> RadioButton

When one of the answers is checked I want the function in Quizmaster called AskNextQuestion() to run.

How do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云淡风轻 2024-12-10 12:44:16

您可以在嵌套控件中创建一个事件,并让您的 QuizMaster 订阅该事件。

在您的 Answers 中添加以下内容:

public static event Action<bool> IsAnswered;

当您在其处理程序和 QuizMaster 中选择 RadioButton 时触发此事件

public void OnRadioButtonSelected(object sender, SomeEventArgs e)
{
  if(IsAnswered != null)
    IsAnswered(true);
}

订阅此静态事件:

public void SomeMethod()
{
  Answers.IsAnswered += new Action<bool>(Answers_IsAnsweredCompleted);
}

public void Answers_IsAnsweredCompleted(bool IsAsnwered)
{
  //call your method in QuizMaster
}

You would create an event in your nested control, and have your QuizMaster subscribe to that event.

In your Answers add this:

public static event Action<bool> IsAnswered;

and Fire this event when you select a RadioButton in its handler

public void OnRadioButtonSelected(object sender, SomeEventArgs e)
{
  if(IsAnswered != null)
    IsAnswered(true);
}

and in your QuizMaster Subscribe to this static event:

public void SomeMethod()
{
  Answers.IsAnswered += new Action<bool>(Answers_IsAnsweredCompleted);
}

public void Answers_IsAnsweredCompleted(bool IsAsnwered)
{
  //call your method in QuizMaster
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文