• <menu id="w2i4a"></menu>
  • logo DevExpress WinForms使用教程

    文檔首頁(yè)>>DevExpress WinForms使用教程>>DevExpress Winforms使用技巧教程:如何在WinForms Apps中顯示Toast Notifications(二)

    DevExpress Winforms使用技巧教程:如何在WinForms Apps中顯示Toast Notifications(二)


    下載DevExpress v19.2完整版    DevExpress v19.2漢化資源獲取

    DevExpress Winforms Controls 內(nèi)置140多個(gè)UI控件和庫(kù),完美構(gòu)建流暢、美觀且易于使用的應(yīng)用程序。使用WinForms PictureEdit控件,可以在表單上顯示圖像。為控件實(shí)現(xiàn)DirectX渲染支持,可以輕松處理大的高DPI圖像。想要體驗(yàn)?點(diǎn)擊下載>>

    Activator和COM服務(wù)器

    Windows在其“操作中心”中保留toast notifications。

    通常,操作中心在用戶關(guān)閉此屏幕后清除所有toasts(如果用戶打開(kāi)、關(guān)閉并在此打開(kāi)操作中心,則該操作將為空),但是某些toasts可以保留在操作中心中,直到用戶手動(dòng)將其關(guān)閉為止。即使用戶注銷并返回Windows之后,此類toasts仍保留在操作中心中。此外,單擊toasts會(huì)啟動(dòng)其父應(yīng)用程序,要顯示此類通知,請(qǐng)創(chuàng)建一個(gè)自定義Activator—DevExpress.XtraBars.ToastNotifications.ToastNotificationActivator類的后代。

    [Guid("39697E4E-3543-4414-A694-90097B433DC6"), ComVisible(true)]
    public class ToastNotificationActivatorCustom : ToastNotificationActivator {
    
    public override void OnActivate(string arguments, Dictionary<string, string> data){
    //specify what happens when a user interacts with a toast
    }
    }

    您將需要注冊(cè)此自定義Activator,在設(shè)計(jì)時(shí)設(shè)置組件的ApplicationActivator屬性,或在代碼中調(diào)用RegisterApplicationActivator方法。

    toastNotificationsManager1.RegisterApplicationActivator(
    typeof(ToastNotificationActivatorCustom));

    您還需要注冊(cè)一個(gè)COM服務(wù)器。 為此,請(qǐng)調(diào)用DevExpress.Data.ShellHelper.RegisterComServer方法。 請(qǐng)注意,如果使用ShellHelper類創(chuàng)建應(yīng)用程序快捷方式,則需要使用帶有activatorType參數(shù)的TryCreateShortcut方法重載。 否則,如果您使用應(yīng)用安裝程序添加應(yīng)用程序快捷方式,則安裝程序還必須添加HKEY_CURRENT_USER \ SOFTWARE \ Classes \ CLSID \ {-your-GUID-here-} \ LocalServer32注冊(cè)表項(xiàng),并以路徑將應(yīng)用程序可執(zhí)行文件添加為 值。

    if (!ShellHelper.IsApplicationShortcutExist("My Toast Application")
    {
    ShellHelper.TryCreateShortcut(
    Process.GetCurrentProcess().MainModule.FileName,
    toastNotificationsManager1.ApplicationId,
    "My Toast Application",
    @"D:\Work\Images\_Icons\ico\chain-icon.ico",
    typeof(ToastNotificationActivatorCustom));
    ShellHelper.RegisterComServer(
    Process.GetCurrentProcess().MainModule.FileName,
    typeof(ToastNotificationActivatorCustom));
    }

    GUIDs

    使用toasts時(shí),您需要幾個(gè)唯一的ID。

    • 針對(duì)組件的ApplicationID屬性
    • 針對(duì)每個(gè)通知的ID屬性
    • 針對(duì)標(biāo)記Activator類的Guid屬性

    您可以混搭鍵盤來(lái)生成唯一的ID,但是更有效的方法是使用聯(lián)機(jī)GUID生成器或Visual Studio中包含的生成器("Tools | Create GUID")。

    傳遞重要通知

    即使您正確設(shè)置了所有內(nèi)容,通知也可能不會(huì)傳遞給用戶。 交付會(huì)受到以下因素的影響:

    • 較舊的OS版本
    • 操作中心設(shè)置中禁用了通知
    • 內(nèi)部錯(cuò)誤等

    在這種情況下,您可以處理ToastNotificationsManager.Failed事件,以通過(guò)其他方法(例如標(biāo)準(zhǔn)消息框)將關(guān)鍵消息傳遞給用戶。

    using DevExpress.XtraBars.ToastNotifications;
    using DevExpress.XtraEditors;
    
    void manager_Failed(object sender, ToastNotificationFailedEventArgs e)
    {
    if ((string)e.NotificationID == "toast_connection_lost_id_das0ud0q94")
    {
    IToastNotificationProperties undeliveredToast =
    toastNotificationsManager1.GetNotificationByID(e.NotificationID);
    XtraMessageBox.Show(undeliveredToast.Body, undeliveredToast.Header);
    }
    }


    DevExpress v19.2線上公開(kāi)課即將開(kāi)課,前10名免費(fèi)參與哦~

    DevExpress技術(shù)交流群:540330292      歡迎一起進(jìn)群討論

    掃描關(guān)注DevExpress中文網(wǎng)微信公眾號(hào),及時(shí)獲取最新動(dòng)態(tài)及最新資訊

    DevExpress中文網(wǎng)微信
    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();