@@ -24,7 +24,7 @@ namespace Ookii.Dialogs.Wpf
24
24
/// </remarks>
25
25
/// <threadsafety static="true" instance="false" />
26
26
[ DefaultEvent ( "DoWork" ) , DefaultProperty ( "Text" ) , Description ( "Represents a dialog that can be used to report progress to the user." ) ]
27
- public partial class ProgressDialog : Component
27
+ public partial class ProgressDialog : Component , IProgress < int > , IProgress < string >
28
28
{
29
29
private class ProgressChangedData
30
30
{
@@ -42,6 +42,7 @@ private class ProgressChangedData
42
42
private bool _useCompactPathsForDescription ;
43
43
private SafeModuleHandle _currentAnimationModuleHandle ;
44
44
private bool _cancellationPending ;
45
+ private int _percentProgress ;
45
46
46
47
/// <summary>
47
48
/// Event raised when the dialog is displayed.
@@ -518,6 +519,24 @@ public void ShowDialog(Window owner, object argument)
518
519
RunProgressDialog ( owner == null ? NativeMethods . GetActiveWindow ( ) : new WindowInteropHelper ( owner ) . Handle , argument ) ;
519
520
}
520
521
522
+ /// <summary>
523
+ /// Updates the dialog's progress bar.
524
+ /// </summary>
525
+ /// <param name="value">The percentage, from 0 to 100, of the operation that is complete.</param>
526
+ void IProgress < int > . Report ( int value )
527
+ {
528
+ ReportProgress ( value , null , null , null ) ;
529
+ }
530
+
531
+ /// <summary>
532
+ /// Updates the dialog's progress bar.
533
+ /// </summary>
534
+ /// <param name="value">The new value of the progress dialog's primary text message, or <see langword="null"/> to leave the value unchanged.</param>
535
+ void IProgress < string > . Report ( string value )
536
+ {
537
+ ReportProgress ( _percentProgress , value , null , null ) ;
538
+ }
539
+
521
540
/// <summary>
522
541
/// Updates the dialog's progress bar.
523
542
/// </summary>
@@ -568,6 +587,10 @@ public void ReportProgress(int percentProgress, string text, string description,
568
587
throw new ArgumentOutOfRangeException ( "percentProgress" ) ;
569
588
if ( _dialog == null )
570
589
throw new InvalidOperationException ( Properties . Resources . ProgressDialogNotRunningError ) ;
590
+
591
+ // we need to cache the latest percentProgress so IProgress<string>.Report(text) can report the percent progress correctly.
592
+ _percentProgress = percentProgress ;
593
+
571
594
_backgroundWorker . ReportProgress ( percentProgress , new ProgressChangedData ( ) { Text = text , Description = description , UserState = userState } ) ;
572
595
}
573
596
0 commit comments