警報(bào)窗口與HTML模板
受web啟發(fā)的HTML和CSS模板允許您設(shè)計(jì)具有任何自定義外觀和布局的警報(bào)。
創(chuàng)建靜態(tài)警報(bào)模板
點(diǎn)擊AlertControl.HtmlTemplate屬性旁邊的省略號(hào)按鈕來調(diào)用模板編輯器。
如果您需要多個(gè)模板,請(qǐng)?zhí)畛銩lertControl.HtmlTemplates集合,也可以使用此集合在顯示通知之前切換活動(dòng)模板。
C#:
alertControl1.HtmlTemplate.Assign(alertControl1.HtmlTemplates[1]);
點(diǎn)擊復(fù)制
VB.NET:
alertControl1.HtmlTemplate.Assign(alertControl1.HtmlTemplates(1))
點(diǎn)擊復(fù)制
<img>標(biāo)簽允許您向模板添加圖標(biāo)。用矢量圖像填充SvgImageCollection,并將其分配給AlertControl.HtmlImages屬性。當(dāng)一個(gè)圖像集合被分配給Alert控件時(shí),可以在模板語法編輯器中按Ctrl+Space來瀏覽存儲(chǔ)在該集合中的圖標(biāo)列表,并將所需的圖像分配給<img>標(biāo)簽的src屬性。
HTML:
c<img src="message_icon_2"/>
點(diǎn)擊復(fù)制
要用靜態(tài)模板顯示通知,請(qǐng)使用AlertControl.Show(Form)方法,該方法只接受父對(duì)象(Form)作為參數(shù)。
C#:
alertControl1.Show(this);
點(diǎn)擊復(fù)制
VB.NET:
alertControl1.Show(Me)
點(diǎn)擊復(fù)制
用可變數(shù)據(jù)創(chuàng)建模板
除了帶有靜態(tài)標(biāo)題和文本字符串的模板之外,還可以創(chuàng)建帶有值占位符的HTML元素。
HTML:
<div class="text">${Caption}</div> <div class="text">${Text}</div>
點(diǎn)擊復(fù)制
使用AlertControl.Show方法重載" Caption "和" Text "參數(shù)來傳遞真實(shí)值給這些HTML元素。因此,您可以對(duì)各種通知使用相同的模板設(shè)計(jì)。
C#:
alertControl1.Show(this, "Sample caption", "Sample notification text");
點(diǎn)擊復(fù)制
VB.NET:
alertControl1.Show(Me, "Sample caption", "Sample notification text")
點(diǎn)擊復(fù)制
您還可以對(duì)AlertInfo參數(shù)使用重載,這個(gè)重載允許將字符串和圖像數(shù)據(jù)傳遞給HTML元素。
HTML:
<div class="text">${Caption}</div> <div class="text">${Text}</div> <img src="${SvgImage}"/>
點(diǎn)擊復(fù)制
C#:
AlertInfo aInfo = new AlertInfo("Sample notification", "This text is stored in the AlertInfo object"); aInfo.ImageOptions.SvgImage = svgImageCollection1[0]; alertControl1.Show(this, aInfo);
點(diǎn)擊復(fù)制
VB.NET:
Dim aInfo As New AlertInfo("Sample notification", "This text is stored in the AlertInfo object") aInfo.ImageOptions.SvgImage = svgImageCollection1(0) alertControl1.Show(Me, aInfo)
點(diǎn)擊復(fù)制
如果需要具有多個(gè)數(shù)據(jù)綁定元素的復(fù)雜模板,請(qǐng)創(chuàng)建自定義數(shù)據(jù)存儲(chǔ)。要將數(shù)據(jù)從這個(gè)對(duì)象傳遞給HTML元素,使用相應(yīng)的Show方法重載或處理AlertControl.BeforeFormShow事件。
HTML:
<div class="title-main">${Title}</div> <div class="title-sub">${Subtitle}</div> <div class="text">${PrimaryText}</div> <div class="text">${SecondaryText}</div>
點(diǎn)擊復(fù)制
C#:
alertControl1.Show(this, new AlertData("Sample Title", "Sample Subtitle", "Primary Text Block", "Secondary Text Block")); // or alertControl1.Show(this); private void AlertControl1_BeforeFormShow(object sender, AlertFormEventArgs e) { e.HtmlPopup.DataContext = new AlertData("Sample Title", "Sample Subtitle", "Primary Text Block", "Secondary Text Block"); } // Custom class whose instances are used as DataContext public class AlertData { public AlertData(string title, string subtitle, string primaryText, string secondaryText) { Title = title; Subtitle = subtitle; PrimaryText = primaryText; SecondaryText = secondaryText; } public string Title { get; set; } public string Subtitle { get; set; } public string PrimaryText { get; set; } public string SecondaryText { get; set; } }
點(diǎn)擊復(fù)制
VB.NET:
alertControl1.Show(Me, New AlertData("Sample Title", "Sample Subtitle", "Primary Text Block", "Secondary Text Block")) ' or alertControl1.Show(Me) private void AlertControl1_BeforeFormShow(Object sender, AlertFormEventArgs e) e.HtmlPopup.DataContext = New AlertData("Sample Title", "Sample Subtitle", "Primary Text Block", "Secondary Text Block") ' Custom class whose instances are used as DataContext public class AlertData public AlertData(String title, String subtitle, String primaryText, String secondaryText) Title = title Subtitle = subtitle PrimaryText = primaryText SecondaryText = secondaryText public String Title {get;set;} public String Subtitle {get;set;} public String PrimaryText {get;set;} public String SecondaryText {get;set;}
點(diǎn)擊復(fù)制
管理通知
所有的AlertControl設(shè)置指定的位置和行為的常規(guī)警報(bào)窗口也可以用于模板警報(bào):
- FormLocation
- AutoFormDelay
- FormDisplaySpeed
- FormShowingEffect
- FormMaxCount
要關(guān)閉和固定模板警報(bào),您可以創(chuàng)建具有唯一id的按鈕,并處理AlertControl.HtmlElementMouseClick事件。
HTML:
<div id="pinButton" class="button">Pin</div> <div id="closeButton" class="button">Close</div>
點(diǎn)擊復(fù)制
C#:
private void OnHtmlElementMouseClick(object sender, AlertHtmlElementMouseEventArgs e) { if (e.ElementId == "pinButton") e.HtmlPopup.Pinned = !e.HtmlPopup.Pinned; if (e.ElementId == "closeButton") e.HtmlPopup.Close(); }
點(diǎn)擊復(fù)制
VB.NET:
Private Sub OnHtmlElementMouseClick(ByVal sender As Object, ByVal e As AlertHtmlElementMouseEventArgs) If e.ElementId = "pinButton" Then e.HtmlPopup.Pinned = Not e.HtmlPopup.Pinned End If If e.ElementId = "closeButton" Then e.HtmlPopup.Close() End If End Sub
點(diǎn)擊復(fù)制
RaiseHtmlElementClick方法允許手動(dòng)觸發(fā)與所需HTML元素相關(guān)的操作(使用唯一的元素id來標(biāo)識(shí)HTML元素)。
C#:
alertControl1.RaiseHtmlElementClick("closeButton", e.HtmlPopup);
點(diǎn)擊復(fù)制
VB.NET:
alertControl1.RaiseHtmlElementClick("closeButton", e.HtmlPopup)
點(diǎn)擊復(fù)制