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); } }