我有循环来创建一列按钮,现在我希望将事件处理程序实现到所有按钮中但不工作。
创建一列按钮的迭代
For e As Integer = 0 To 19
btnFriday(e) = New Button()
btnFriday(e).Height = 23
btnFriday(e).Width = 150
btnFriday(e).SetValue(Grid.ColumnProperty, 9)
btnFriday(e).SetValue(Grid.RowProperty, e + 1)
btnFriday(e).Click += New RoutedEventHandler(AddressOf btnBookSlot_Click)
LayoutRoot.Children.Add(btnFriday(e))
Next
我希望在单击 btnFriday 的 1 时执行以下事件,该事件打开一个称为 Bookslot 的子窗口
Private Sub btnBookSlot_Click(sender As Object, e As RoutedEventArgs)
Dim btn As Button = DirectCast(sender, Button)
Dim bookSlot As New BookSlot()
bookSlot.show()
End Sub
我收到类似的错误
Public Event Click(sender As Object, e As System.Windows.RoutedEventArgs)'是一个事件,不能直接调用。使用“RaiseEvent”语句引发事件
大多数解决方案都是使用带有 silverlight 的 C# 构建的,它们似乎运行良好。虽然我在使用带有 silverlight 的 VB.NET 时遇到问题,但有什么想法吗?