WinMFMUploadProcress.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Windows.Controls;
  5. using System.Windows.Threading;
  6. namespace PackageUploader
  7. {
  8. /// <summary>
  9. /// WinMFMUploadProcress.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class WinMFMUploadProcress :INotifyPropertyChanged
  12. {
  13. private double m_ProgressLeft;
  14. public WinMFMUploadProcress()
  15. {
  16. InitializeComponent();
  17. m_ProgressLeft=Canvas.GetLeft(progressBar);
  18. this.DataContext = this;
  19. //var lblwidth = lblpresent.Width;
  20. //Canvas.SetLeft(lblpresent, m_ProgressLeft - (lblwidth / 2.0));
  21. }
  22. private string m_FloorName;
  23. public string FloorName
  24. {
  25. get { return m_FloorName; }
  26. set
  27. {
  28. m_FloorName = value;
  29. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("FloorName"));
  30. }
  31. }
  32. private string m_LabelPath;
  33. public string LabelPath
  34. {
  35. get { return m_LabelPath; }
  36. set
  37. {
  38. m_LabelPath = value;
  39. PropertyChanged?.Invoke(this,new PropertyChangedEventArgs("LabelPath"));
  40. }
  41. }
  42. private string m_Present;
  43. public string Present
  44. {
  45. get { return m_Present; }
  46. set
  47. {
  48. m_Present = value;
  49. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Present"));
  50. }
  51. }
  52. //public string FloorName
  53. //{
  54. // set { txtFloorName.Content = value; }
  55. //}
  56. //public string LabelPath
  57. //{
  58. // set { txtPath.Text = value; }
  59. //}
  60. public int Count { get; set; }
  61. public int Cur { get; set; }
  62. public event PropertyChangedEventHandler PropertyChanged;
  63. public void Update(string currentData)
  64. {
  65. //lblpresent.Content = Present;
  66. //Present = currentData;
  67. this.Dispatcher.Invoke(() => { lblpresent.Content = currentData + "%"; }, DispatcherPriority.Background);
  68. //DispatcherFrame nestedFrame = new DispatcherFrame();
  69. //DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, exitFrameCallback, nestedFrame);
  70. //Dispatcher.PushFrame(nestedFrame);
  71. //if (exitOperation.Status !=
  72. // DispatcherOperationStatus.Completed)
  73. //{
  74. // exitOperation.Abort();
  75. //}
  76. //lblpresent.Dispatcher.Invoke(() => { lblpresent.Content = currentData + "%"; },
  77. // DispatcherPriority.Background);
  78. //this.Dispatcher.Invoke(() => { lblpresent.Content = currentData + "%"; }, DispatcherPriority.Background);
  79. //var progresswidth = progressBar.Width;
  80. //var progressleft = Canvas.GetLeft(progressBar);
  81. //var lblwidth = lblpresent.Width;
  82. ////Canvas.SetLeft(lblpresent, progressleft + progresswidth * (currentData / 100.0) - (lblwidth / 2.0))), DispatcherPriority.Background
  83. //Dispatcher.Invoke(
  84. // new Action(() =>
  85. // {
  86. // lblpresent_Total.Content = $"({Cur}/{Count})";
  87. // lblpresent.Content = currentData + "%";
  88. // } ), DispatcherPriority.Background);
  89. //Dispatcher.Invoke(
  90. // new Action(() => Canvas.SetLeft(lblpresent, progressleft + progresswidth * (currentData / 100.0) - (lblwidth / 2.0))),DispatcherPriority.Background);
  91. //Canvas.SetLeft(lblpresent, progressleft+progresswidth*(currentData/100.0)-(lblwidth/2.0));
  92. //Dispatcher.Invoke(
  93. // new Action<DependencyProperty, object>((db, value) => this.progressBar.SetValue(db, value)),
  94. // System.Windows.Threading.DispatcherPriority.Background,
  95. // RangeBase.ValueProperty, Convert.ToDouble(currentData));
  96. }
  97. private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);
  98. private static Object ExitFrame(Object state)
  99. {
  100. DispatcherFrame frame = state as
  101. DispatcherFrame;
  102. frame.Continue = false;
  103. return null;
  104. }
  105. }
  106. }