radiobutton检查验证会抛出错误

时间:2015-11-13 20:05:44

标签: c# wpf validation radio-button

我在wpf应用程序中遇到单选按钮验证问题,radiobutton.checked函数会抛出错误。 2个单选按钮的名称为TSBtnDSBtn。我尝试构建应用程序时得到的错误是'

  

错误2事件' System.Windows.Controls.Primitives.ToggleButton.Checked'只能出现在+ =或 - = 115 23 MainServerWIndow

的左侧

我不知道为什么会发生这种情况我写的代码如下:'

        private void Bill_Click(object sender, RoutedEventArgs e)
    {
        if (TSBtn.Checked)
        {
            StringBuilder itm = new StringBuilder();
            foreach (object selectedItem in yourOrder.Items)
            {
                 itm.AppendLine(selectedItem.ToString());
            }
            MessageBox.Show("The server is " + serversname.SelectedItem + "\n" + "The table number is " + int.Parse(TableNumber.Text) + "\n" + itm);
        }
        else if (DSBtn.Checked)
        {
            yourOrder.Items.Add("The driver is " + DriverName.SelectedItem);
            yourOrder.Items.Add("Delivery Address " + DeliveryAddress.Text);
        }
    }

有没有人知道为什么会这样? 感谢。

3 个答案:

答案 0 :(得分:1)

您的答案在于错误消息。

  

事件'System.Windows.Controls.Primitives.ToggleButton.Checked'...

Checked是一个事件,而非财产。

你想要的是IsChecked属性。

答案 1 :(得分:0)

. /www/inf/xxxx/inf_security_common/2.0/scripts/GetBatchCredentials.sh SampleBatchAppId xxxxAlias gbc.log if [ "$GetBatchCredentials_Result" != "Success" ] then echo "Error obtaining FTP Credentials" echo $GetBatchCredentials_Reason ret=1 else echo "Obtained FTP Credentials" ########### FTP User ID ################################ FTP_USR=$GetBatchCredentials_ID ########### FTP Password ############################### FTP_PWD=$GetBatchCredentials_PW echo "starting FTP" $FTP_USR $FTP_PWD fi 是一个事件。您应该测试Checked的已检查属性。

所以你的代码应该是:

IsChecked

if (TSBtn.IsChecked)
...

答案 2 :(得分:0)

我发现这个问题已经解决了:

stackoverflow.com

if (radLot.IsChecked == true)
{
    SymbolSpecification = "LotRenderer";
}