此处留笔记以便查阅,大神绕行。
VB.NET在WPF中Button异常触发2次,问题代码如下:
VB.NET 代码:
Private num As Integer
Private Sub AddUser_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnAdd.Click
num = userdb.UserDB.Count + 1
MsgBox(num)
End Sub
xaml 代码:
<Button Grid.Row="0" Width="80" Content="添加用户" Name="BtnAdd" Click="AddUser_Click" />
解决方案一:去掉VB.NET代码中的事件绑定:
VB.NET 代码:
Private num As Integer
Private Sub AddUser_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
num = userdb.UserDB.Count + 1
MsgBox(num)
End Sub
xaml 代码:
<Button Grid.Row="0" Width="80" Content="添加用户" Name="BtnAdd" Click="AddUser_Click" />
解决方案二:去掉Xaml代码中的事件绑定:
VB.NET 代码:
Private num As Integer
Private Sub AddUser_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnAdd.Click
num = userdb.UserDB.Count + 1
MsgBox(num)
End Sub
xaml 代码:
<Button Grid.Row="0" Width="80" Content="添加用户" Name="BtnAdd" />