예제 #1
0
        public void ShouldRaiseChangeNotificationsOnSort()
        {
            bool propertyChanged   = false;
            bool collectionChanged = false;

            GridEntryCollection <CategoryItemMock> list = new GridEntryCollection <CategoryItemMock>();

            (list as INotifyPropertyChanged).PropertyChanged += delegate { propertyChanged = true; };
            list.CollectionChanged += delegate { collectionChanged = true; };

            list.Sort(null);
            Assert.IsTrue(propertyChanged);
            Assert.IsTrue(collectionChanged);
        }
예제 #2
0
        public void ShouldPerformItemsSort()
        {
            CategoryItemMock item1 = new CategoryItemMock("a");
            CategoryItemMock item2 = new CategoryItemMock("b");

            GridEntryCollection <CategoryItemMock> list = new GridEntryCollection <CategoryItemMock>();

            list.Add(item2);
            list.Add(item1);

            list.Sort(new CategoryItemMockComparer());

            Assert.AreEqual(item1, list[0]);
            Assert.AreEqual(item2, list[1]);
        }
예제 #3
0
        public CollectionItemValue(PropertyItemValue propertyItemValue, int index)
        {
            _propertyItemValue = propertyItemValue;
            _index             = index;

            var expandable = PropertyGridUtils.GetAttributes <ExpandableObjectAttribute>(Value);

            if (expandable.Any())
            {
                var descriptors = MetadataRepository.GetProperties(Value).Select(prop => prop.Descriptor);

                if (descriptors.Any())
                {
                    object objectValue;
                    if (Value is ICloneable valueToClone)
                    {
                        objectValue = valueToClone.Clone();
                    }
                    else
                    {
                        objectValue = Value;
                    }


                    HasSubProperties = true;

                    var properties = new GridEntryCollection <PropertyItem>();
                    foreach (PropertyDescriptor d in descriptors)
                    {
                        var item = new PropertyItem(_propertyItemValue.ParentProperty.Owner, objectValue, d);
                        item.IsBrowsable   = ShouldDisplayProperty(d);
                        item.ValueChanged += ItemOnValueChanged;
                        properties.Add(item);
                    }

                    if (_propertyItemValue.ParentProperty.Owner.PropertyComparer != null)
                    {
                        properties.Sort(_propertyItemValue.ParentProperty.Owner.PropertyComparer);
                    }

                    SubProperties = properties;
                }

                MetadataRepository.Remove(Value);
            }
        }