单选按钮 "Checked" 方法不起作用

Radiobutton "Checked" method doesn't work

我在构建我的第一个 UWP 应用程序时遇到未知问题。

在按钮 onclick 方法上,我想检查是否选中了一个复选框,如果是,我想打开一个新框架:

namespace IDG
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void bt_start_Click(object sender, RoutedEventArgs e)
        {
            if (rb_quiz.Checked)
            {
                this.Frame.Navigate(typeof(Page2));
            }
        }
    }
}

Visual Studio 标记该行的错误: if (rb_quiz.Checked)

弹出窗口显示:

The Event 'ToggleButton.Checked' can only appear on the left hand side of += or -"

我勾选了“==Checked”或“isChecked”。但没有任何效果。我的 radiobutton 叫做 rb_quiz.

Checked 是一个事件,您正在寻找 IsChecked 这是一个 Nullable<Boolean>.

试试这个:

if (rb_quiz.IsChecked == true)

根据 the documentationChecked 是 "Fires when a ToggleButton is checked" 的事件。您反而想使用 属性 IsChecked