5

I have a ribbon in my view named 'ribbon' that have 2 tabs as below sample codes. I want Button1 when clicked will open Tab2 and vice versa. How would I do this?

<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>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Nam G VU
  • 33,193
  • 69
  • 233
  • 372
  • Perhaps see http://stackoverflow.com/questions/7929646/how-to-programmaticaly-select-a-tabitem-in-wpf-tabcontrol/25960172#25960172? – Adrian Ratnapala Sep 21 '14 at 14:23

4 Answers4

5

You only have to trigger 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;
        }
Mark
  • 3,273
  • 2
  • 36
  • 54
3

Found myself: If your ribbon control named 'Ribbon' then call this in your button's clicked handler:

Ribbon.SelectedIndex = indexOfTab;

Hope that would help anyone with the same problem with me.

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
2

Simple, using:

ribbonName.Tabs[TabNumber].IsSelected=true;
Datnt6
  • 21
  • 2
1

I my opinion that is purely layout related stuff so I would attach an eventhandler to the buttons to change the SelectedTab.

Wouter Janssens
  • 1,593
  • 10
  • 17