zoukankan      html  css  js  c++  java
  • win8开发笔记6 消息框

    直接上代码:

    1. 界面上添加三个按钮和一个提示框:

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
                <StackPanel VerticalAlignment="Center" Margin="34,558,-34,137">
                    <StackPanel Orientation="Horizontal">
                        <Button Content="一个按钮的消息框" Click="onOKClick"/>
                        <Button Content="两个按钮的消息框" Click="onYesNoClick"/>
                        <Button Content="三个按钮的消息框" Click="onThirdClick"/>
                    </StackPanel>
                <TextBlock x:Name="tbTip" Margin="3,6,0,0" FontSize="24"/>
            </StackPanel>
            </Grid>

    2. 相关函数如下:

            private async void onOKClick(object sender, RoutedEventArgs e)
            {
                MessageDialog msg = new MessageDialog("只带一个按钮的消息框。", "提示");
                msg.Commands.Add(new UICommand("确定", new UICommandInvokedHandler(OnUICommand)));
                await msg.ShowAsync();
            }
    
            private async void onYesNoClick(object sender, RoutedEventArgs e)
            {
                MessageDialog msg = new MessageDialog("带两个按钮的消息框。");
                msg.Commands.Add(new UICommand("", new UICommandInvokedHandler(OnUICommand)));
                msg.Commands.Add(new UICommand("", new UICommandInvokedHandler(OnUICommand)));
                await msg.ShowAsync();
            }
    
            private async void onThirdClick(object sender, RoutedEventArgs e)
            {
                MessageDialog msg = new MessageDialog("带三个按钮的消息框。");
                msg.Commands.Add(new UICommand("重试", new UICommandInvokedHandler(OnUICommand)));
                msg.Commands.Add(new UICommand("忽略", new UICommandInvokedHandler(OnUICommand)));
                msg.Commands.Add(new UICommand("取消", new UICommandInvokedHandler(OnUICommand)));
                // 默认按钮索引   
                msg.CancelCommandIndex = 2;
                msg.DefaultCommandIndex = 0;
                await msg.ShowAsync();
            }
    
            async void OnUICommand(IUICommand cmd)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>
                    {
                        this.tbTip.Text = "您点击了 " + cmd.Label + " 按钮。";
                    });
            }  
  • 相关阅读:
    一、【注解】Spring注解@ComponentScan
    一致性Hash算法
    垃圾回收器搭配和调优
    JVM的逃逸分析
    简单理解垃圾回收
    类加载机制和双亲委派模型
    VMWare15下安装CentOS7
    HBase协处理器(1)
    依赖注入的三种方式
    Javascript-设计模式_装饰者模式
  • 原文地址:https://www.cnblogs.com/Roarsun/p/2828665.html
Copyright © 2011-2022 走看看