MainWindow.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace Test.WpfApplication1
  19. {
  20. /// <summary>
  21. /// MainWindow.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class MainWindow : Window, INotifyPropertyChanged
  24. {
  25. private string _BindData = string.Empty;
  26. public string BindData
  27. {
  28. get
  29. {
  30. if (_BindData.Length == 0)
  31. _BindData = "this is BindData";
  32. return _BindData;
  33. }
  34. set
  35. {
  36. _BindData = value;
  37. }
  38. }
  39. private string _TextBoxData = string.Empty;
  40. public string TextBoxData
  41. {
  42. get
  43. {
  44. if (_TextBoxData.Length == 0)
  45. _TextBoxData = "this is data";
  46. return _TextBoxData;
  47. }
  48. set
  49. {
  50. if (_TextBoxData != value)
  51. {
  52. _TextBoxData = value;
  53. OnPropertyChanged("TextBoxData");
  54. }
  55. }
  56. }
  57. ObservableCollection<StudentModel> StudentModelList = new ObservableCollection<StudentModel>()
  58. {
  59. new StudentModel() { Number = Guid.NewGuid().ToString().Substring(0,2),Name = "张三"},
  60. new StudentModel() { Number = Guid.NewGuid().ToString().Substring(0,2),Name = "李四"},
  61. new StudentModel() { Number = Guid.NewGuid().ToString().Substring(0,2),Name = "王五"},
  62. };
  63. public event PropertyChangedEventHandler PropertyChanged;
  64. public virtual void OnPropertyChanged(string propertyName)
  65. {
  66. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  67. }
  68. private ObservableCollection<StudentModel> _GuidList;
  69. public ObservableCollection<StudentModel> GuidList
  70. {
  71. get { return _GuidList; }
  72. set
  73. {
  74. _GuidList = value;
  75. OnPropertyChanged("GuidList");
  76. }
  77. }
  78. public MainWindow()
  79. {
  80. InitializeComponent();
  81. DataContext = this;
  82. GuidList = StudentModelList;
  83. Task.Factory.StartNew(() =>
  84. {
  85. for (int i = 0; i < 10000; i++)
  86. {
  87. foreach (var item in GuidList)
  88. {
  89. item.Number = Guid.NewGuid().ToString().Substring(0, 2);
  90. }
  91. GuidList = new ObservableCollection<StudentModel>(StudentModelList);
  92. TextBoxData = DateTime.Now.ToString("HH:mm:ss.fff");
  93. Thread.Sleep(1000);
  94. }
  95. });
  96. }
  97. }
  98. }