Guest User

Untitled

a guest
Jan 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. private int _MyVal;
  2. [Export("MyVal")]
  3. public int MyVal
  4. {
  5. get { return _MyVal; }
  6. set
  7. {
  8. WillChangeValue("MyVal");
  9. this._MyVal = value;
  10. DidChangeValue("MyVal");
  11. }
  12. }
  13.  
  14. SettingsModel.AddObserver(this, (NSString)key, NSKeyValueObservingOptions.New, this.Handle);
  15.  
  16. public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
  17. {
  18. switch (keyPath)
  19. {
  20. case "MyValue":
  21.  
  22. // CODE HERE THAT UPDATES AN API WITH THE VALUE
  23. // But this handler fires twice.
  24.  
  25.  
  26. break;
  27. }
  28. }
  29.  
  30. [Export("MyVal")]
  31. public int MyVal { get; set }
  32.  
  33. this.SettingsModel.MyVal = 1;
  34.  
  35. MainViewController.ObserveValue
  36. ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr()
  37. Foundation.NSObject.DidChangeValue(string forKey)
  38. CameraSettingsModel.set_MyValue(int value)
  39. AppKit.NSApplication.NSApplicationMain()
  40. AppKit.NSApplication.Main(string[] args)
  41. MainClass.Main(string[] args)
  42.  
  43. MainViewController.ObserveValue
  44. AppKit.NSApplication.NSApplicationMain()
  45. AppKit.NSApplication.Main(string[] args)
  46. MainClass.Main(string[] args)
  47.  
  48. [Export ("automaticallyNotifiesObserversForKey:")]
  49. public static new bool AutomaticallyNotifiesObserversForKey (string key) => false;
  50.  
  51. bool _checkValue;
  52.  
  53. [Export("CheckValue")]
  54. public bool CheckValue
  55. {
  56. get { return _checkValue; }
  57. set
  58. {
  59. WillChangeValue("CheckValue");
  60. _checkValue = value;
  61. DidChangeValue("CheckValue");
  62. }
  63. }
  64.  
  65. public override void ViewDidLoad ()
  66. {
  67. base.ViewDidLoad();
  68.  
  69. this.AddObserver("CheckValue", NSKeyValueObservingOptions.New, o =>
  70. {
  71. Console.WriteLine($"Observer triggered for {o}");
  72. });
  73.  
  74. CheckValue = false;
Add Comment
Please, Sign In to add comment