progressbar

main
syneffort 2 years ago
parent 14086b24e3
commit ea8bc791de
  1. 6
      PacticeSolution/PacticeSolution.sln
  2. 9
      PacticeSolution/ProgressBarSample/App.xaml
  3. 17
      PacticeSolution/ProgressBarSample/App.xaml.cs
  4. 10
      PacticeSolution/ProgressBarSample/AssemblyInfo.cs
  5. 21
      PacticeSolution/ProgressBarSample/MainWindow.xaml
  6. 72
      PacticeSolution/ProgressBarSample/MainWindow.xaml.cs
  7. 10
      PacticeSolution/ProgressBarSample/ProgressBarSample.csproj

@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyboardInputSample", "Keyb
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TabControlSample", "TabControlSample\TabControlSample.csproj", "{7A148D37-36D1-43B5-A133-B02CE5CB743F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TabControlSample", "TabControlSample\TabControlSample.csproj", "{7A148D37-36D1-43B5-A133-B02CE5CB743F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgressBarSample", "ProgressBarSample\ProgressBarSample.csproj", "{EB304FB7-67EA-467E-9BE4-E55187415CAB}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -153,6 +155,10 @@ Global
{7A148D37-36D1-43B5-A133-B02CE5CB743F}.Debug|Any CPU.Build.0 = Debug|Any CPU {7A148D37-36D1-43B5-A133-B02CE5CB743F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A148D37-36D1-43B5-A133-B02CE5CB743F}.Release|Any CPU.ActiveCfg = Release|Any CPU {7A148D37-36D1-43B5-A133-B02CE5CB743F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A148D37-36D1-43B5-A133-B02CE5CB743F}.Release|Any CPU.Build.0 = Release|Any CPU {7A148D37-36D1-43B5-A133-B02CE5CB743F}.Release|Any CPU.Build.0 = Release|Any CPU
{EB304FB7-67EA-467E-9BE4-E55187415CAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB304FB7-67EA-467E-9BE4-E55187415CAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB304FB7-67EA-467E-9BE4-E55187415CAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB304FB7-67EA-467E-9BE4-E55187415CAB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -0,0 +1,9 @@
<Application x:Class="ProgressBarSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ProgressBarSample"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ProgressBarSample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

@ -0,0 +1,21 @@
<Window x:Class="ProgressBarSample.MainWindow"
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:ProgressBarSample"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="400">
<StackPanel>
<Button x:Name="btnStart" Width="100" Height="20" Margin="10"
Content="Start"
Click="btnStart_Click"/>
<Grid Width="200" Margin="10">
<ProgressBar x:Name="pgbMain" Height="15" VerticalAlignment="Center"
Minimum="0" Maximum="100" Value="30"/>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"
Text="{Binding ElementName=pgbMain, Path=Value, StringFormat={}{0:N2}%}"/>
</Grid>
</StackPanel>
</Window>

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
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 ProgressBarSample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private BackgroundWorker _worker;
public MainWindow()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
_worker = new BackgroundWorker();
_worker.WorkerReportsProgress = true;
_worker.DoWork -= OnWorker_DoWork;
_worker.ProgressChanged -= OnWorker_ProgressChanged;
_worker.RunWorkerCompleted -= OnWorker_RunWorkerCompleted;
_worker.DoWork += OnWorker_DoWork;
_worker.ProgressChanged += OnWorker_ProgressChanged;
_worker.RunWorkerCompleted += OnWorker_RunWorkerCompleted;
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
if (_worker.IsBusy)
return;
_worker.RunWorkerAsync();
}
private void OnWorker_RunWorkerCompleted(object? sender, RunWorkerCompletedEventArgs e)
{
pgbMain.Value = pgbMain.Maximum;
}
private void OnWorker_ProgressChanged(object? sender, ProgressChangedEventArgs e)
{
pgbMain.Value = (double)e.ProgressPercentage / 10.0;
}
private void OnWorker_DoWork(object? sender, DoWorkEventArgs e)
{
for (int i = 0; i < 1000; i++)
{
_worker.ReportProgress(i);
Thread.Sleep(10);
}
}
}
}

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
Loading…
Cancel
Save