About RibbonCollectionBase

Apr 6, 2014 at 4:27 PM
Edited Apr 6, 2014 at 5:03 PM
I see that ribbon collections was rewritten with using of base class.

I think it is better to inherit base class from System.Collections.ObjectModel.Collection<T> as it has virtual methods (InsertItem, SetItem, etc) for your needs. So there not need to use "new" keyword hack.

Also there is no need to implement IList interface because List<T> and Collection<T> already implements it.

You can look what I have done with collections in my fork https://officeribbon.codeplex.com/discussions/528566. It is already old verion, but I'm using Collection<T>.
Developer
Apr 7, 2014 at 7:38 AM
I could not agree more. The decission to inherit List<T> was totally wrong! But that was long time ago and definitly not mine!

BUT: I consider the Ribbon as "legacy" code and therefore I was not willing to change the base class of RibbonItem/Tab/Panel. Imagine someone has written some code and expects a List<T>. Or is still using .net 2.0 (we had already comments from users which do this) and calls ToArray() - this function is only available at List<T>.
I have almost no time to do some changes on the ribbon. Therefore it is most important that the Ribbon keeps working, no matter which version you are using. I wanna avoid discussions like "I updated Ribbon. Now my code is not working any more" or "I can't find XXX any more".

Yes, we must implement IList! If you had read my comment in the source code about it. you would know. The reason is that the visual studio designer casts to an IList and if the collection implements this interface, it shows the collection editor. This is the gotcha! The List<T> has an explicit interface implementation of IList. Meaning my functions of Add/Remove/Clear are not called! If you have used the Ribbon for quite some time, you maybe remember the issue when the ribbon was not updated in visual studio designer. You had to close the control in design mode and reopen it to have an updated UI. No setting of the Owner. No notifying the parent about the UI changes.
If you do not use visual studio designer with the Ribbon there is no need to implement IList. But all other must do that.

Hope that explains my doing.

Cheers