WPF 进度条

一:简单常见

//window1.xaml
<Window x:Class="progressbartest.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="217" Width="300">
    <Grid>
        <ProgressBar Height="24" HorizontalAlignment="Left" Margin="12,72,0,0" Name="progressBar1" VerticalAlignment="Top" Width="254" Foreground="#FF2EAFF1" />
    </Grid>
</Window>


//window1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using System.Threading;

namespace progressbartest
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            ProgressBegin();

        }

        private void ProgressBegin()
        {

            Thread thread = new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i <= 100; i++)
                {
                    this.progressBar1.Dispatcher.BeginInvoke((ThreadStart)delegate { this.progressBar1.Value = i; });
                    Thread.Sleep(100);
                }

            }));
            thread.Start();
        }

    }
}

  效果图:

 

 

 二:斜纹渐变滚动条

https://www.cnblogs.com/lonelyxmas/p/10716917.html

三:类似于系统麦克风音量大小检测效果

 

 

 

<ListView x:Name="SpeakerPrograssListview" ItemContainerStyle="{StaticResource customProgressView}" ItemsSource="{Binding list1}"     HorizontalAlignment="Stretch" BorderThickness="0" Margin="12,0,0,0" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled"     ScrollViewer.VerticalScrollBarVisibility="Disabled">
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
    <WrapPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left" Background="Transparent" IsItemsHost="True">
    </WrapPanel>
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
</ListView>

<Style TargetType="ListViewItem" x:Key="customProgressView">
  <Setter Property="Template">
  <Setter.Value>
  <ControlTemplate TargetType="ListViewItem">
  <Grid Margin="3,0,3,0">
    <ProgressBar x:Name="proBar" Style="{DynamicResource SimpleProgressBar}" Maximum="10" Minimum="0" Width="6" Height="15" Background="#F2F3F7"   Foreground="#329FEE" Value="{Binding progressValue}" BorderBrush="Transparent" BorderThickness="0"></ProgressBar>
  </Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ProgressBar" x:Key="SimpleProgressBar">
<Setter Property="Background" Value="#F2F3F7" />
<Setter Property="Maximum" Value="1" />
<Setter Property="Value" Value="0" />
<Setter Property="Height" Value="10" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Foreground" Value="#329FEE" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Grid x:Name="Root" >
<Border x:Name="PART_Track" Background="{TemplateBinding Background}"
CornerRadius="0"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Border x:Name="PART_Indicator" HorizontalAlignment="Left" Background="{TemplateBinding Foreground}"
CornerRadius="0"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="LayoutTransform" TargetName="Root" >
<Setter.Value>
<RotateTransform Angle="-90" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

四:复杂的效果

https://www.cnblogs.com/dathlin/p/8150516.html

posted @ 2020-04-16 16:22  寒夜美美  阅读(1968)  评论(1编辑  收藏  举报