我希望用户单击单选按钮,然后单击“提交”按钮。按下提交按钮后,它会更改文本框值。但Visual Studio告诉我,我需要使用“引发事件”。我不知道如何使用它或甚至需要它?这是代码:
Private Sub create_Click(sender As Object, e As RoutedEventArgs)
If RadioButton1.Checked = True Then
Me.creflag.Text += "1"
ElseIf RadioButton2.Checked = True Then
Me.creflag.Text += "4224"
ElseIf RadioButton3.Checked = True Then
Me.creflag.Text += "2"
ElseIf RadioButton4.Checked = True Then
Me.immune.Text += "619659263"
Me.typeflag.Text += "4"
End If
End Sub
答案 0 :(得分:1)
在您的XAML标记中,您有
.... Click="Button_Click"
这意味着你需要一个名为Button_Click的RouterEventHandler而不是create_Click
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
If RadioButton1.Checked = True Then
Me.creflag.Text += "1"
ElseIf RadioButton2.Checked = True Then
Me.creflag.Text += "4224"
ElseIf RadioButton3.Checked = True Then
Me.creflag.Text += "2"
ElseIf RadioButton4.Checked = True Then
Me.immune.Text += "619659263"
Me.typeflag.Text += "4"
End If
End Sub
答案 1 :(得分:0)
好的,我发现我正在将Windows窗体和WPF混合在一起。在Windows窗体中它是.Checked但在WPF中这是一个事件因此它给我的错误。 WPF中的正确方法是.IsChecked
最终守则:
Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs) Handles Button.Click
If RadioButton1.IsChecked = True Then
Me.creflag.Text += "1"
ElseIf RadioButton2.IsChecked = True Then
Me.creflag.Text += "4224"
ElseIf RadioButton3.IsChecked = True Then
Me.creflag.Text += "2"
ElseIf RadioButton4.IsChecked = True Then
Me.immune.Text += "619659263"
Me.typeflag.Text += "4"
End If
End Sub