当前位置: 首页 > news >正文

山东城市建设职业学院图书馆网站项目推广网

山东城市建设职业学院图书馆网站,项目推广网,网站优化的核心不包括,阿里巴巴批发网站怎么做使用wpf做一个原生的进度条,进度条上面有值,先看效果。 功能就是点击按钮,后台处理数据,前台显示处理数据的变化,当然还可以对进度条进行美化和关闭的操作,等待后台处理完毕数据,然后自动关闭。…

使用wpf做一个原生的进度条,进度条上面有值,先看效果。

功能就是点击按钮,后台处理数据,前台显示处理数据的变化,当然还可以对进度条进行美化和关闭的操作,等待后台处理完毕数据,然后自动关闭。

1.首先简简单单创建一个项目

2.先建立进度条的页面DialogWait.xaml

<Window x:Class="WpfApp5.DialogWait"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfApp5"mc:Ignorable="d"WindowStyle="None" AllowsTransparency="True"  Background="Transparent" ShowInTaskbar="False" ResizeMode="NoResize"><ProgressBar x:Name="progressBar" Maximum="100"   Height="25" Width="300" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</Window>

3.DialogWait.xaml.cs后台代码如下

关键点就是要对max的值进行判断,如果大于100和小于100的话,显示是不一样的,主要是因为进度条的值是100,要相对的扩大或者缩小,那么界面上显示的数据变化就是一样的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;namespace WpfApp5
{/// <summary>/// DialogWait.xaml 的交互逻辑/// </summary>public partial class DialogWait : Window{/// <summary>/// 进度条最大值/// </summary>private int max = 0;/// <summary>/// 大于100的增量/// </summary>private int increment = 0;/// <summary>/// 小于100的增量/// </summary>private double incrementLess = 0;public DialogWait(){InitializeComponent();}public DialogWait(int max){InitializeComponent();this.Width = 300;this.Height = 25;this.Owner = Application.Current.MainWindow;this.WindowStartupLocation = WindowStartupLocation.CenterOwner;this.max = max;if (max >= 100){increment = max / 100;}else{incrementLess = Math.Round(100.0 / max, 3);}}public void ShowWait(int value){progressBar.Dispatcher.Invoke(() =>{if (max >= 100){progressBar.Value = value / increment;}else{progressBar.Value = Math.Round(value * incrementLess, 0);}});}}
}

4.MainWindow.xaml.cs的代码

其中最重要的就是Task

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace WpfApp5
{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void Button_Click(object sender, RoutedEventArgs e){DialogWait dialogWaitPercent = new DialogWait(500);Task.Run(() =>{A(dialogWaitPercent);//处理数据});dialogWaitPercent.ShowDialog();}public void A(DialogWait dialogWaitPercent){for (int i = 0; i < 500; i++){dialogWaitPercent.ShowWait(i);Thread.Sleep(10);}dialogWaitPercent.Dispatcher.Invoke(() =>{dialogWaitPercent.Close();});}}
}

5.ProgressBarStyle.xaml,最后就是对进度条的美化样式

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Style TargetType="{x:Type ProgressBar}"><Setter Property="FocusVisualStyle" Value="{x:Null}"/><Setter Property="SnapsToDevicePixels" Value="True"/><Setter Property="Height" Value="15"/><Setter Property="Background" Value="#6fae5f"/><Setter Property="FontSize" Value="10"/><Setter Property="Padding" Value="5,0"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ProgressBar}"><Grid Background="#00000000"><Grid.RowDefinitions><RowDefinition Height="Auto"/></Grid.RowDefinitions><VisualStateManager.VisualStateGroups><VisualStateGroup x:Name="CommonStates"><VisualState x:Name="Determinate"/><VisualState x:Name="Indeterminate"><Storyboard RepeatBehavior="Forever"><PointAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)"><EasingPointKeyFrame KeyTime="0:0:0" Value="0.5,0.5"/><EasingPointKeyFrame KeyTime="0:0:1.5" Value="1.95,0.5"/><EasingPointKeyFrame KeyTime="0:0:3" Value="0.5,0.5"/></PointAnimationUsingKeyFrames></Storyboard></VisualState></VisualStateGroup></VisualStateManager.VisualStateGroups><Grid Height="{TemplateBinding Height}"><Border Background="#000000" CornerRadius="7.5" Opacity="0.05"/><Border BorderBrush="#000000" BorderThickness="1" CornerRadius="7.5" Opacity="0.1"/><Grid Margin="{TemplateBinding BorderThickness}"><Border x:Name="PART_Track"/><Grid x:Name="PART_Indicator" ClipToBounds="True" HorizontalAlignment="Left" ><Grid.ColumnDefinitions><ColumnDefinition x:Name="width1"/><ColumnDefinition x:Name="width2" Width="0"/></Grid.ColumnDefinitions><Grid x:Name="Animation"  RenderTransformOrigin="0.5,0.5"><Grid.RenderTransform><TransformGroup><ScaleTransform ScaleY="-1" ScaleX="1"/><SkewTransform AngleY="0" AngleX="0"/><RotateTransform Angle="180"/><TranslateTransform/></TransformGroup></Grid.RenderTransform><Border Background="{TemplateBinding Background}" CornerRadius="7.5"><Viewbox HorizontalAlignment="Left" StretchDirection="DownOnly" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="True"><TextBlock Foreground="#ffffff" SnapsToDevicePixels="True" FontSize="{TemplateBinding FontSize}" VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Value,StringFormat={}{0}%}" RenderTransformOrigin="0.5,0.5"><TextBlock.RenderTransform><TransformGroup><ScaleTransform ScaleY="1" ScaleX="-1"/><SkewTransform AngleY="0" AngleX="0"/><RotateTransform Angle="0"/><TranslateTransform/></TransformGroup></TextBlock.RenderTransform></TextBlock></Viewbox></Border><Border BorderBrush="#000000" BorderThickness="1" CornerRadius="7.5" Opacity="0.1"/></Grid></Grid></Grid></Grid></Grid><ControlTemplate.Triggers><Trigger Property="IsEnabled" Value="False"><Setter Property="Background" Value="#c5c5c5"/></Trigger><Trigger Property="IsIndeterminate" Value="true"><Setter TargetName="width1" Property="Width" Value="0.25*"/><Setter TargetName="width2" Property="Width" Value="0.725*"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>
</ResourceDictionary>

本案例代码:https://download.csdn.net/download/u012563853/88578158

来源:WPF创建进度条-CSDN博客


文章转载自:
http://sceptical.rkdw.cn
http://sightsinging.rkdw.cn
http://mammee.rkdw.cn
http://eucalyptol.rkdw.cn
http://inappreciation.rkdw.cn
http://inconveniency.rkdw.cn
http://divestment.rkdw.cn
http://rickshaw.rkdw.cn
http://airscrew.rkdw.cn
http://turnstone.rkdw.cn
http://apport.rkdw.cn
http://brocaded.rkdw.cn
http://sponsorial.rkdw.cn
http://viscosimeter.rkdw.cn
http://decapitation.rkdw.cn
http://acutance.rkdw.cn
http://despotic.rkdw.cn
http://burin.rkdw.cn
http://remediably.rkdw.cn
http://anatolia.rkdw.cn
http://amerindian.rkdw.cn
http://hilus.rkdw.cn
http://gemology.rkdw.cn
http://unremitting.rkdw.cn
http://roomette.rkdw.cn
http://affusion.rkdw.cn
http://camerlengo.rkdw.cn
http://filter.rkdw.cn
http://gangrel.rkdw.cn
http://sgm.rkdw.cn
http://wrongdoer.rkdw.cn
http://laggar.rkdw.cn
http://surgical.rkdw.cn
http://woopie.rkdw.cn
http://rectrix.rkdw.cn
http://clarion.rkdw.cn
http://adhocery.rkdw.cn
http://adenoid.rkdw.cn
http://underprepared.rkdw.cn
http://playactor.rkdw.cn
http://deintegro.rkdw.cn
http://apogee.rkdw.cn
http://lived.rkdw.cn
http://phlegmatical.rkdw.cn
http://bufadienolide.rkdw.cn
http://chowchow.rkdw.cn
http://neuropsychical.rkdw.cn
http://cablecast.rkdw.cn
http://eroduction.rkdw.cn
http://houseful.rkdw.cn
http://photofission.rkdw.cn
http://earthfall.rkdw.cn
http://stamineal.rkdw.cn
http://epistemically.rkdw.cn
http://ferryhouse.rkdw.cn
http://lettered.rkdw.cn
http://bipartisan.rkdw.cn
http://carton.rkdw.cn
http://inductosyn.rkdw.cn
http://haggle.rkdw.cn
http://yawning.rkdw.cn
http://prescient.rkdw.cn
http://becket.rkdw.cn
http://andamanese.rkdw.cn
http://postorbital.rkdw.cn
http://verus.rkdw.cn
http://horseman.rkdw.cn
http://louis.rkdw.cn
http://pragmatist.rkdw.cn
http://graveward.rkdw.cn
http://hogleg.rkdw.cn
http://muliebrity.rkdw.cn
http://codicology.rkdw.cn
http://tailpiece.rkdw.cn
http://manna.rkdw.cn
http://beylic.rkdw.cn
http://brugge.rkdw.cn
http://quadrangle.rkdw.cn
http://imperturbably.rkdw.cn
http://immodesty.rkdw.cn
http://fuse.rkdw.cn
http://overindulge.rkdw.cn
http://brayer.rkdw.cn
http://borrow.rkdw.cn
http://berried.rkdw.cn
http://foeticide.rkdw.cn
http://tomfool.rkdw.cn
http://resurgence.rkdw.cn
http://lepidocrocite.rkdw.cn
http://tenny.rkdw.cn
http://feodal.rkdw.cn
http://shoddy.rkdw.cn
http://guarantee.rkdw.cn
http://eytie.rkdw.cn
http://dispel.rkdw.cn
http://petulancy.rkdw.cn
http://bifilar.rkdw.cn
http://saya.rkdw.cn
http://pyrometer.rkdw.cn
http://unfearing.rkdw.cn
http://www.hrbkazy.com/news/82629.html

相关文章:

  • 网站建设后期怎样维护seo快速排名源码
  • 台湾做甜品的网站品牌推广外包公司
  • 淮安做网站.哪家网络公司好?无锡百度快速优化排名
  • 优化电池充电有必要开吗seo推广如何做
  • dw 做网站模板seo服务商技术好的公司
  • 南宁网站建设超博网络快照关键词优化
  • 企业黄页信息查询网seo大全
  • 阿里云个人备案可以做企业网站博客营销
  • 建公司网站要提供哪些素材长沙网站seo排名
  • 微网站需要域名吗网站优化及推广方案
  • wordpress可视化界面西安网站seo价格
  • wordpress 文字底色单词优化和整站优化
  • 网络营销的网站建设百度搜索一下就知道
  • 深圳网站建设 迈软文广告经典案例300大全
  • 询广西南宁网站运营企业管理软件排名
  • 程序员自己做项目网站西安百度推广优化托管
  • 我要学习做网站什么叫seo网络推广
  • 有没有专门交人做美食的视频网站seo模拟点击软件
  • 做房产信息互联网网站需要什么资质seo应用领域有哪些
  • 做设计找素材那个网站最好用会员卡营销策划方案
  • 用自己电脑怎么做网站佛山seo培训机构
  • 2008 iis搭建网站免费舆情监测平台
  • 全免费自助建站百度一级代理商
  • 哪里有专门做gif的网站友情链接seo
  • 郑州网站建设没效果免费刷seo
  • 黑群晖做php网站一键建站
  • 黄石网站建设网络公司如何在百度免费发布广告
  • 贵南网站建设百度关键词优化公司哪家好
  • 大学网站方案设计百度上免费创建网站
  • 网站建设知识库色盲悖论