久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

顯示 Windows 10 Toast 通知

Showing a Windows 10 toast notification(顯示 Windows 10 Toast 通知)
本文介紹了顯示 Windows 10 Toast 通知的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在用 C# (Visual Studio 2015) 開發一個程序,我想在特定情況下向用戶顯示一條吐司消息.我從 MSDN 下載了這段代碼,它運行良好:

I'm developing a program in C# (Visual Studio 2015) and I want to show a toast message to the user at a certain situation. I downloaded this code from the MSDN and it runs fine:

// Get a toast XML template
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);

// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
    stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
}

// Specify the absolute path to an image
String imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;

// Create the toast and attach event listeners
ToastNotification toast = new ToastNotification(toastXml);
toast.Activated += ToastActivated;
toast.Dismissed += ToastDismissed;
toast.Failed += ToastFailed;

// Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);

測試此代碼后,我想將其實現到我的應用程序中.所以我稍微改變了它并嘗試運行它.錯誤信息:

After testing this code I wanted to implement it into my application. So I changed it up a little bit and tried to run it. The error messages:

類型IReadOnlyList<>"是在未引用的程序集中定義的.添加對 System.Runtime、Version=4.0.0.0、Culture=neutral、PublicKeyToken=b03f5f7f11d50a3a 的引用"(已翻譯)

The type "IReadOnlyList<>" is defined in a not referenced assembly. Add a reference to System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" (translated)

同樣適用于 IEnumerable<>IReadOnlyList<>

錯誤來自這兩行:

for (int i = 0; i < stringElements.Length; i++)
{
    stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));

我還嘗試添加對 System.Runtime 的引用.我用 NuGet (https://www.nuget.org/packages/System.Runtime/4.0.0/).在那之后,錯誤消失了,但現在我的代碼中的每個字都變成了紅色,并帶有諸如System.Object is not defined"之類的錯誤(但它在我啟動時仍然運行!).

I also tried adding the reference to System.Runtime. I downloaded it with NuGet (https://www.nuget.org/packages/System.Runtime/4.0.0/). After that the errors were gone, but now literaly every word in my code is cringled red with error like "System.Object is not defined" and so on (but it still runs when I start it!).

我能想到的唯一可能的解決方案是 System.Runtime 已經安裝在我電腦的某個地方,而 4.0.0 是我程序的錯誤版本.但我在任何地方都找不到.

The only possible solution I can think of is that System.Runtime is already installed somewhere on my computer, and that 4.0.0 is the wrong version for my program. But I can't find it anywhere.

PS:它是桌面應用程序,而不是 Windows 商店應用程序.

PS: It's a desktop-application, not a Windows-Store application.

推薦答案

我覺得和 這個問題您必須添加對

I think it is the same problem as in this question You must add a reference to

C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5.1FacadesSystem.Runtime.dll

PS:如果您只有 Windows 10 桌面應用程序,您可能希望使用新的 Toast 系統,MSDN 上的代碼示例使用的是 Windows 8 系統.它適用于 W10,但沒有所有新功能(微軟發布了官方 NuGet 包).

PS : If you have a Windows 10 only desktop app, you might want to use the new toast system, the code sample on MSDN uses the Windows 8 one. it works on W10 but does not have all the new features (Microsoft released an official NuGet package).

由于我無法發表評論,我將在此處發布答案:

Edit : Since I can't comment, I will post the answer here :

例外是因為您需要在 CreateToastNotifier()

ToastNotificationManager.CreateToastNotifier("MyApplicationId").Show(toast);

它是將在操作中心用于對您的 toast 進行分組的名稱(因此通常,您輸入應用程序的名稱).在 Windows 8.1 中,需要注冊您的應用程序 ID(我認為這在 MSDN 的示例中),但現在您只需輸入應用程序的名稱即可.

It is the name that will be used in the action center to group your toasts (so in general, you put the name of your app). In Windows 8.1 it was needed to register your application Id (I think this was in the sample from the MSDN) but now you can just put the name of your app.

GetXml() 僅適用于 WinRT.在桌面上,您需要像使用 GetContent() 那樣做.

And the GetXml() is only for WinRT. In desktop you need to do like you did with the GetContent().

這篇關于顯示 Windows 10 Toast 通知的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發問題)
SQL Server 2005 Transaction Level and Stored Procedures(SQL Server 2005 事務級和存儲過程)
Yield return from a try/catch block(try/catch 塊的收益回報)
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務的 SqlCommand 時,我應該調用 Parameters.Clear 嗎?)
Does SqlTransaction need to have Dispose called?(SqlTransaction 是否需要調用 Dispose?)
Reason for System.Transactions.TransactionInDoubtException(System.Transactions.TransactionInDoubtException 的原因)
主站蜘蛛池模板: 亚洲高清成人在线 | 在线精品国产 | 精品国产欧美 | 国产性生活一级片 | 91精品综合久久久久久五月天 | 欧美一级久久 | 欧美日韩国产在线观看 | 激情欧美一区二区三区中文字幕 | 国产成人自拍av | 亚洲精品一区二三区不卡 | 97超碰人人草 | 国产成人精品av | 久久久久一区二区三区四区 | 狠狠干天天干 | 国产精品国产三级国产播12软件 | 国产片侵犯亲女视频播放 | 国产精品一区二区三区在线 | 欧美黄色片 | 男人天堂av网站 | 全部免费毛片在线播放网站 | 在线中文字幕国产 | 久久黄网 | 手机看片169 | 中文字幕日韩一区二区 | 成人午夜精品 | 国产精品成人在线播放 | 成年人在线观看视频 | 欧美日韩综合精品 | 请别相信他免费喜剧电影在线观看 | 亚洲精彩视频 | 中文一级片 | 日本精品一区二区三区在线观看 | 中文精品视频 | 狠狠干美女 | 日日夜夜精品视频 | 一区二区三区视频在线观看 | 国产成人精品免费视频大全最热 | 午夜av免费 | 精品国产成人 | 国产精品美女久久久久aⅴ国产馆 | 精品久久久久久中文字幕 |