我的 View 中有一个名为“ribbon”的功能区,其中有2个选项卡,如下面的示例代码所示。我希望在单击Button1时将打开Tab2,反之亦然。我该怎么做?

<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>

最佳答案

您只需要触发选项卡的IsSelected属性

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

关于wpf - 如何以编程方式切换功能区选项卡?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3528981/

10-12 22:14