Why is new added RibbonTabItem not visible ?

Oct 1, 2009 at 9:55 AM

I'm trying to simply add a new RibbonTabItem from code (RibbonBar.Tabs.Add (new RibbonTabItem ....)). New RibbonTabItem is in Tabs collection, but visualy nothing has changed. And property IsVisible is always false, although I set Visibility = Visible. Any help ?

Oct 7, 2009 at 8:17 PM

This works for me:

RibbonTabItem tab = new RibbonTabItem();
tab.Title = "My Tab";

this.ribbonBar.Tabs.Add(tab);

 

 

Nov 9, 2009 at 3:00 AM

Hi,

I am getting the same behavior. Did someone manage to describe conditions under which the newly added tabs don't apear? 

Nov 10, 2009 at 10:44 AM

I'm sorry. I'm trying to write Region Adapter for RibbonBar (PRISM2, CAL ) similar to http://www.codeproject.com/script/Membership/View.aspx?mid=4823267&msg=3145094 and it doesn't work. Outside the Adapter it works fine, thank you. 

Nov 10, 2009 at 11:23 AM

What your working code looks like and how it is initiated?

I also use it in CAL, altough I access the RibbonBar directly not through an adapter. Nevertheless it doesn't work.

Maybe it is really a CAL related issue.

I have also noticted one thing.

In my application every module has a possibility to register its own tab in the RibbonBar. At first none of them apeared after the window came up. When I increased the initial size of the window, suddenly one tab became visible. Unfortunately the rest of the them I add later during the program execution don't show up at all.

Any thoughts on that?

As I see it, it is some kind of a measuring and repainting issue. 

Mar 3, 2010 at 7:56 AM
Edited Mar 3, 2010 at 8:00 AM

It seems currently a workaround is needed if you want to add a new Tab dynamically "late" (i.e. after the ribbon had its template applied):

RibbonTabItem tab = new RibbonTabItem();
tab.Title = "My Tab";

this.ribbonBar.Tabs.Add(tab);

this.ribbonBar.OnApplyTemplate(); // added

I don't know if this has any other bad side-effects!

The same (OnApplyTemplate) also seems to help when dynamically adding new Controls to a RibbonGroup.

A real fix for the control itself would probably change RibbonBar.OnTabItemCollectionChanged to something like:

        protected virtual void OnTabItemCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (RibbonTabItem tab in e.NewItems)
                    {
                        tab.RibbonBar = this;
                        if(tabItemContainer != null) tabItemContainer.Children.Add(tab); // added
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (RibbonTabItem tab in e.OldItems)
                    {
                        tab.RibbonBar = null;
                        if(tabItemContainer != null) tabItemContainer.Children.Remove(tab); // added
                    }
                    break;
            }
        }

(untested!)