VB.Net WPF应用程序-吐司通知未通过

时间:2018-08-02 21:40:20

标签: xml wpf vb.net visual-studio-2017 toast

嘿,我只是在尝试测试WPF定时Toast Notification Setup,但无法收到到Action Center的通知。没有错误,但通知从未出现。我知道计时器处理程序正常运行,因为它将消息输出到控制台,但没有吐司通知。这是我完成的主要代码之外的一些事情:

1:已将<'targetplatformversion> 10.0 <'/ targetplatformversion>添加到: <'PropertyGroup>, <'PropertyGroup Condition =“'$(配置)| $(平台)'=='Debug | AnyCPU'”>,并且 <'PropertyGroup Condition =“'$(配置)| $(平台)'=='发布| AnyCPU'”>

2:添加了Windows.winmd和System.Runtime.WindowsRuntime.dll作为引用

下面是所有相关代码:

Class MainWindow()

    Dim Timer1 As Timer

    Private Sub Install_Click(sender As Object, e As RoutedEventArgs)

        Timer1 = New Timer With {
            .Interval = 30000
        }
        AddHandler Timer1.Elapsed, AddressOf Timer1_Tick
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As ElapsedEventArgs)

        Toasty.ShowToastNotification()
        Console.WriteLine("Timer Ticked")

    End Sub

    Private Sub Uninstall_Click(sender As Object, e As RoutedEventArgs)

        Console.WriteLine("Timer Stopped")
        Timer1.Enabled = False

    End Sub

End Class

Public Class Toasty

    Public Shared Sub ShowToastNotification()
        Dim APP_ID As String = "RegisterAlertService"

        Dim Xml = $"<toast>
                        <visual>
                            <binding template='ToastGeneric'>
                                <text>Test</text>
                                <text>Toast Notification</text>
                            </binding>
                        </visual>
                    </toast>"

        Dim toastXml As New XmlDocument()

        toastXml.LoadXml(Xml)

        Dim toast = New ToastNotification(toastXml)

        ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast)

    End Sub

End Class

0 个答案:

没有答案