Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. this.mediaCenter.ItemManager.Root.SetProgressBar += (val) =>
  2. {
  3. this.Invoke((Action)(() =>
  4. {
  5. this.progressBarControl1.Position = val;
  6. }));
  7. };
  8.  
  9. private ItemContainerRoot _myRoot;
  10. public ItemContainerRoot Root
  11. {
  12. get { return this._myRoot; }
  13. }
  14.  
  15. this._myRoot = context.GetTable<Item>().Single(a => a.Id == 0) as ItemContainerRoot;
  16.  
  17. class ItemManager : INotifyPropertyChanged
  18. {
  19. private ItemContainerRoot _myRoot;
  20. public ItemContainerRoot Root
  21. {
  22. get { return _myRoot; }
  23.  
  24. set
  25. {
  26. _myRoot = value;
  27. OnPropertyChanged("Root");
  28. }
  29. }
  30.  
  31. public event PropertyChangedEventHandler PropertyChanged;
  32.  
  33. protected virtual void OnPropertyChanged(string propertyName)
  34. {
  35. PropertyChangedEventHandler handler = PropertyChanged;
  36. if (handler != null)
  37. {
  38. handler(this, new PropertyChangedEventArgs(propertyName));
  39. }
  40. }
  41. }
  42.  
  43. ItemManager.PropertyChanged += (o, args) =>
  44. {
  45. if (args.PropertyName == "Root" && ItemManager.Root != null)
  46. {
  47. ItemManager.Root.SetProgressBar += (val) =>
  48. {
  49. this.Invoke((Action)(() =>
  50. {
  51. this.progressBarControl1.Position = val;
  52. }));
  53. };
  54. }
  55. };
  56.  
  57. private Action _myRootDisconnect = null;
  58. private object _myRootGate = new object();
  59. private ItemContainerRoot _myRoot;
  60. public ItemContainerRoot Root
  61. {
  62. get { return _myRoot; }
  63. set
  64. {
  65. lock (_myRootGate)
  66. {
  67. Action<int> setProgressBar = val =>
  68. {
  69. this.Invoke((Action)(() =>
  70. {
  71. this.progressBarControl1.Position = val;
  72. }));
  73. };
  74.  
  75. if (_myRootDisconnect != null)
  76. {
  77. _myRootDisconnect();
  78. _myRootDisconnect = null;
  79. }
  80.  
  81. _myRoot = value;
  82. _myRoot.SetProgressBar += setProgressBar;
  83.  
  84. _myRootDisconnect = () =>
  85. {
  86. _myRoot.SetProgressBar -= setProgressBar;
  87. };
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement