Selecting a tab in a ContextualTabGroup

Ribbon for WPF Forum

Posted 10 years ago by Owen Christensen - Software Engineer, Minitab Inc.
Version: 4.5.0485
Avatar
This may or may not be a bug but I'll give you guys the benefit of the doubt :P

    <ribbon:Ribbon Name="_ribbon" x:FieldModifier="private">
        <ribbon:Tab Label="Home">
            <ribbon:Group Label="Misc.">
                <ribbon:Button Label="Activate Contextual Tab Group" Click="OnButtonClick"/>
            </ribbon:Group>
        </ribbon:Tab>
        <ribbon:Ribbon.ContextualTabGroups>
            <ribbon:ContextualTabGroup Name="_contextualTabGroup" x:FieldModifier="private" IsVisibleChanged="OnContextualTabGroupIsVisibleChanged">
                <ribbon:Tab>
                    <ribbon:Group>
                        <ribbon:Button/>
                    </ribbon:Group>
                </ribbon:Tab>
            </ribbon:ContextualTabGroup>
        </ribbon:Ribbon.ContextualTabGroups>
    </ribbon:Ribbon>

        private void OnContextualTabGroupIsVisibleChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
        {
            _ribbon.SelectedTab = (sender as ContextualTabGroup).Items[0] as Tab;
        }

        private void OnButtonClick(object sender, ExecuteRoutedEventArgs e)
        {
            _contextualTabGroup.IsActive = true;
        }
The above does not select the tab within the ContextualTabGroup. It enters the IsVisibleChanged and does the assignment statement. But it doesn't actually commit the value to the property. IsActive is clearly set to true on the group. If you instead just set IsActive to true on the group in the xaml and run, it is selected when the program starts.

Comments (6)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Owen,

My guess is that the tabs haven't been rebound just yet when the IsVisibleChanged occurs. It probably occurs immediately after that. So you are probably trying to set a selected tab that isn't in the tabstrip yet, and thus it doesn't select.

You could possibly try doing a Dispatcher.BeginInvoke using Send priority to set the selected tab. That may put the code after the tabs are bound.


Actipro Software Support

Posted 10 years ago by Owen Christensen - Software Engineer, Minitab Inc.
Avatar
So there's no event that I can hook up to to ensure that the contextual tab has been added to the Tabs collection in the Ribbon?

[Modified at 02/16/2009 02:35 PM]
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Owen,

I don't believe there is one at this time. Really it depends on how you are displaying the contextual tab group.

Normally you'd do so by setting IsActive = true, then you could focus the first tab on the next line of your code because after the IsActive call is complete, the new tabs should be bound.


Actipro Software Support

Posted 10 years ago by Owen Christensen - Software Engineer, Minitab Inc.
Avatar
I base the IsActive property on the currently selected view in the interface through a binding. This means I have no idea when the value is set so I can do my update of SelectedTab. The only solution I have at the moment seems to be setting NotifyOnTargetUpdated=True on the binding and then hook up the TargetUpdated event on the ContextualTabGroup. I'm going to suggest an IsActiveChanged event so that that's not neccessary.

[Modified at 02/17/2009 07:51 AM]
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Owen,

We'll add an IsActiveChanged event for you for the next maintenance release.


Actipro Software Support

Posted 10 years ago by Owen Christensen - Software Engineer, Minitab Inc.
Avatar
Thank you!
The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.