背水一戰 Windows 10 (106) - 通知(Toast): 經過 toast 打開協議, 經過 toast 選擇在指定的時間以後延遲提醒或者取消延遲提醒

[源碼下載]


html

背水一戰 Windows 10 (106) - 通知(Toast): 經過 toast 打開協議, 經過 toast 選擇在指定的時間以後延遲提醒或者取消延遲提醒



做者:webabcd


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

  • 經過 toast 打開協議
  • 經過 toast 選擇在指定的時間以後延遲提醒或者取消延遲提醒



示例
一、本例用於演示如何經過 toast 打開指定的協議
Notification/Toast/LaunchProtocol.xamlc++

<Page
    x:Class="Windows10.Notification.Toast.LaunchProtocol"
    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(打開 http 協議)" Click="buttonShowToast1_Click" Margin="5" />

            <Button Name="buttonShowToast2" Content="顯示 toast(打開 webabcd 協議)" Click="buttonShowToast2_Click" Margin="5" />

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

Notification/Toast/LaunchProtocol.xaml.csweb

/*
 * 本例用於演示如何經過 toast 打開指定的協議
 * 
 * 
 * 本例 xml 說明:
 * activationType - 經過點擊 toast 激活 app 時的激活方式,protocol 表明打開指定的協議
 * launch - 協議地址
 *
 * 
 * 注:經過 toast 中的按鈕打開指定協議也是相似的,示例以下
 * <action content='打開' activationType='protocol' arguments='http://webabcd.cnblogs.com/' />
 */

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 LaunchProtocol : Page
    {
        public LaunchProtocol()
        {
            this.InitializeComponent();
        }

        // 彈出 toast 通知(打開 http 協議)
        private void buttonShowToast1_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='protocol' launch='http://webabcd.cnblogs.com/'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>toast - content 1</text>
                        </binding>
                    </visual>
                </toast>";

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

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

        // 彈出 toast 通知(打開 webabcd 協議)
        // 關於 webabcd 協議的支持,請參見 /AssociationLaunching/ProtocolAssociation.xaml.cs
        private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='protocol' launch='webabcd:data'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>toast - content 2</text>
                        </binding>
                    </visual>
                </toast>";

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

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


二、本例用於演示如何經過 toast 選擇在指定的時間以後延遲提醒或者取消延遲提醒
Notification/Toast/SnoozeAndDismiss.xamlexpress

<Page
    x:Class="Windows10.Notification.Toast.SnoozeAndDismiss"
    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">

    <StackPanel Margin="10 0 10 10">

        <Button Name="buttonShowToast1" Content="彈出 snooze and dismiss toast 通知(由系統設置下拉框和按鈕)" Click="buttonShowToast1_Click" Margin="5" />

        <Button Name="buttonShowToast2" Content="彈出 snooze and dismiss toast 通知(自定義下拉框,由系統設置按鈕文字)" Click="buttonShowToast2_Click" Margin="5" />

        <Button Name="buttonShowToast3" Content="彈出 snooze and dismiss toast 通知(自定義下拉框,自定義按鈕文字)" Click="buttonShowToast3_Click" Margin="5" />

    </StackPanel>
</Page>

Notification/Toast/SnoozeAndDismiss.xaml.cswindows

/*
 * 本例用於演示如何經過 toast 選擇在指定的時間以後延遲提醒或者取消延遲提醒
 * 單擊 toast 激活 app 後(前臺方式激活),如何獲取相關信息請參見 Demo.xaml.cs 中的代碼
 * 
 * 
 * 本例 xml 說明:
 * hint-systemCommands - 當此值爲 SnoozeAndDismiss 時,則由系統設置下拉框和按鈕,並由系統處理相關行爲
 * action - 按鈕(如下說明以 activationType='system' 爲例)
 *     activationType - 單擊此按鈕激活 app 時的激活方式,system 表明由系統處理相關行爲
 *     content - 按鈕上顯示的文本,不指定的話則由系統設置
 *     arguments - snooze 表明延遲按鈕;dismiss 表明取消按鈕
 *     hint-inputId - 用戶選擇延遲時間的下拉框的 id
 * 
 * 
 * 注:
 * 所謂的 snooze and dismiss 指的是:snooze - 在指定的時間以後延遲提醒,dismiss - 取消延遲提醒
 */

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 SnoozeAndDismiss : Page
    {
        public SnoozeAndDismiss()
        {
            this.InitializeComponent();
        }

        // 彈出 snooze and dismiss toast 通知(由系統設置下拉框和按鈕)
        private void buttonShowToast1_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-SnoozeAndDismiss-Arguments 1'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>snooze and dismiss</text>
                            <text>單擊按鈕後的行爲由系統處理</text>
                        </binding>
                    </visual>
                    <actions hint-systemCommands='SnoozeAndDismiss' />
                </toast>";

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

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

        // 彈出 snooze and dismiss toast 通知(自定義下拉框,由系統設置按鈕文字)
        private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-SnoozeAndDismiss-Arguments 2'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>snooze and dismiss</text>
                            <text>單擊按鈕後的行爲由系統處理</text>
                        </binding>
                    </visual>
                    <actions>
                        <input id='snoozeTime' type='selection' defaultInput='1'>
                            <selection id='1' content='1 分鐘'/>
                            <selection id='2' content='2 分鐘'/>
                            <selection id='5' content='5 分鐘'/>
                        </input>
                        <action activationType='system' arguments='snooze' hint-inputId='snoozeTime' content='' />
                        <action activationType='system' arguments='dismiss' content='' />
                    </actions>
                </toast>";

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

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

        // 彈出 snooze and dismiss toast 通知(自定義下拉框,自定義按鈕文字)
        private void buttonShowToast3_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的以前的所有 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-SnoozeAndDismiss-Arguments 3'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>snooze and dismiss</text>
                            <text>單擊按鈕後的行爲由系統處理</text>
                        </binding>
                    </visual>
                    <actions>
                        <input id='snoozeTime' type='selection' defaultInput='1'>
                            <selection id='1' content='1 分鐘'/>
                            <selection id='2' content='2 分鐘'/>
                            <selection id='5' content='5 分鐘'/>
                        </input>
                        <action activationType='system' arguments='snooze' hint-inputId='snoozeTime' content='延遲' />
                        <action activationType='system' arguments='dismiss' content='取消' />
                    </actions>
                </toast>";

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

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



OK
[源碼下載]app

相關文章
相關標籤/搜索