Exemplo n.º 1
0
        public void ObserveValueForKeyPathOfObject(String keyPath, Object obj, Dictionary<String, Object> change, Object context)
        {
            String message = "KVO change notification received" + Environment.NewLine + Environment.NewLine;

            if (change.ValueForKey(KNKVOConstants.KNKeyValueChangeNewKey) != null)
            {
                message += "New: " + change.ValueForKey(KNKVOConstants.KNKeyValueChangeNewKey).ToString() + Environment.NewLine;
            }
            if (change.ValueForKey(KNKVOConstants.KNKeyValueChangeOldKey) != null)
            {
                message += "Old: " + change.ValueForKey(KNKVOConstants.KNKeyValueChangeOldKey).ToString() + Environment.NewLine;
            }

            MessageBox.Show(message);
        }
Exemplo n.º 2
0
        public void ObserveValueForKeyPathOfObject(String aKeyPath, Object anObj, Dictionary<String, Object> change, Object aContext)
        {
            if (change != null && change.ValueForKey(KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey) != null) {

                Object oldValue = observedObject.ValueForKeyPath(keyPath);
                KNKVOObservationChangeTracker tracker = new KNKVOObservationChangeTracker(oldValue, aKeyPath);
                changes.Push(tracker);

                // Remove our observers completely
                Object currentObj = observedObject;
                ArrayList keys = new ArrayList(keyPath.Split('.'));

                foreach (String key in keys) {

                    previousObservations.Add(new KeyValuePair<Object, String>(currentObj, key));
                    currentObj = currentObj.ValueForKey(key);
                    if (currentObj == null) { break; }
                }

                if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionPrior) == KNKeyValueObservingOptions.KNKeyValueObservingOptionPrior) {
                    Dictionary<String, Object> changeDict = new Dictionary<String, Object>();
                    changeDict.SetValueForKey(true, KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey);
                    changeDict.SetValueForKey(oldValue, KNKVOConstants.KNKeyValueChangeOldKey);

                    observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, changeDict, context);
                }
            } else {

                ResetObservationTree();

                Dictionary<String, Object> changeDict = new Dictionary<String, Object>();

                if (changes.Count > 0) {
                    KNKVOObservationChangeTracker tracker = changes.Pop();
                    if (((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) == KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) && (tracker != null)) {
                        changeDict.SetValueForKey(tracker.OldValue, KNKVOConstants.KNKeyValueChangeOldKey);
                    }
                }

                changeDict.SetValueForKey(observedObject.ValueForKeyPath(keyPath), KNKVOConstants.KNKeyValueChangeNewKey);
                observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, changeDict, context);

            }
        }
Exemplo n.º 3
0
        public void ObserveValueForKeyPathOfObject(string keyPath, object obj, Dictionary<string, object> change, object context)
        {
            if (context != null && context.Equals(kColumnWidthKVOContext)) {
                RebuildBasicLayout();
                RebuildColumnLayout();
                return;
            }

            if (keyPath.Equals("SelectedRows")) {
                RebuildSelectionLayout();
            }

            if (keyPath.Equals("HeaderHeight")) {
                foreach (KNTableColumn column in Columns) {
                    column.HeaderHeight = HeaderHeight;
                }
            }

            if (keyPath.Equals("RowHeight")) {
                foreach (KNTableColumn column in Columns) {
                    column.RowHeight = RowHeight;
                }
            }

            if (keyPath.Equals("ContentPadding")) {
                foreach (KNTableColumn column in Columns) {
                    column.RowHeight = RowHeight;
                }
            }

            if (keyPath.Equals("ContentPadding") || keyPath.Equals("Width") || keyPath.Equals("RowHeight") || keyPath.Equals("HeaderHeight") || keyPath.Equals("VerticalScrollBarVisibility") || keyPath.Equals("HorizontalScrollBarVisibility")) {
                RebuildBasicLayout();
            }

            if (keyPath.Equals("Columns")) {

                KNTableColumn[] oldColumns = (KNTableColumn[])change.ValueForKey(KNKVOConstants.KNKeyValueChangeOldKey);

                if (oldColumns != null) {
                    foreach (KNTableColumn column in oldColumns) {
                        column.RemoveObserverFromKeyPath(this, "Width");
                    }
                }

                KNTableColumn[] newColumns = (KNTableColumn[])change.ValueForKey(KNKVOConstants.KNKeyValueChangeNewKey);

                if (newColumns != null) {
                    foreach (KNTableColumn column in oldColumns) {
                        column.AddObserverToKeyPathWithOptions(this, "Width", 0, kColumnWidthKVOContext);
                    }
                }

                foreach (KNTableColumn column in Columns) {
                    column.RowHeight = RowHeight;
                    column.HeaderHeight = HeaderHeight;
                    column.ContentPadding = ContentPadding;
                }

                RebuildColumnLayout();
            }
        }