@@ -24,7 +24,7 @@ namespace Ookii.Dialogs.Wpf
2424 /// </remarks>
2525 /// <threadsafety static="true" instance="false" />
2626 [ 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 >
2828 {
2929 private class ProgressChangedData
3030 {
@@ -42,6 +42,7 @@ private class ProgressChangedData
4242 private bool _useCompactPathsForDescription ;
4343 private SafeModuleHandle _currentAnimationModuleHandle ;
4444 private bool _cancellationPending ;
45+ private int _percentProgress ;
4546
4647 /// <summary>
4748 /// Event raised when the dialog is displayed.
@@ -518,6 +519,24 @@ public void ShowDialog(Window owner, object argument)
518519 RunProgressDialog ( owner == null ? NativeMethods . GetActiveWindow ( ) : new WindowInteropHelper ( owner ) . Handle , argument ) ;
519520 }
520521
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+
521540 /// <summary>
522541 /// Updates the dialog's progress bar.
523542 /// </summary>
@@ -568,6 +587,10 @@ public void ReportProgress(int percentProgress, string text, string description,
568587 throw new ArgumentOutOfRangeException ( "percentProgress" ) ;
569588 if ( _dialog == null )
570589 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+
571594 _backgroundWorker . ReportProgress ( percentProgress , new ProgressChangedData ( ) { Text = text , Description = description , UserState = userState } ) ;
572595 }
573596
0 commit comments