[英]System Notifications at WPF
我怎么可以將click
事件在使用Microsoft.Toolkit.Uwp.Notifications圖書館在WPF應用系統Toast通知按鈕?
我知道我需要使用IBackground
接口,但不能綁定到此類,因為以下代碼導致了錯誤( ToastNotificationActionTrigger()
元素未找到,HRESULT:0x80070490)。
private void RegisterBackgroundTask()
{
const string taskName = "ToastBackgroundTask";
// Otherwise create the background task
var builder = new BackgroundTaskBuilder();
builder.Name = taskName;
builder.TaskEntryPoint = typeof(ToastNotificationBackgroundTask).FullName;
// And set the toast action trigger
builder.SetTrigger(new ToastNotificationActionTrigger());
// And register the task
builder.Register();
}
我的通知視圖:
請幫忙。
一年前,我在WPF中使用了通知,這是我如何實現的:
首先,您必須從Nuget中添加Windows API Code Pack包 。
然后,我使用以下代碼:
public static void RaiseGeneratedNotification(int errors, int warnings)
{
// Get a toast XML template
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Web Studio"));
stringElements[1].AppendChild(toastXml.CreateTextNode(Strings.Errors+": "+errors));
stringElements[2].AppendChild(toastXml.CreateTextNode(Strings.Warnings+": " +warnings));
// Specify the absolute path to an image
String imagePath = "file:///" + Path.GetFullPath("App.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)
{
ExpirationTime = DateTimeOffset.Now.AddMinutes(2)
};
// Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(Resources.AppId).Show(toast);
}
使用此代碼,我執行了以下步驟:
您還必須在應用程序快捷方式中注冊一個AppId。
希望對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.