如何将 WPF Tab Control 选项卡放在一边

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/189370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:41:53  来源:igfitidea点击:

How to put WPF Tab Control tabs on the side

wpfxamltabcontrol

提问by Brian Stewart

I am trying to create a Tab Control in WPF that has the tabs arranged down the right side of the control, with the text rotated 90 degrees The look is similar to those plastic tabs you can buy and use in a notebook. I have tried changing the TabStripPlacement to Right, but it just stacks the tabs up on the top right side of the control - not at all what I had in mind.

我正在尝试在 WPF 中创建一个选项卡控件,该控件的选项卡排列在控件的右侧,文本旋转 90 度。外观类似于您可以在笔记本中购买和使用的那些塑料选项卡。我曾尝试将 TabStripPlacement 更改为 Right,但它只是将选项卡堆叠在控件的右上角 - 完全不是我所想的。

回答by Brad Leach

The effect I believe you are seeking is achieved by providing a HeaderTemplate for the TabItem's in you Tab collection.

我相信您正在寻求的效果是通过为您的 Tab 集合中的 TabItem 提供 HeaderTemplate 来实现的。

<TabControl TabStripPlacement="Right">
  <TabControl.Resources>
    <Style TargetType="{x:Type TabItem}">
      <Setter Property="Padding" Value="4" />
      <Setter Property="HeaderTemplate">
        <Setter.Value>
          <DataTemplate>
            <ContentPresenter Content="{TemplateBinding Content}">
              <ContentPresenter.LayoutTransform>
                <RotateTransform Angle="90" />
              </ContentPresenter.LayoutTransform>
            </ContentPresenter>
          </DataTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </TabControl.Resources>
  <TabItem Header="Tab Item 1" />
  <TabItem Header="Tab Item 2" />
  <TabItem Header="Tab Item 3" />
  <TabItem Header="Tab Item 4" />
</TabControl>

Hope this helps!

希望这可以帮助!