如何在 WPF 中构建垂直选项卡集?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3953286/
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 22:14:24  来源:igfitidea点击:

How to build vertical tab sets in WPF?

wpftabcontrol

提问by Gulshan

How to build vertical tab sets in WPF? The tabs will stack up in top-to-bottom just like the "Properties" of a project shown in visual studio.

如何在 WPF 中构建垂直选项卡集?选项卡将像 Visual Studio 中显示的项目的“属性”一样从上到下堆叠。

回答by ChrisF

Have you tried the TabControl.TabStripPlacementProperty?

你试过TabControl.TabStripPlacement物业吗?

The following example creates a tab control that positions the tabs on the left side.

下面的示例创建一个选项卡控件,将选项卡定位在左侧。

<TabControl TabStripPlacement="Left" Margin="0, 0, 0, 10">
  <TabItem Name="fontweight" Header="FontWeight">
    <TabItem.Content>
      <TextBlock TextWrapping="WrapWithOverflow">
        FontWeight property information goes here.
      </TextBlock>
    </TabItem.Content>
  </TabItem>

  <TabItem Name="fontsize" Header="FontSize">
    <TabItem.Content>
      <TextBlock TextWrapping="WrapWithOverflow">
        FontSize property information goes here.
      </TextBlock>
    </TabItem.Content>
  </TabItem>
</TabControl>

回答by rkirac

You should try this code:

你应该试试这个代码:

<TabControl.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <ContentPresenter Content="{TemplateBinding Content}">
                                <ContentPresenter.LayoutTransform>
                                    <RotateTransform Angle="270" />
                                </ContentPresenter.LayoutTransform>
                            </ContentPresenter>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Padding" Value="3" />
            </Style>
        </TabControl.Resources>

回答by dotNET

Based on rkirac's answer above. If you don't want to create a global style, you can put the same stuff inside TabControl.ItemContainerStylethat will only affect the TabControlin question. Following is a simple example:

基于上面 rkirac 的回答。如果您不想创建全局样式,则可以将相同的内容放入TabControl.ItemContainerStyle只会影响相关TabControl问题的内容。下面是一个简单的例子:

<TabControl TabStripPlacement="Left">
  <TabControl.ItemContainerStyle>
    <Style TargetType="TabItem">
      <Setter Property="LayoutTransform">
        <Setter.Value>
          <RotateTransform Angle="270" />
        </Setter.Value>
      </Setter>
    </Style>
  </TabControl.ItemContainerStyle>
</TabControl>