首页 > 其他分享 >wpf最简单进度条

wpf最简单进度条

时间:2023-01-05 20:44:55浏览次数:36  
标签:进度条 Windows Media Window1 System Threading 简单 using wpf

 

<Window x:Class="WpfApp1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        
        Title="gisoracle进度条" Height="200" Width="600" WindowStartupLocation="CenterScreen"  
        >
    <Grid Margin="100,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="80" />
            <RowDefinition Height="100" />
            <RowDefinition Height="Auto" />
          
        </Grid.RowDefinitions>
        <Label  Name="label1"  Content="进度条提示"></Label>
        <ProgressBar
        Name="ProgressBar"
        Grid.Row="0"
        Width="400"
        Height="30"
        Maximum="100"
        Minimum="0" />
        <DockPanel Grid.Row="1" LastChildFill="False">
            <Button
            
            Click="Download_OnClick"
            Content="确定"
            DockPanel.Dock="Right" Width="100" Height="30" />
        </DockPanel>
    </Grid>


</Window>

代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading;
 6 using System.Threading.Tasks;
 7 using System.Windows;
 8 using System.Windows.Controls;
 9 using System.Windows.Data;
10 using System.Windows.Documents;
11 using System.Windows.Input;
12 using System.Windows.Media;
13 using System.Windows.Media.Imaging;
14 using System.Windows.Shapes;
15 using System.Windows.Threading;
16 
17 namespace WpfApp1
18 {
19     /// <summary>
20     /// Window1.xaml 的交互逻辑
21     /// </summary>
22     public partial class Window1 : Window
23     {
24         public Window1()
25         {
26             InitializeComponent();
27         }
28 
29         /// <summary>
30         /// Download按钮点击事件
31         /// </summary>
32         /// <param name="sender"></param>
33         /// <param name="e"></param>
34         private void Download_OnClick(object sender, RoutedEventArgs e)
35         {
36             Task task = new Task(TaskMethod);
37             task.Start();
38         }
39 
40         private void TaskMethod()
41         {
42             for (int i = 1; i <= 100; i++)
43             {
44                 Thread.Sleep(50);
45                 
46                 Dispatcher.BeginInvoke((ThreadStart)delegate
47                 {
48                     if (i<=100)
49                     {
50                         label1.Content = i.ToString() + "%";
51                         ProgressBar.Value = i;
52                     }
53 
54                 }, DispatcherPriority.Normal);
55             }
56         }
57 
58     }
59 }

 

标签:进度条,Windows,Media,Window1,System,Threading,简单,using,wpf
From: https://www.cnblogs.com/gisoracle/p/17028805.html

相关文章

  • dremio PrivilegeCatalog 接口简单说明
    PrivilegeCatalog实际是一个权限检查的能力,同时dremio的StoragePlugin也提供了一个安全check能力StoragePlugin安全检查booleanhasAccessPermission(Str......
  • 实现简单的csv文件上传和bootstrap表格的下载
    一、写一个简单的页面并发送文件引入bootstrap.js,jQuery.js等,具体的网页就不细写了,很简单。加入input框,button控件,进度条。如下:<liclass="list-group-item"......
  • Android 如何 简单的添加 启动页 SplashScreen
    1.在AndroidApp启动中,为了体验优化,各大App都是有添加启动页的,比较土的方法就是直接弄个loadingActivity,充当启动页,在启动初始化相关工作做完以后,再跳......
  • 简单的C#&PHP对称加解密
    byte[]ctxbytes=System.Text.Encoding.UTF8.GetBytes(ctx);byte[]keybytes=System.Text.Encoding.UTF8.GetBytes(key);intctxLen=ctxbytes.Length......
  • WPF-‘_’在Lable中显示为文字的下划线不独立显示的问题。
    一、原因:  ‘_’在WPF中用于表示访问键。二、对策:  建立新样式,并关闭lable对快捷键的自动处理:RecognizesAccessKey="True"=》"False",如下:<!--不对下划......
  • 简单使用SimpleCursorAdapter
     如果使用Sqlite,建议和ContentProvider结合使用。这样数据库的生命周期就不用自己管了。然后,如果要在比如ListView中显示,可以使用CursorAdapter。简化的办法是使用子类Simp......
  • android Service 的简单使用
    androidService的简单使用1、要使用Service,首先就是在配置文件里吗添加Service,如果不填加,你的Service是不能够使用的。目前学到的方法有两种  方法一:<serviceandroi......
  • 用Python来做一个简单的学生管理系统(附源码)
    小学妹说要毕业了,学了一学期Python等于没学,现在要做毕设做不出来,让我帮帮她,晚上去她家吃夜宵。当时我心想,这不是分分钟的事情,还要去她家,男孩子晚上不要随便出门,要学会......
  • 关于使用gdb调试c代码的简单教程
    因个人此前调试c代码的时候只会在代码中加打印信息,然后编译代码,运行程序,搜索打印信息,查找问题...因此代码的调试效率很慢,经大佬提示使用gdb调试后,代码的调试效率提高了不少......
  • Java简单仿制在创建同名目录时名称拼接(数字)
    /***创建同名文件名称拼接(数字)**@parampath需要创建的目录*@return*/publicstaticStringrecursionMkdirsFile(Stringpat......