Exemplo n.º 1
0
        private void ItemDefinitions_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    if (item is CommandBarItemDefinition itemDefinition)
                    {
                        if (ExcludedCommandDefinitions.Any(
                                x => x.GetType() == itemDefinition.CommandDefinition.GetType()))
                        {
                            ItemDefinitions.Remove(itemDefinition);
                            continue;
                        }

                        if (!itemDefinition.Group.Items.Contains(itemDefinition))
                        {
                            itemDefinition.Group.Items.AddSorted(itemDefinition,
                                                                 new SortOrderComparer <CommandBarDefinitionBase>());
                        }
                    }
                }
            }
            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    if (item is CommandBarItemDefinition itemDefinition)
                    {
                        itemDefinition.Group.Items.Remove(itemDefinition);
                    }
                }
            }
        }