How to declare lambda event handlers in VB.Net?

前端 未结 4 1303
盖世英雄少女心
盖世英雄少女心 2021-02-07 02:44

I believe the following VB.Net code is the equivalent of the proceeding C# code; however the VB.Net test fails - the event handling Lambda is never called.

What is going

4条回答
  •  死守一世寂寞
    2021-02-07 03:02

    WPF controls that have popups require an instance of the WPF Application Object. In a WPF application, this is automatically created. This is not the case in a WinForm application. For this reason, this object must be created manually. The Application also must be set to remain open until it is shut down through code, otherwise it will shut automatically when the WinForm applications determines it is no longer needed. The following code will open the Application object in a WinForm and keep it open until it is closed. Shutting down the Application object when the WinForm closes is the recommended approach.

      Dim app As System.Windows.Application = New System.Windows.Application With {
                .ShutdownMode = Windows.ShutdownMode.OnExplicitShutdown
            }
            AddHandler Closed, Sub()
                                   app.Shutdown()
                               End Sub
    

提交回复
热议问题