├── src ├── ProgressDialogEx │ ├── App.xaml.cs │ ├── app.config │ ├── packages.config │ ├── ProgressDialog │ │ ├── ProgressDialogOptions.cs │ │ ├── ProgressDialogWindow.xaml.cs │ │ ├── CancelCommand.cs │ │ ├── ProgressDialogWindow.xaml │ │ ├── ProgressDialogWindowViewModel.cs │ │ ├── IProgressDialogService.cs │ │ └── ProgressDialogService.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── App.xaml │ ├── AttachedProperties │ │ ├── DialogCloser.cs │ │ └── WindowBehavior.cs │ ├── MyLongRunningCommand.cs │ ├── MainWindow.xaml │ ├── ProgressDialogEx.csproj │ └── MainWindow.xaml.cs └── ProgressDialogEx.sln ├── .gitignore └── README.md /src/ProgressDialogEx/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace ProgressDialogEx 4 | { 5 | public partial class App : Application 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/ProgressDialogEx/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/ProgressDialogEx/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/ProgressDialogEx/ProgressDialog/ProgressDialogOptions.cs: -------------------------------------------------------------------------------- 1 | namespace ProgressDialogEx.ProgressDialog 2 | { 3 | public class ProgressDialogOptions 4 | { 5 | public string WindowTitle { get; set; } 6 | public string Label { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/ProgressDialogEx/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyProduct("ProgressDialogEx")] 5 | 6 | [assembly: ComVisible(false)] 7 | 8 | [assembly: AssemblyVersion("1.0.0.0")] 9 | [assembly: AssemblyFileVersion("1.0.0.0")] 10 | -------------------------------------------------------------------------------- /src/ProgressDialogEx/ProgressDialog/ProgressDialogWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace ProgressDialogEx.ProgressDialog 4 | { 5 | /// 6 | /// Interaction logic for ProgressDialog.xaml 7 | /// 8 | public partial class ProgressDialogWindow : Window 9 | { 10 | public ProgressDialogWindow() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/ProgressDialogEx/App.xaml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/ProgressDialogEx/AttachedProperties/DialogCloser.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace ProgressDialogEx.AttachedProperties 4 | { 5 | // From 6 | public static class DialogCloser 7 | { 8 | public static readonly DependencyProperty DialogResultProperty = 9 | DependencyProperty.RegisterAttached( 10 | "DialogResult", 11 | typeof(bool?), 12 | typeof(DialogCloser), 13 | new PropertyMetadata(DialogResultChanged)); 14 | 15 | private static void DialogResultChanged( 16 | DependencyObject d, 17 | DependencyPropertyChangedEventArgs e) 18 | { 19 | var window = d as Window; 20 | if (window != null && (bool?) e.NewValue == true) 21 | window.Close(); 22 | } 23 | 24 | public static void SetDialogResult(Window target, bool? value) 25 | { 26 | target.SetValue(DialogResultProperty, value); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/ProgressDialogEx/ProgressDialog/CancelCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Windows.Input; 4 | 5 | namespace ProgressDialogEx.ProgressDialog 6 | { 7 | public class CancelCommand : ICommand 8 | { 9 | readonly CancellationTokenSource cancellationTokenSource; 10 | 11 | public event EventHandler CanExecuteChanged; 12 | 13 | public CancelCommand(CancellationTokenSource cancellationTokenSource) 14 | { 15 | if (cancellationTokenSource == null) throw new ArgumentNullException("cancellationTokenSource"); 16 | this.cancellationTokenSource = cancellationTokenSource; 17 | } 18 | 19 | public bool CanExecute(object parameter) 20 | { 21 | return !cancellationTokenSource.IsCancellationRequested; 22 | } 23 | 24 | public void Execute(object parameter) 25 | { 26 | cancellationTokenSource.Cancel(); 27 | 28 | if (CanExecuteChanged != null) 29 | CanExecuteChanged(this, EventArgs.Empty); 30 | 31 | CommandManager.InvalidateRequerySuggested(); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/ProgressDialogEx.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgressDialogEx", "ProgressDialogEx\ProgressDialogEx.csproj", "{85C1B8BF-A213-4C8F-BD62-FBFD953CBB7C}" 5 | EndProject 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{D69881D8-E47F-4A83-ACD6-0D49E6D2464E}" 7 | ProjectSection(SolutionItems) = preProject 8 | .nuget\NuGet.Config = .nuget\NuGet.Config 9 | .nuget\NuGet.exe = .nuget\NuGet.exe 10 | .nuget\NuGet.targets = .nuget\NuGet.targets 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|x86 = Debug|x86 16 | Release|x86 = Release|x86 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {85C1B8BF-A213-4C8F-BD62-FBFD953CBB7C}.Debug|x86.ActiveCfg = Debug|x86 20 | {85C1B8BF-A213-4C8F-BD62-FBFD953CBB7C}.Debug|x86.Build.0 = Debug|x86 21 | {85C1B8BF-A213-4C8F-BD62-FBFD953CBB7C}.Release|x86.ActiveCfg = Release|x86 22 | {85C1B8BF-A213-4C8F-BD62-FBFD953CBB7C}.Release|x86.Build.0 = Release|x86 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /src/ProgressDialogEx/MyLongRunningCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using System.Windows; 5 | using System.Windows.Input; 6 | using ProgressDialogEx.ProgressDialog; 7 | 8 | namespace ProgressDialogEx 9 | { 10 | public class MyLongRunningCommand : ICommand 11 | { 12 | readonly IProgressDialogService dialogService; 13 | 14 | public MyLongRunningCommand(IProgressDialogService dialogService) 15 | { 16 | this.dialogService = dialogService; 17 | } 18 | 19 | public void Execute(object parameter) 20 | { 21 | Task task = dialogService.ExecuteAsync(DoWork, new ProgressDialogOptions { WindowTitle = "Loading files" }); 22 | 23 | MessageBox.Show(String.Format("Result = {0}", task.Result)); 24 | } 25 | 26 | static async Task DoWork(CancellationToken cancellationToken, IProgress progress) 27 | { 28 | return await Task.Factory.StartNew(() => progress.Report("First"), cancellationToken) 29 | .ContinueWith(_ => Thread.Sleep(1000), cancellationToken) 30 | .ContinueWith(_ => progress.Report("Second"), cancellationToken) 31 | .ContinueWith(_ => Thread.Sleep(1000), cancellationToken) 32 | .ContinueWith(_ => 42); 33 | } 34 | 35 | public bool CanExecute(object parameter) 36 | { 37 | return true; 38 | } 39 | 40 | public event EventHandler CanExecuteChanged; 41 | } 42 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Rr]elease/ 19 | x64/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.log 36 | *.vspscc 37 | *.vssscc 38 | .builds 39 | 40 | # Visual C++ cache files 41 | ipch/ 42 | *.aps 43 | *.ncb 44 | *.opensdf 45 | *.sdf 46 | 47 | # Visual Studio profiler 48 | *.psess 49 | *.vsp 50 | *.vspx 51 | 52 | # Guidance Automation Toolkit 53 | *.gpState 54 | 55 | # ReSharper is a .NET coding add-in 56 | _ReSharper* 57 | 58 | # NCrunch 59 | *.ncrunch* 60 | .*crunch*.local.xml 61 | 62 | # Installshield output folder 63 | [Ee]xpress 64 | 65 | # DocProject is a documentation generator add-in 66 | DocProject/buildhelp/ 67 | DocProject/Help/*.HxT 68 | DocProject/Help/*.HxC 69 | DocProject/Help/*.hhc 70 | DocProject/Help/*.hhk 71 | DocProject/Help/*.hhp 72 | DocProject/Help/Html2 73 | DocProject/Help/html 74 | 75 | # Click-Once directory 76 | publish 77 | 78 | # Publish Web Output 79 | *.Publish.xml 80 | 81 | # NuGet Packages Directory 82 | packages 83 | 84 | # Windows Azure Build Output 85 | csx 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | [Bb]in 93 | [Oo]bj 94 | sql 95 | TestResults 96 | [Tt]est[Rr]esult* 97 | *.Cache 98 | ClientBin 99 | [Ss]tyle[Cc]op.* 100 | ~$* 101 | *.dbmdl 102 | Generated_Code #added for RIA/Silverlight projects 103 | 104 | # Backup & report files from converting an old project file to a newer 105 | # Visual Studio version. Backup files are not needed, because we have git ;-) 106 | _UpgradeReport_Files/ 107 | Backup*/ 108 | UpgradeLog*.XML 109 | -------------------------------------------------------------------------------- /src/ProgressDialogEx/ProgressDialog/ProgressDialogWindow.xaml: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 |