Windows 10 將傳統的「氣泡提示」整合至通知中心,開發者需使用 Toast Notification API 而非舊版 Shell_NotifyIcon(NIM_MODIFY, ...) 的氣泡方式。雖然舊 API 仍能運作,但外觀會自動轉換為 Toast 樣式,且功能受限(無法支援按鈕、圖片、輸入框等豐富互動)。
// NuGet 安裝 Microsoft.Toolkit.Uwp.Notifications
using Microsoft.Toolkit.Uwp.Notifications;
new ToastContentBuilder()
.AddText("標題:任務完成")
.AddText("內容:資料備份已於 14:30 完成。")
.AddButton(new ToastButton()
.SetContent("查看詳情")
.AddArgument("action", "viewDetail")
.AddArgument("taskId", "12345"))
.AddAppLogoOverride(new Uri("ms-appx:///Assets/Logo.png"), ToastGenericAppLogoCrop.Circle)
.Show(); // 直接發送
傳統 Win32 桌面應用程式需透過 Desktop Bridge 封裝為 MSIX,或使用 windows.data.xml.dom + Windows.UI.Notifications 配合 ToastNotificationManager:
#include
#include
using namespace winrt;
using namespace Windows::Data::Xml::Dom;
using namespace Windows::UI::Notifications;
void SendToast()
{
init_apartment();
// 1. 載入 Toast 範本 XML
XmlDocument xml;
xml.LoadXml(LR"(
編譯完成
專案 MyApp 建置成功,耗時 1 分 23 秒。
)");
// 2. 建立並顯示通知
ToastNotification toast(xml);
ToastNotificationManager::CreateToastNotifier(L"YourAppId").Show(toast);
}
必要條件: 應用程式必須有 AppUserModelId (AUMI),且已在開始選單安裝捷徑(或透過 MSIX 部署),否則 Toast 不會顯示。
若維護舊專案,仍在使用 NOTIFYICONDATA + Shell_NotifyIcon(NIM_MODIFY, ...) 並設定 szInfoTitle/szInfo:
Settings > System > Notifications & actions 中應用程式通知開關為「開啟」。ToastNotificationManager.History.Clear() 清除歷史避免干擾測試。Microsoft.Toolkit.Uwp.Notifications NuGet 套件,大幅簡化 XML 組裝。Windows 10 通知中心基於 Toast Notification 架構。C# 開發者建議使用 UWP Community Toolkit;C++ 需引入 WinRT 標頭並確保擁有有效 AUMI。舊版氣泡提示雖相容但功能受限,新專務應直接採用 Toast API。