无法执行 RoutedEventHandler

发布于 2024-12-15 08:11:20 字数 1043 浏览 2 评论 0原文

我有循环来创建一列按钮,现在我希望将事件处理程序实现到所有按钮中,但不起作用。

创建一列按钮的迭代,

 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

我希望像单击 1 个 btnFriday 时那样,然后执行以下事件,该事件打开一个名为 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

并且我收到如下错误

公共事件点击(发送者作为对象,e作为 System.Windows.RoatedEventArgs)' 是一个事件,无法调用 直接地。使用“RaiseEvent”语句引发事件

大多数解决方案都是使用 C# 和 silverlight 构建的,而且它们似乎运行良好。虽然我在使用 VB.NET 和 silverlight 时遇到问题,有什么想法吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪装你 2024-12-22 08:11:20

我相信你需要改变的是

 btnFriday(e).Click +=  New RoutedEventHandler(AddressOf btnBookSlot_Click)

  AddHandler btnFriday(e).Click, AddressOf btnBookSlot_Click

I believe all you need to change is:

 btnFriday(e).Click +=  New RoutedEventHandler(AddressOf btnBookSlot_Click)

To:

  AddHandler btnFriday(e).Click, AddressOf btnBookSlot_Click
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文