How to programmatically switch the ribbon tab?

In my view, there is a feed called "feed" that has two tabs, as shown below for sample codes. I want Button1 to open Tab2 when pressed and vice versa. How would I do that?

<ribbon:Ribbon x:Name="ribbon" HelpPaneContent="{x:Static data:WordModel.Help}">
    <ribbon:RibbonTab Header="Tab1" ... >
        <ribbon:RibbonGroup x:Name="Button1" >
            <ribbon:RibbonButton Clicked="SwitchToTab2" />
        </ribbon:RibbonGroup>
    </ribbon:RibbonTab>

    <ribbon:RibbonTab Header="Tab2" ... >
        <ribbon:RibbonGroup x:Name="Button2" >
            <ribbon:RibbonButton Clicked="SwitchToTab1" />
        </ribbon:RibbonGroup>
    </ribbon:RibbonTab>
... 
</ribbon:Ribbon>
+5
source share
4 answers

You only need to call the IsSelected property of your tabs

private void SwitchToTab1(object sender, MouseButtonEventArgs e)
        {
            ribbontab1.IsSelected = true;
        }
    private void SwitchToTab2(object sender, MouseButtonEventArgs e)
        {
            ribbontab2.IsSelected = true;
        }
+5
source

Found: if your ribbon control is called "Ribbon", then call it in the handler of the pressed button:

Ribbon.SelectedIndex = indexOfTab;

Hope this helps someone with the same issue with me.

+2
source

, :

ribbonName.Tabs[TabNumber].IsSelected=true;
+2

, , , SelectedTab.

+1

All Articles