/// <summary> /// Reloads all PropertyNodes in PropertyGrid, recreating all PropertyNodes</summary> protected virtual void Reload() { // Destroy and unsubscribe from old properties if (Properties != null) { foreach (PropertyNode node in Properties) { node.UnBind(); node.ValueSet -= new EventHandler(node_ValueSet); node.ValueError -= new EventHandler(node_ValueError); } } object[] instances = 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.GetSharedProperties(instances); } var propertyNodes = new ObservableCollection <PropertyNode>(); foreach (var descriptor in descriptors) { if (descriptor.IsBrowsable) { PropertyNode node = null; if (PropertyFactory != null) { node = PropertyFactory.CreateProperty(instances, descriptor, true, this); } else { node = new PropertyNode(instances, descriptor, true, this); } node.ValueSet += new EventHandler(node_ValueSet); node.ValueError += new EventHandler(node_ValueError); propertyNodes.Add(node); } } Properties = propertyNodes; }
/// <summary> /// Returns a sequence of property descriptors for the selected objects</summary> /// <returns>Sequence of property descriptors for the selected objects</returns> /// <remarks>Default behavior is to return only the descriptors common to all /// selected objects; override to customize.</remarks> protected virtual IEnumerable <PropertyDescriptor> GetPropertyDescriptors() { return(PropertyUtils.GetSharedProperties(Items)); // only props shared by all selected objects }