AnimatedSplashScreenWindow.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.ComponentModel;
  3. using System.Threading;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace OHV.Vehicle.Concept
  7. {
  8. /// <summary>
  9. /// AnimatedSplashScreenWindow.xaml에 대한 상호 작용 논리
  10. /// </summary>
  11. public partial class AnimatedSplashScreenWindow : Window, ISplashScreen, INotifyPropertyChanged
  12. {
  13. public event PropertyChangedEventHandler PropertyChanged;
  14. #region Properties
  15. string totalProgressText;
  16. private int _progressValue;
  17. public int ProgressValue
  18. {
  19. get { return _progressValue; }
  20. set
  21. {
  22. _progressValue = value;
  23. OnPropertyChanged( nameof( ProgressValue ) );
  24. }
  25. }
  26. public string TotalProgressText
  27. {
  28. get { return totalProgressText; }
  29. set
  30. {
  31. if ( totalProgressText == value )
  32. return;
  33. totalProgressText = value;
  34. OnPropertyChanged( nameof( TotalProgressText ) );
  35. }
  36. }
  37. #endregion
  38. public void SetRange( int count )
  39. {
  40. Dispatcher.Invoke( new Action( () =>
  41. {
  42. ProgressValue = 0;
  43. ProgressBar.Maximum = count;
  44. } ) );
  45. }
  46. public void StepIt()
  47. {
  48. Dispatcher.Invoke( new Action( () =>
  49. {
  50. if ( this.ProgressBar.Maximum <= ProgressValue )
  51. return;
  52. this.ProgressValue += 1;
  53. } ) );
  54. }
  55. public AnimatedSplashScreenWindow()
  56. {
  57. InitializeComponent();
  58. }
  59. public void AddMessage( string message )
  60. {
  61. Dispatcher.Invoke( (Action)delegate ()
  62. {
  63. this.UpdateMessageLabel.Content = message;
  64. } );
  65. }
  66. public void ReportProgress(int persent )
  67. {
  68. Dispatcher.Invoke( (Action)delegate ()
  69. {
  70. ProgressValue = persent;
  71. } );
  72. }
  73. public void ReportTotalProgress( int persent )
  74. {
  75. Dispatcher.Invoke( (Action)delegate ()
  76. {
  77. this.TotalProgressText = $"Total {persent}%";
  78. } );
  79. }
  80. public void LoadComplete()
  81. {
  82. Thread.Sleep( 500 );
  83. Dispatcher.InvokeShutdown();
  84. }
  85. protected void OnPropertyChanged( string name )
  86. {
  87. PropertyChangedEventHandler handler = PropertyChanged;
  88. if ( handler != null )
  89. {
  90. handler( this, new PropertyChangedEventArgs( name ) );
  91. }
  92. }
  93. }
  94. public interface ISplashScreen
  95. {
  96. void ReportTotalProgress( int persent );
  97. void AddMessage( string message );
  98. void LoadComplete();
  99. void ReportProgress( int persent );
  100. void SetRange( int count );
  101. void StepIt();
  102. }
  103. }