从WinForm应用程序

时间:2016-04-25 20:48:42

标签: vb.net

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

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

我安装了所需的NuGet包并创建了下面的代码(请注意我现在跳过原来的c#代码中的" action"部分):

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也无处可寻。

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

1 个答案:

答案 0 :(得分:0)

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

1RST:
“%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()