Beispiel #1
0
        private static void CopyCategoryFrom(GridEntryCollection <CategoryItem> oldValue, IEnumerable <CategoryItem> newValue)
        {
            foreach (var category in newValue)
            {
                var prev = oldValue[category.Name];
                if (prev == null)
                {
                    continue;
                }

                category.IsExpanded = prev.IsExpanded;
            }
        }
Beispiel #2
0
        private void DoReload()
        {
            if (SelectedObject == null)
            {
                Categories = new GridEntryCollection <CategoryItem>();
                Properties = new GridEntryCollection <PropertyItem>();
            }
            else
            {
                // Collect BrowsableCategoryAttribute items
                var categoryAttributes = PropertyGridUtils.GetAttributes <BrowsableCategoryAttribute>(SelectedObject);
                browsableCategories = new List <BrowsableCategoryAttribute>(categoryAttributes);

                // Collect BrowsablePropertyAttribute items
                var propertyAttributes = PropertyGridUtils.GetAttributes <BrowsablePropertyAttribute>(SelectedObject);
                browsableProperties = new List <BrowsablePropertyAttribute>(propertyAttributes);

                // Collect categories and properties
                var properties = CollectProperties(SelectedObjects);

                // TODO: This needs more elegant implementation
                var categories = new GridEntryCollection <CategoryItem>(CollectCategories(properties));
                if (_categories != null && _categories.Count > 0)
                {
                    CopyCategoryFrom(_categories, categories);
                }

                // Fetch and apply category orders
                var categoryOrders = PropertyGridUtils.GetAttributes <CategoryOrderAttribute>(SelectedObject);
                foreach (var orderAttribute in categoryOrders)
                {
                    var category = categories[orderAttribute.Category];
                    // don't apply Order if it was applied before (Order equals zero or more),
                    // so the first discovered Order value for the same category wins
                    if (category != null && category.Order < 0)
                    {
                        category.Order = orderAttribute.Order;
                    }
                }

                Categories = categories; //new CategoryCollection(CollectCategories(properties));
                Properties = new GridEntryCollection <PropertyItem>(properties);
            }
        }