zoukankan      html  css  js  c++  java
  • 背水一战 Windows 10 (105)

    [源码下载]


    背水一战 Windows 10 (105) - 通知(Toast): 带按钮的 toast, 带输入的 toast(文本输入框,下拉选择框)



    作者:webabcd


    介绍
    背水一战 Windows 10 之 通知(Toast)

    • 带按钮的 toast
    • 带输入的 toast(文本输入框,下拉选择框)



    示例
    1、本例用于演示如何弹出带按钮的 toast
    Notification/Toast/ActionButton.xaml

    <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.cs

    /*
     * 本例用于演示如何弹出带按钮的 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);
            }
        }
    }


    2、本例用于演示如何弹出带输入的 toast(文本输入框,下拉选择框)
    Notification/Toast/ActionInput.xaml

    <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.cs

    /*
     * 本例用于演示如何弹出带输入的 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
    [源码下载]

  • 相关阅读:
    2018.8.20 Python之路---常用模块
    2018.8.16 正则表达式
    2018.8.15 python中的冒泡法排序
    2018.8.15 python 中的sorted()、filter()、map()函数
    2018.8.14 python中的内置函数(68个)
    2018.8.13 python中生成器和生成器表达式
    2018.8.10 python中的迭代器
    2018.8.9 python中的动态传参与命名空间
    python测试开发django(1)--开始Hello World!
    UPC-5120 Open-Pit Mining(最大权闭合子图)
  • 原文地址:https://www.cnblogs.com/webabcd/p/9202171.html
Copyright © 2011-2022 走看看