Пример #1
0
        public override void Recreate(bool sendPropertyCreatedEvent)
        {
            Grid.InsideValueRecreate = true;
            Grid.BeginUpdate();
            object states = Grid.SavePropertiesStates();

            // Set the grid in categorized mode
            PropertyGrid.DisplayModes dispMode = Grid.DisplayMode;
            if (dispMode != PropertyGrid.DisplayModes.Categorized)
            {
                Grid.Grid.DisplayMode = PropertyGrid.DisplayModes.Categorized;
            }

            RecreateChildProperties();

            PropertyValue parentValue = null;

            if (OwnerEnumerator.Parent.Property != null)
            {
                parentValue = OwnerEnumerator.Parent.Property.Value;
            }

            PropertyTypeDescriptorContext context = GetTypeDescriptorContext(OwnerEnumerator);

            if ((parentValue == null) || !parentValue.TypeConverter.GetPropertiesSupported(context) ||
                parentValue.TypeConverter.GetCreateInstanceSupported(context))
            {
                PropertyDescriptor pd = null;

                object target = TargetInstance;
                if (target != null)
                {
                    pd = TypeDescriptor.GetProperties(target,
                                                      new Attribute[1] {
                        BrowsableAttribute.Yes
                    })[((PropertyDescriptor)((Utilities.KeyValuePair)_targets[0]).Key).Name];
                }

                if (pd != null)
                {
                    _targets[0] = new Utilities.KeyValuePair(pd, ((Utilities.KeyValuePair)_targets[0]).Value);
                    ResetDisplayedValues(true);

                    Grid.ShowProperty(mOwnerEnumerator, true);
                }
                else
                {
                    // Hide properties that are suddenly not browsable
                    Grid.ShowProperty(mOwnerEnumerator, false);
                }
            }

            // Handle ReadOnly
            bool readOnly = IsReadOnly(mOwnerEnumerator);

            if (readOnly)
            {
                if (Grid.ReadOnlyVisual == PropertyGrid.ReadOnlyVisuals.Disabled)
                {
                    Grid.EnableProperty(mOwnerEnumerator, false);
                }
                else
                {
                    mOwnerEnumerator.Property.ForeColor = DisabledForeColor;
                }
            }
            else
            {
                Grid.EnableProperty(mOwnerEnumerator, true);
                mOwnerEnumerator.Property.ForeColor = Grid.ForeColor;
            }

            if (Feel == null)
            {
                if (!readOnly || (((Look == null) || !Look.NoFeelForReadOnly) && (Grid.ReadOnlyVisual == PropertyGrid.ReadOnlyVisuals.ReadOnlyFeel)))
                {
                    Feel = Grid.Grid.FindFeel(mOwnerEnumerator.Parent, mOwnerEnumerator);
                }
            }

            if (sendPropertyCreatedEvent)
            {
                Grid.OnPropertyCreated(new PropertyCreatedEventArgs(OwnerEnumerator));
            }

            // Set the grid in non categorized mode if it was as such before calling SelectedObject(s)
            if (dispMode != PropertyGrid.DisplayModes.Categorized)
            {
                Grid.Grid.DisplayMode = dispMode;
            }

            Grid.RestorePropertiesStates(states);
            Grid.EndUpdate();
            Grid.InsideValueRecreate = false;
        }
Пример #2
0
        public override void Recreate(bool sendPropertyCreatedEvent)
        {
            Grid.InsideValueRecreate = true;
            Grid.BeginUpdate();
            object states = Grid.SavePropertiesStates();

            // Set the grid in categorized mode
            PropertyGrid.DisplayModes dispMode = Grid.DisplayMode;
            if (dispMode != PropertyGrid.DisplayModes.Categorized)
                Grid.Grid.DisplayMode = PropertyGrid.DisplayModes.Categorized;
            
            RecreateChildProperties();
            
            PropertyValue parentValue = null;
            if (OwnerEnumerator.Parent.Property != null)
                parentValue = OwnerEnumerator.Parent.Property.Value;

            PropertyTypeDescriptorContext context = GetTypeDescriptorContext(OwnerEnumerator);

            if ((parentValue == null) || !parentValue.TypeConverter.GetPropertiesSupported(context) ||
                parentValue.TypeConverter.GetCreateInstanceSupported(context))
            {
                PropertyDescriptor pd = null;

                object target = TargetInstance;
                if (target != null)
                    pd = TypeDescriptor.GetProperties(target,
                        new Attribute[1] { BrowsableAttribute.Yes })[((PropertyDescriptor)((Utilities.KeyValuePair)_targets[0]).Key).Name];

                if (pd != null)
                {
                    _targets[0] = new Utilities.KeyValuePair(pd, ((Utilities.KeyValuePair)_targets[0]).Value);
                    ResetDisplayedValues(true);

                    Grid.ShowProperty(mOwnerEnumerator, true);
                }
                else
                    // Hide properties that are suddenly not browsable
                    Grid.ShowProperty(mOwnerEnumerator, false);
            }

            // Handle ReadOnly
            bool readOnly = IsReadOnly(mOwnerEnumerator);
            if (readOnly)
            {
                if (Grid.ReadOnlyVisual == PropertyGrid.ReadOnlyVisuals.Disabled)
                    Grid.EnableProperty(mOwnerEnumerator, false);
                else
                    mOwnerEnumerator.Property.ForeColor = DisabledForeColor;
            }
            else
            {
                Grid.EnableProperty(mOwnerEnumerator, true);
                mOwnerEnumerator.Property.ForeColor = Grid.ForeColor;
            }

            if (Feel == null)
            {
                if (!readOnly || (((Look == null) || !Look.NoFeelForReadOnly) && (Grid.ReadOnlyVisual == PropertyGrid.ReadOnlyVisuals.ReadOnlyFeel)))
                    Feel = Grid.Grid.FindFeel(mOwnerEnumerator.Parent, mOwnerEnumerator);
            }

            if (sendPropertyCreatedEvent)
                Grid.OnPropertyCreated(new PropertyCreatedEventArgs(OwnerEnumerator));

            // Set the grid in non categorized mode if it was as such before calling SelectedObject(s)
            if (dispMode != PropertyGrid.DisplayModes.Categorized)
                Grid.Grid.DisplayMode = dispMode;

            Grid.RestorePropertiesStates(states);
            Grid.EndUpdate();
            Grid.InsideValueRecreate = false;
        }