最新的DevExpress WinForm版本中,開發者可以使用WinForm產品線(通過DevExpress AlertControl和ToastNotificationManager)創建兩種類型的通知/警報,最近技術團隊還推薦使用DevExpress ToastNotificationManager來顯示原生 Windows 10+ 通知。
DevExpress Universal Subscription官方最新版免費下載試用,歷史版本下載,在線文檔和幫助文件下載-慧都網
盡管自定義選項有些有限(toast 僅提供九個布局模板),但ToastNotificationManager 代表了比傳統的基于面板的AlertControl更好、更現代的替代方案。
在最新版中為AlertControl發布的HTML & CSS 模板,允許開發人員創建時尚的警告通知,同時可利用AlertControl 本身的簡單性。下圖說明了技術團隊提供的一些示例模板(查找您喜歡的模板并將其復制到項目中):
大多數通知只是一個帶有幾個文本塊、圖像和按鈕的矩形,設計這樣簡單的對象對每個人來說都應該相對容易——無論您有 HTML 和 CSS 經驗,還是開始在WinForms 應用程序中利用其潛力。 例如以下模板創建一個帶有圖標、標題、描述和“確定”按鈕的通知。
<div class="container">
<div class="popup">
<img src="${SvgImage}" class="image" />
<div class="caption">Notification Title</div>
<div class="text">This notification uses a web-inspired template.</div>
<div id="okButton" class="ok-button">OK</div>
</div>
</div>
請注意,在此示例標記中,通知標題和說明是靜態字符串。 如果您要為用戶顯示一條消息,此解決方案就可以正常工作。
當然我們的數據綁定功能提供了更大的靈活性——您可以創建一個模板并將不同的數據對象傳遞給它。 因此,您可以為多個通知消息重用一個模板。
如果您更喜歡此選項,請使用 ${Data_property_name} 占位符,如下所示:
<div class="text">${Caption}</div>
<div class="text">${Text}</div>
“Caption”和“Text”是標準占位符,可以通過 AlertControl.Show 重載直接替換:
alertControl1.Show(this, "Sample caption", "Sample notification text");
您可以添加模板設計所需的任意數量的占位符,但請記住處理 AlertControl.BeforeFormShow 事件并將數據對象傳遞給 e.HtmlPopup.DataContext 屬性。 例如,下面的代碼使用 div 元素來顯示由五個占位符組合而成的字符串:兩個用于字符串值(FullName、Ticker),兩個用于數字(Percentage、Price),一個用于自定義 Direction 枚舉值。
<div class="message-text">
${FullName} ({Ticker}) {Direction} {Percentage}%. The current price is ${Price}.
</div>
通知圖像也在運行時檢索,img 標簽使用占位符替代靜態 src 屬性值。
<img src="${StockImage}" class="message-image" />
此示例應用程序使用 StockInfo 類對象作為數據項。
public class StockInfo {
public StockInfo(string ticker, string fullName, Direction direction,
double percentage, double price, SvgImage img) {
Ticker = ticker;
FullName = fullName;
Direction = direction;
Percentage = percentage;
Price = price;
StockImage = img;
}
public string Ticker { get; set; }
public string FullName { get; set; }
public Direction Direction { get; set; }
public double Percentage { get; set; }
public double Price { get; set; }
public SvgImage StockImage { get; set; }
}
public enum Direction {
[Description("rises")]
Up,
[Description("falls")]
Down
}
當數據項的 "Price" 值在短時間內發生顯著變化時會觸發通知,相應的項目分配給 AlertControl.BeforeFormShow 事件處理程序中的 e.HtmlPopup.DataContext 屬性。
void AlertControl1_BeforeFormShow(object sender, AlertFormEventArgs e) {
// TODO: Retrieve a data item
e.HtmlPopup.DataContext = myStockInfoInstance;
}
因此,通知會從指定為 DataContext 的數據項中檢索其 ${Field_Name} 占位符的數據。 請注意,邊條的顏色會根據 "Direction" 枚舉值而變化。
DevExpress WinForm
DevExpress WinForm擁有180+組件和UI庫,能為Windows Forms平臺創建具有影響力的業務解決方案。DevExpress WinForms能完美構建流暢、美觀且易于使用的應用程序,無論是Office風格的界面,還是分析處理大批量的業務數據,它都能輕松勝任!
PNotify是一個原生JavaScript通知和確認/提示庫。PNotify可以根據Web Notifications規范提供桌面通知,并返回瀏覽器內通知。PNotify是目前筆者正在項目中使用的一個通知提示組件,功能非常豐富,可以讓你的Web項目通知和提示更加的優雅!
https://github.com/sciactive/pnotify
npm install --save pnotify # Material style: npm install --save material-design-icons # Animate module: npm install --save animate.css # NonBlock module: npm install --save nonblockjs
PNotify模塊目錄如下:
要想看真實效果的朋友可以直接看官方提供的demo,非常的豐富示例,絕對讓你有使用它的沖動,咱們通過截圖來看一下:
具體的效果只有使用了之后才會體會到,絕對值得使用!
import PNotify from 'pnotify/dist/es/PNotify'; import PNotifyButtons from 'pnotify/dist/es/PNotifyButtons'; PNotify.alert('Notice me, senpai!');
import PNotify from 'pnotify/dist/es/PNotify'; import PNotifyButtons from 'pnotify/dist/es/PNotifyButtons'; //... export class WhateverComponent { constructor() { PNotifyButtons; // Initiate the module. Important! PNotify.alert('Notice me, senpai!'); } }
<script type="text/javascript" src="node_modules/pnotify/dist/iife/PNotify.js"></script> <script type="text/javascript" src="node_modules/pnotify/dist/iife/PNotifyButtons.js"></script> <script type="text/javascript"> PNotify.alert('Notice me, senpai!'); </script>
import PNotify from 'node_modules/pnotify/dist/es/PNotify.js'; import PNotifyButtons from 'node_modules/pnotify/dist/es/PNotifyButtons.js'; PNotify.alert('Notice me, senpai!');
<link href="node_modules/pnotify/dist/PNotifyBrightTheme.css" rel="stylesheet" type="text/css" />
Material 樣式模塊:
import PNotifyStyleMaterial from 'pnotify/dist/es/PNotifyStyleMaterial.js'; // or var PNotifyStyleMaterial = require('pnotify/dist/umd/PNotifyStyleMaterial.js'); // Set default styling. PNotify.defaults.styling = 'material'; // This icon setting requires the Material Icons font. (See below.) PNotify.defaults.icons = 'material';
# The official Google package: npm install --save material-design-icons # OR, An unofficial package that only includes the font: npm install --save material-design-icon-fonts
要將Bootstrap設置為默認樣式,請在導入PNotify后從下面包含相應的設置:
PNotify.defaults.styling = 'bootstrap3'; // Bootstrap version 3 PNotify.defaults.icons = 'bootstrap3'; // glyphicons // or PNotify.defaults.styling = 'bootstrap4'; // Bootstrap version 4
要將Font Awesome設置為默認圖標,請在導入PNotify后從下面包含相應的設置:
PNotify.defaults.icons = 'fontawesome4'; // Font Awesome 4 // or PNotify.defaults.icons = 'fontawesome5'; // Font Awesome 5
// 手動設置類型 PNotify.alert({ text: "I'm an alert.", type: 'notice' }); // 自動設置類型。 PNotify.notice({ text: "I'm a notice." }); PNotify.info({ text: "I'm an info message." }); PNotify.success({ text: "I'm a success message." }); PNotify.error({ text: "I'm an error message." });
以上只是簡單的介紹,如果你想讓你的瀏覽器推送通知不是很簡陋,筆者認為是時候使用這樣一個插件來助你解決這個問題了:
PNotify是筆者用過的最優雅的提示通知組件,推薦給需要的人!
evExpress WinForms擁有180+組件和UI庫,能為Windows Forms平臺創建具有影響力的業務解決方案。DevExpress WinForms能完美構建流暢、美觀且易于使用的應用程序,無論是Office風格的界面,還是分析處理大批量的業務數據,它都能輕松勝任!
DevExpress WinForm 控件已正式發布v23.1版本,此版本全新升級HTML & CSS的可重用模板、增強Ribbon組件功能、新增Office 365樣式等,歡迎下載最新版體驗!
DevExpress WinForms Subscription官方最新版免費下載試用,歷史版本下載,在線文檔和幫助文件下載-慧都網
DevExpress WinForms HTML & CSS模板庫包括一組預先設計的模板,這些模板基于官方WinForms演示應用程序中使用的模板。您可以“按原樣”使用這些模板,也可以根據需要進行定制。當然您也可以創建一個HTML & CSS模板,將模板保存到庫中,并在需要時在任何項目中使用它。
現在可以將圖像標簽綁定到具有圖像名稱的數據源字段中,HTML模板檢查數據字段是否包含SVG或位圖。如果沒有,則模板在SvgImageCollection(分配給控件的htmlages屬性)中查找具有指定名稱的圖像。
HTML
<img class="icon" src="${IconName}"/>
DevExpress WinForms Ribbon控件附帶了一個全新的Office 365渲染樣式。
當我們使用新的Office 365樣式時,WinForm Ribbon控件在功能區表單的頂部顯示一個搜索框,并在 Ribbon UI的右下方顯示顯示功能區選項。
使用以下API在其他 Ribbon樣式中啟用新的UI增強功能:
Backstage View(后臺視圖)項目現在包括一個新的對齊選項,此選項允許您將項目對齊到后臺視圖的頂部和底部,以及標題欄和快速訪問工具欄的左側和右側(當它顯示在Ribbon控件下方時)。
C#
backstageViewItem.Alignment = BackstageViewItemAlignment.Bottom;
新版本中實現了新的API來顯示受Office啟發的彈出式通知和警報。
新的API包括:
C#
using DevExpress.XtraBars.Ribbon;
void ShowMessage() {
RibbonMessageArgs args = new RibbonMessageArgs();
args.Caption = "What's New";
args.Text = "Explore new WinForms-related features we expect to introduce in our first major update this year (v23.1).";
args.Icon = MessageBoxIcon.Information;
args.Buttons = new DialogResult[] { DialogResult.OK };
args.Showing += Args_Showing;
Ribbon.ShowMessage(args);
Ribbon.MessageClosed += Ribbon_MessageClosed;
}
void Ribbon_MessageClosed(object sender, RibbonMessageClosedArgs e) {
if(e.Result == DialogResult.OK)
Data.Utils.SafeProcess.Start("https://community.devexpress.com/blogs/winforms/archive/2023/02/16/devexpress-winforms-roadmap-23-1.aspx");
}
void Args_Showing(object sender, RibbonMessageShowingArgs e) {
e.Buttons[DialogResult.OK].Caption = "Explore Roadmap";
}
Page header項(BarButtonItem和BarCheckitem)可以根據矢量皮膚中的背景顏色調整文本和SVG圖標的顏色,背景色必須設置為皮膚顏色(在設計時,切換到“DX Skins”選項卡來選擇皮膚顏色)。
更多DevExpress線上公開課、中文教程資訊請上中文網獲取
*請認真填寫需求信息,我們會在24小時內與您取得聯系。