Win10的UWP之进度条

关于UWP的进度条的处理的方案有两种方案
我们新建一个项目,然后处理的界面如下的代码

<Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

            <TextBlock Text="选择" FontSize="20"
                       Grid.Row="0"
                       HorizontalAlignment="Center"/>
            <RadioButton Content="Determinate类型" 
                         Height="71" 
                         Name="radionButton1"
                         GroupName="Type"
                         Grid.Row="1"
                         HorizontalAlignment="Center"/>
            <RadioButton Content="Indeterminate类型"
                         Height="71"
                         Name="radioButton2"
                         GroupName="Type"
                         IsChecked="True"
                         Grid.Row="2"
                         HorizontalAlignment="Center"/>
            <Button Content="启动ProgressBar" 
                    Height="72"
                    x:Name="Begin"
                    Click="Begin_Click"
                    Grid.Row="3"
                    HorizontalAlignment="Center"/>
            <Button Content="取消ProgressBar"
                    Height="72"
                    x:Name="Cancel"
                    Click="Cancel_Click"
                    Grid.Row="4"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"/>
        <ProgressBar x:Name="ProgressBar" IsIndeterminate="True"
                         Grid.Row="5"
                     Height="24"/>

这里写图片描述

然后我们再来处理下界面的后台代码

public MainPage()
        {
            this.InitializeComponent();
            //初始化界面时,设置进度条不可见
            ProgressBar.Visibility = Visibility.Collapsed;
        }

        private void Begin_Click(object sender, RoutedEventArgs e)
        {
            //启动进度条,并可以显示状态
            ProgressBar.Visibility = Visibility.Visible;

            if (radionButton1.IsChecked==true)
            {
                //设置进度条的模式为不重复状态
                ProgressBar.IsIndeterminate = false;
                //启用定时器,再每下一秒改变原来的状态
                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(1);
                timer.Tick += timer_Tick;
                timer.Start();
            }
            else
            {
                ProgressBar.Value = 0;
                ProgressBar.IsIndeterminate = true;
            }
        }
        async void timer_Tick(object sender,object e)
        {
            if (ProgressBar.Value<100)
            {
                ProgressBar.Value += 10;
            }
            else
            {
                (sender as DispatcherTimer).Tick -= timer_Tick;
                (sender as DispatcherTimer).Stop();
                await new MessageDialog("进度100%").ShowAsync();
            }
        }
        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            ProgressBar.Visibility = Visibility.Collapsed;
        }

这里写图片描述

我们来看一下运行的效果吧
这里写图片描述

这里写图片描述

这里写图片描述

这是模拟了手机的界面运行的结果
这里写图片描述

这里写图片描述

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值