コード例 #1
0
        private void ItemGroupDefinitions_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    if (item is CommandBarGroupDefinition groupDefinition)
                    {
                        var items = ItemDefinitions.Where(x => x.Group == groupDefinition);
                        foreach (var itemDefinition in items)
                        {
                            if (!groupDefinition.Items.Contains(itemDefinition))
                            {
                                groupDefinition.Items.AddSorted(itemDefinition,
                                                                new SortOrderComparer <CommandBarDefinitionBase>());
                            }
                        }
                    }
                }
            }

            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    if (item is CommandBarGroupDefinition groupDefinition)
                    {
                        groupDefinition.Parent.ContainedGroups.Remove(groupDefinition);
                        groupDefinition.Items.Clear();
                    }
                }
            }
        }