Пример #1
0
        public GalleryCategories(IRibbonControl ribbonControl, IUICollection fromGallery)
        {
            if (ribbonControl == null)
            {
                throw new ArgumentNullException(nameof(ribbonControl));
            }
            _ribbonControl = ribbonControl;
            if (fromGallery == null)
            {
                throw new ArgumentException(ribbonControl.ToString() + " not initialized");
            }
            _collectionChanged = new UICollectionChangedEvent();
            _collectionChanged.ChangedEvent += CollectionChanged_ChangedEvent;
            _collectionChanged.Attach(fromGallery);
            uint   count;
            object item;

            fromGallery.GetCount(out count);
            for (uint i = 0; i < count; i++)
            {
                fromGallery.GetItem(i, out item);
                GalleryItemPropertySet galleryItem = GetItemPropertySet(item);
                _controlItems.Add(galleryItem);
            }
        }
Пример #2
0
        private void CollectionChanged_ChangedEvent(object sender, UICollectionChangedEventArgs e)
        {
            GalleryItemPropertySet newGalleryItem = GetItemPropertySet(e.NewItem);

            //GalleryItemPropertySet oldGalleryItem = GetItemPropertySet(e.OldItem);
            switch (e.Action)
            {
            case CollectionChange.Insert:
                _controlItems.Insert((int)e.NewIndex, newGalleryItem);
                break;

            case CollectionChange.Remove:
                _controlItems.RemoveAt((int)e.OldIndex);
                break;

            case CollectionChange.Replace:
                _controlItems[(int)e.NewIndex] = newGalleryItem;
                break;

            case CollectionChange.Reset:
                _controlItems.Clear();
                break;

            default:
                break;
            }
        }