我试图在。net 6或。net 7上使用Visual Basic中的Windows 10UserNotificationListener
API。我已经编写了以下代码来创建对象并注册事件:
Imports Windows.UI.Notifications
Public Class Form1
Private WithEvents listen As UserNotificationListener
Private Async Sub onnotif(sender As UserNotificationListener, e As UserNotificationChangedEventArgs) Handles listen.NotificationChanged
MsgBox(e)
End Sub
Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
listen = UserNotificationListener.Current
'AddHandler listen.NotificationChanged, AddressOf onnotif
End Sub
End Class
我还尝试以编程方式注册事件处理程序(在上面的代码中注释掉),但收到相同的运行时异常。
但是当我运行代码时,我得到以下异常:
System.Runtime.InteropServices.COMException: 'Element not found. (0x80070490)'
我是否错误地注册了事件,或者这是我如何使用UserNotificationListener
API的问题?
谢谢!
我需要为我的应用程序创建一个包标识,方法是在MSIX包中运行应用程序并启用"用户通知侦听器"。能力。