Creates an instance of this class to track changes to as many objects as needed. It automatically drills down and track changes to all objects reachable from the explicitly tracked objects. In a MVVM application, it should be sufficient to track just the root view model.
This class is not thread-safe. If you want to access instances of this class from multiple threads, you need to synchronize properly.
Inheritance: IDisposable
Exemple #1
0
        private static void Main()
        {
            var screen = new Screen();
            for (int i = 0; i < 10; i++) {
                screen.Add(new Shape {Location = new Point(i, i), Color = Color.Red});
            }

            using (var tracker = new Tracker().Track(screen)) {
                tracker.Changed += _ => Console.WriteLine("Changed!");
                screen.Add(new Shape()); // "Changed!" x 2 (1 for new element, 1 for Count property change)
                screen[0].Location = new Point(1, 1); // "Changed!"
                screen[1].Color = Color.Blue; // "Changed!"
                screen.RemoveAt(2); // "Changed!" x 2
            }
        }
Exemple #2
0
        public PersistentObject(string id, object obj)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            this.Id  = id;
            this.Obj = obj;

            var npc = obj as INotifyPropertyChanged;

            if (npc == null)
            {
                throw new InvalidOperationException($"{nameof(obj)} must implement {nameof(INotifyPropertyChanged)}");
            }

            tracker = new Tracker();
            tracker.Track(obj);
            tracker.Changed += _ => ChangedAndUnsaved = true;
        }
Exemple #3
0
 protected void OnChange(Tracker tracker = null)
 {
     if (Changed != null) Changed(null);
 }