Ejemplo n.º 1
0
        public static void Load()
        {
            try
            {
                string content = File.ReadAllText(configPath);
                Instance = JsonConvert.DeserializeObject <Models.ConfigData>(content);
            }
            catch { }

            var listener = ChangeListener.Create(Instance);

            listener.PropertyChanged   += (_, e) => Save();
            listener.CollectionChanged += (_, e) => Save();
        }
Ejemplo n.º 2
0
 private void Monitor()
 {
     if (listener != null)
     {
         listener.DeepCollectionChanged -= CollectionListener_DeepCollectionChanged;
         listener.Dispose();
         this.Children.Clear();
         listener = null;
     }
     if (this.BindingContext != null && string.IsNullOrEmpty(this.ItemsSourceSelector) == false)
     {
         listener = ChangeListener.Create(this.BindingContext, this.ItemsSourceSelector, this.propsToIgnoreList);
         listener.DeepCollectionChanged += CollectionListener_DeepCollectionChanged;
         if (this.BindingContext is INotifyPropertyChanged)
         {
             CollectionListener_DeepCollectionChanged(null, new DeepCollectionChangedEventArg(this.ItemsSourceSelector, this.BindingContext, null));
         }
         listener.Subscribe();
     }
 }
Ejemplo n.º 3
0
        protected virtual void RebuildPopertyNodesImpl()
        {
            DestroyPropertyNodes();

            object[] instances = Instances == null ? EmptyArray <object> .Instance
                                     : Instances.Cast <object>().ToArray();

            // TODO: cache and reuse PropertyNodes where possible to prevent having to
            // rebuild all of the data templates
            IEnumerable <PropertyDescriptor> descriptors = null;

            if (CustomPropertyDescriptors != null)
            {
                descriptors = CustomPropertyDescriptors;
            }
            else if (Instances != null)
            {
                descriptors = PropertyUtils.GetSharedPropertiesOriginal(instances);
            }

            PropertyNode headerPropertyNode = null;
            var          propertyNodes      = new ObservableCollection <PropertyNode>();

            if (descriptors != null)
            {
                var context = TransactionContext.As <ITransactionContext>();
                if (context == null)
                {
                    context = DataContext.As <ITransactionContext>();
                }

                foreach (var descriptor in descriptors)
                {
                    if (descriptor.IsBrowsable)
                    {
                        PropertyNode node;
                        if (PropertyFactory != null)
                        {
                            node = PropertyFactory.CreateProperty(instances, descriptor, true, context);
                        }
                        else
                        {
                            node = new PropertyNode();
                            node.Initialize(instances, descriptor, true);
                        }

                        node.ValueSet   += node_ValueSet;
                        node.ValueError += node_ValueError;

                        if (node.Category != null)
                        {
                            bool expansionState;
                            if (m_categoryExpanded.TryGetValue(node.Category, out expansionState))
                            {
                                node.IsExpanded = expansionState;
                            }
                        }

                        if (headerPropertyNode == null && descriptor.Attributes[typeof(HeaderPropertyAttribute)] != null)
                        {
                            headerPropertyNode = node;
                        }
                        else
                        {
                            propertyNodes.Add(node);
                        }
                    }
                }
            }

            // Listen for expansion state changes so that we can persist through different objects.
            m_listener = ChangeListener.Create(propertyNodes, "IsExpanded");
            m_listener.PropertyChanged += ChildExpandedPropertyChanged;

            Properties     = propertyNodes;
            HeaderProperty = headerPropertyNode;
        }