繁体   English   中英

从WinForm应用程序显示Windows 10吐司

[英]Show Windows 10 toast from WinForm application

我正在尝试将C#代码从下面的链接转换为VB.NET,并从经典的Windows窗体应用程序运行它:

快速入门:发送本地Toast通知并从中处理激活(Windows 10)

我安装了必需的NuGet软件包并在下面创建了代码(请注意,我暂时跳过了原始c#代码中的“操作”部分):

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    Dim title As String = "Andrew sent you a picture"
    Dim content As String = "Check this out, Happy Canyon in Utah!"
    Dim image As String = "http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-71-81-permanent/2727.happycanyon1_5B00_1_5D00_.jpg"
    Dim logo As String = "ms-appdata:///local/Andrew.jpg"
    Dim conversationId As Integer = 384928

    ' Construct the visuals of the toast

    'Visual content
    Dim visual As New ToastVisual()

    Dim TitleText As New ToastText
    TitleText.Text = title

    Dim BodyTextLine1 As New ToastText
    BodyTextLine1.Text = content

    Dim InLineImages As New ToastImageSource(image)

    Dim LogoImage As New ToastImageSource(logo)
    Dim AppLogoOverride As New ToastAppLogo
    AppLogoOverride.Source = LogoImage
    AppLogoOverride.Crop = ToastImageCrop.Circle

    ' Add all content into toastcontent
    Dim ToastContent As New ToastContent
    ToastContent.Visual = visual

    'Arguments when the user taps body of toast
    ToastContent.Launch = New QueryString() From {{"action", "viewConversation"}, {"conversationId", conversationId.ToString()}}.ToString()

我知道代码可以更有效,但是为了理解它,我现在就这样保留它。

现在的问题是下一行:

Dim Toast As New toastnotification(ToastContent.getXml)

ToastNotificationManager.CreateToastNotifier().Show(toast)

我无法将Toast声明为新的toastnotification,并且ToastContent似乎缺少getXml函数。

而且,ToastNotificationManager也找不到。

有人可以指出正确的方向吗?

您必须添加2个参考! (Win10)

1st:
“”%ProgramFiles(x86)%\\ Windows Kits \\ 10 \\ References \\ Windows.Foundation.UniversalApiContract \\ 1.0.0.0 \\ Windows.Foundation.UniversalApiContract.winmd

和(如果您想附加到ToastNotification类提供的事件)

第二名:
“”%ProgramFiles(x86)%\\ Windows Kits \\ 10 \\ References \\ Windows.Foundation.FoundationContract \\ 1.0.0.0 \\ Windows.Foundation.FoundationContract.winmd

并使用ToastContent.GetContent()代替ToastContent.getXml()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM