久久久久久久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 的原因)
主站蜘蛛池模板: 欧美高清一级片 | 久久99精品久久久久 | 日韩av一区二区在线观看 | 欧美久久精品一级c片 | 成人依人| 国产美女在线免费观看 | 久久精品亚洲一区二区三区浴池 | 日本在线免费 | 久久久久久久亚洲精品 | 亚洲性视频 | 欧美日韩在线一区 | 91精品国产高清一区二区三区 | 男人影音| 日韩精品一区二区三区老鸭窝 | 日韩成人一区 | 国产一区二区黑人欧美xxxx | 日韩在线播放一区 | 久久精品亚洲精品 | 午夜精品视频 | 成年人黄色小视频 | 99福利网| 亚洲成人网在线 | 亚洲天堂久久 | 欧美日韩亚洲国产综合 | 欧美成人免费在线 | 久久久久国产一区二区三区四区 | 美女视频黄的免费 | 国产极品粉嫩美女呻吟在线看人 | 一级久久久久久 | 国产日韩欧美中文 | 国产精品一区在线观看 | 精品国产一区二区三区免费 | 老头搡老女人毛片视频在线看 | 国产成人高清 | 黄a大片 | 亚洲精彩免费视频 | 国产一级视频在线观看 | 亚洲一区电影 | 国产在线一区二区三区 | 青青草综合 | 一区二区精品在线 |