vb.net 从 WinForm 应用程序显示 Windows 10 Toast

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36850781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:50:50  来源:igfitidea点击:

Show Windows 10 toast from WinForm application

vb.net

提问by Jurian Groeneveld

I'm trying to convert the c# code from below link into VB.NET and run it from a classic Windows form application:

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

Quickstart: Sending a local toast notification and handling activations from it (Windows 10)

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

I installed the required NuGet packages and created the code below (please note I skipped the "action" section from the original c# code for now):

我安装了所需的 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()

I understand the code can be more efficient but for understanding it I left it for now like this.

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

Now the problem is the next line:

现在的问题是下一行:

Dim Toast As New toastnotification(ToastContent.getXml)

and

ToastNotificationManager.CreateToastNotifier().Show(toast)

I cannot declare Toast as a new toastnotification and ToastContent seems to miss the getXml function.

我不能将 Toast 声明为新的 toastnotification 并且 ToastContent 似乎错过了 getXml 函数。

Also the ToastNotificationManager is nowhere to be found.

也找不到 ToastNotificationManager。

Can someone please point me in the right direction?

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

回答by Cadburry

You have to add 2 references! (Win10)

您必须添加 2 个引用!(Win10)

1rst:
"%ProgramFiles(x86)%\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0\Windows.Foundation.UniversalApiContract.winmd"

第一个:
“%ProgramFiles(x86)%\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0\ Windows.Foundation.UniversalApiContract.winmd

and (if you want to attach to the events provided by the ToastNotificationclass)

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

2nd:
"%ProgramFiles(x86)%\Windows Kits\10\References\Windows.Foundation.FoundationContract\1.0.0.0\Windows.Foundation.FoundationContract.winmd"

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

And use ToastContent.GetContent()instead of ToastContent.getXml()

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