如何根据TabStripPlacement属性WPF影响TabPanel模板的位置

时间:2012-08-04 01:47:39

标签: c# .net wpf tabcontrol

我为我的应用程序中的所有TabControl创建了一个控件模板。模板将TabPanel置于选项卡项主要内容的左侧。

   <Style TargetType="{x:Type TabControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabControl}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TabPanel Grid.Column="0"
                              Panel.ZIndex="1"
                              Margin="0,0,0,0"
                              IsItemsHost="True"
                              Background="Transparent" />
                    <Border Grid.Column="1"
                            BorderBrush="Black"
                            BorderThickness="1"
                            CornerRadius="0,12,12,12">
                        <Border.Background>
                            <SolidColorBrush Color="Green" />
                        </Border.Background>
                        <ContentPresenter ContentSource="SelectedContent" />
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

这是我最初希望我的标签控件看起来像的样子。但是当我将TabStripPlacement属性设置为Top时,它仍然保留在左侧。有没有办法在控件模板中定义根据TabStrip属性调整TabPanel的位置?谢谢你提前。

1 个答案:

答案 0 :(得分:2)

您需要在您的样式中使用对TabStripPlacement属性中的更改做出反应的触发器。

This stackoverflow post提供了一个示例。

相关问题