背水一戰 Windows 10 (105) - 通知(Toast): 帶按鈕的 toast, 帶輸入的 toast(文本輸入框,下拉選擇框)

[源碼下載]


html

背水一戰 Windows 10 (105) - 通知(Toast): 帶按鈕的 toast, 帶輸入的 toast(文本輸入框,下拉選擇框)



做者:webabcd


介紹
背水一戰 Windows 10 之 通知(Toast)html5

  • 帶按鈕的 toast
  • 帶輸入的 toast(文本輸入框,下拉選擇框)



示例
一、本例用於演示如何彈出帶按鈕的 toast
Notification/Toast/ActionButton.xamlc++

<Page
    x:Class="Windows10.Notification.Toast.ActionButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Notification.Toast"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <Button Name="buttonShowToast1" Content="顯示 toast(文本按鈕)" Click="buttonShowToast1_Click" Margin="5" />

            <Button Name="buttonShowToast2" Content="顯示 toast(圖文按鈕)" Click="buttonShowToast2_Click" Margin="5" />

        </StackPanel>
    </Grid>
</Page>

Notification/Toast/ActionButton.xaml.csweb

/*
 * 本例用於演示如何彈出帶按鈕的 toast
 * 單擊 toast 激活 app 後(前臺方式激活),如何獲取相關信息請參見 Demo.xaml.cs 中的代碼
 * 
 * 
 * 本例 xml 說明:
 * activationType - 經過點擊 toast 激活 app 時的激活方式,foreground 表明前臺方式激活
 * launch - 經過點擊 toast 激活 app 時,傳遞給 app 的參數(經過按鈕激活時,此參數無效)
 * template - 在 uwp 中就 ToastGeneric 一種模板
 * text - 每個新的 text 會另起一行,一行顯示不下會自動換行,第一個 text 會高亮顯示,最多顯示 5 行文本
 * action - 按鈕,最多顯示 5 個按鈕
 *     content - 按鈕上顯示的文本
 *     activationType - 單擊此按鈕激活 app 時的激活方式,foreground 表明前臺方式激活
 *     arguments - 單擊此按鈕激活 app 時,傳遞給 app 的參數
 *     imageUri - 圖文按鈕上顯示的圖標
 */

using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Windows10.Notification.Toast
{
    public sealed partial class ActionButton : Page
    {
        public ActionButton()
        {
            this.InitializeComponent();
        }

        // 彈出 toast 通知(文本按鈕)
        private void buttonShowToast1_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-ActionButton-Arguments 1'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>""Hololens""引領技術革命浪潮傳統的人機交互,主要是經過鍵盤和觸摸,包括並不能被精確識別的語音等。""Hololens""的出現,則給新一代體驗更好的人機交互指明道路,並現實了設備的小型化和便攜化。</text>
                        </binding>
                    </visual>
                    <actions>
                        <action content='確認' activationType='foreground' arguments='Notification-Toast-ActionButton-Arguments 1 confirm'/>
                        <action content='取消' activationType='foreground' arguments='Notification-Toast-ActionButton-Arguments 1 cancel' imageUri='Assets/StoreLogo.png' />
                    </actions>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();
            toastDoc.LoadXml(toastXml);

            ToastNotification toastNotification = new ToastNotification(toastDoc);
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
            toastNotifier.Show(toastNotification);
        }

        // 彈出 toast 通知(圖文按鈕)
        private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-ActionButton-Arguments 2'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>""Hololens""引領技術革命浪潮傳統的人機交互,主要是經過鍵盤和觸摸,包括並不能被精確識別的語音等。""Hololens""的出現,則給新一代體驗更好的人機交互指明道路,並現實了設備的小型化和便攜化。</text>
                        </binding>
                    </visual>
                    <actions>
                        <action content='確認' activationType='foreground' arguments='Notification-Toast-ActionButton-Arguments 2 confirm' imageUri='Assets/StoreLogo.png' />
                        <action content='取消' activationType='foreground' arguments='Notification-Toast-ActionButton-Arguments 2 cancel' imageUri='Assets/StoreLogo.png' />
                    </actions>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();
            toastDoc.LoadXml(toastXml);

            ToastNotification toastNotification = new ToastNotification(toastDoc);
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
            toastNotifier.Show(toastNotification);
        }
    }
}


二、本例用於演示如何彈出帶輸入的 toast(文本輸入框,下拉選擇框)
Notification/Toast/ActionInput.xamlexpress

<Page
    x:Class="Windows10.Notification.Toast.ActionInput"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Notification.Toast"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <Button Name="buttonShowToast1" Content="顯示 toast(文本輸入框)" Click="buttonShowToast1_Click" Margin="5" />

            <Button Name="buttonShowToast2" Content="顯示 toast(文本輸入框與快速應答)" Click="buttonShowToast2_Click" Margin="5" />

            <Button Name="buttonShowToast3" Content="顯示 toast(下拉選擇框)" Click="buttonShowToast3_Click" Margin="5" />

        </StackPanel>
    </Grid>
</Page>

Notification/Toast/ActionInput.xaml.cswindows

/*
 * 本例用於演示如何彈出帶輸入的 toast(文本輸入框,下拉選擇框)
 * 單擊 toast 激活 app 後(前臺方式激活),如何獲取相關信息請參見 Demo.xaml.cs 中的代碼
 * 
 * 
 * 本例 xml 說明:
 * activationType - 經過點擊 toast 激活 app 時的激活方式,foreground 表明前臺方式激活
 * launch - 經過點擊 toast 激活 app 時,傳遞給 app 的參數(經過按鈕激活時,此參數無效)
 * template - 在 uwp 中就 ToastGeneric 一種模板
 * text - 每個新的 text 會另起一行,一行顯示不下會自動換行,第一個 text 會高亮顯示,最多顯示 5 行文本
 * input - 輸入框,最多顯示 5 個輸入框
 *     type - text 文本輸入框;selection 下拉選擇框(最多 5 條選項)
 *     id - 標識
 *     title - 輸入框上顯示的標題
 *     defaultInput - 輸入框內顯示的默認內容
 *     placeHolderContent - 輸入框內顯示的 placeHolder
 * action - 按鈕
 *     hint-inputId - 用於快速應答場景,指定快速應答的 input 的 id
 *         說明:當指定的 input 無內容時則按鈕不可點擊,當指定的 input 有內容時則按鈕可點擊(也能夠經過快捷鍵 ctrl + enter 發送)
 *     
 *     
 * 注:只有經過 toast 中的按鈕激活 app 時,input 中的內容纔會被傳遞(經過點擊 toast 激活 app 時,input 中的內容不會被傳遞)
 */

using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Windows10.Notification.Toast
{
    public sealed partial class ActionInput : Page
    {
        public ActionInput()
        {
            this.InitializeComponent();
        }

        // 彈出 toast 通知(文本輸入框)
        private void buttonShowToast1_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-ActionInput-Arguments 1'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>""Hololens""引領技術革命浪潮傳統的人機交互,主要是經過鍵盤和觸摸,包括並不能被精確識別的語音等。""Hololens""的出現,則給新一代體驗更好的人機交互指明道路,並現實了設備的小型化和便攜化。</text>
                        </binding>
                    </visual>
                    <actions>
                        <input type='text' id='message1' title='title1' />
                        <input type='text' id='message2' title='title2' defaultInput='defaultInput'/>
                        <input type='text' id='message3' title='title3' placeHolderContent='placeHolderContent'/>
                        <action content='確認' activationType='foreground' arguments='Notification-Toast-ActionInput-Arguments 1 confirm'/>
                    </actions>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();
            toastDoc.LoadXml(toastXml);

            ToastNotification toast = new ToastNotification(toastDoc);
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }

        // 彈出 toast 通知(文本輸入框與快速應答)
        private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-ActionInput-Arguments 2'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>""Hololens""引領技術革命浪潮傳統的人機交互,主要是經過鍵盤和觸摸,包括並不能被精確識別的語音等。""Hololens""的出現,則給新一代體驗更好的人機交互指明道路,並現實了設備的小型化和便攜化。</text>
                        </binding>
                    </visual>
                    <actions>
                        <input id='message' type='text' />
                        <action content='確認' activationType='foreground' arguments='Notification-Toast-ActionInput-Arguments 2 confirm' 
                            hint-inputId='message' />
                    </actions>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();
            toastDoc.LoadXml(toastXml);

            ToastNotification toast = new ToastNotification(toastDoc);
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }

        // 彈出 toast 通知(下拉選擇框)
        private void buttonShowToast3_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-ActionInput-Arguments 3'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>""Hololens""引領技術革命浪潮傳統的人機交互,主要是經過鍵盤和觸摸,包括並不能被精確識別的語音等。""Hololens""的出現,則給新一代體驗更好的人機交互指明道路,並現實了設備的小型化和便攜化。</text>
                        </binding>
                    </visual>
                    <actions>
                        <input id ='select' type='selection' defaultInput='2'>
                            <selection id='1' content='1天' />
                            <selection id='2' content='2天' />
                            <selection id='3' content='3天' />
                            <selection id='4' content='4天' />
                            <selection id='5' content='5天' />
                        </input> 
                        <action content='確認' activationType='foreground' arguments='Notification-Toast-ActionInput-Arguments 3 confirm'/>
                    </actions>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();
            toastDoc.LoadXml(toastXml);

            ToastNotification toast = new ToastNotification(toastDoc);
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
    }
}



OK
[源碼下載]app

相關文章
相關標籤/搜索