I have loop to create a column of button and now i wish to implemented the eventhandler into all the buttons but is not working.
The iteration to create a column of button
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
I wish to do like when 1 of the btnFriday is clicked then perform the below event which is open a childwindow called as 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
And i receive error like
Public Event Click(sender As Object, e As System.Windows.RoutedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event
Most of the solutions were built using C# with silverlight and they seem to be working great. While i having problem by using VB.NET with silverlight Any idea ?
I believe all you need to change is:
btnFriday(e).Click += New RoutedEventHandler(AddressOf btnBookSlot_Click)
To:
AddHandler btnFriday(e).Click, AddressOf btnBookSlot_Click