WPF TabControl如何在选择tabItem时删除行

时间:2016-04-02 13:37:54

标签: c# wpf wpf-controls

设计师讨厌开发人员,为什么他们创造了如此糟糕的设计!)) 所以我的任务是从psd文件创建xaml UI。我正在完成它,但我不知道如何删除选定tabItem中的行。对图片感到高兴。

这就是我需要得到的东西。 enter image description here

这就是我得到的。enter image description here

如何删除此行?没有硬编码可能吗? 这是我的标签控件的代码。

     <TabControl.Resources>
            <Style TargetType="TabControl">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabControl}">
                            <Grid KeyboardNavigation.TabNavigation="Local">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Border
                                    Name="Border"
                                    Grid.Row="0"
                                    BorderBrush="{StaticResource SolidBrush_Blue}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    KeyboardNavigation.TabNavigation="Local"
                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                    KeyboardNavigation.TabIndex="2" >
                                    <ContentPresenter
                                        Name="PART_SelectedContentHost"
                                        ContentSource="SelectedContent">
                                    </ContentPresenter>
                                </Border>
                                <TabPanel
                                    Name="HeaderPanel"
                                    Grid.Row="1"
                                    Panel.ZIndex="1"
                                    HorizontalAlignment="Center"
                                    IsItemsHost="True"
                                    KeyboardNavigation.TabIndex="1"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- SimpleStyles: TabItem -->
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabItem}">
                            <Grid
                                x:Name="grid">
                                <Border
                                    Name="Border"
                                    Margin="5,0,5,0"
                                    Padding="30 15 30 15"
                                    CornerRadius="0 0 3 3"
                                    BorderBrush="{StaticResource SolidBrush_Blue}"
                                    BorderThickness="2 0 2 2" >
                                    <ContentPresenter
                                        x:Name="contentPresenter"
                                        VerticalAlignment="Center"
                                        ContentSource="Header"
                                        TextBlock.Foreground="White"
                                        TextBlock.FontFamily="{StaticResource FontFamilyRegular}"
                                        RecognizesAccessKey="True">
                                    </ContentPresenter>
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter TargetName="Border"
                                            Property="Background"
                                            Value="White" />
                                    <Setter TargetName="contentPresenter"
                                            Property="TextBlock.FontFamily"
                                            Value="{StaticResource FontFamilyBold}"/>
                                    <Setter TargetName="contentPresenter"
                                            Property="TextBlock.Foreground"
                                            Value="{StaticResource SolidBrush_Blue}"/>
                                </Trigger>
                                <Trigger Property="IsSelected" Value="False">
                                    <Setter TargetName="Border"
                                            Property="Background" 
                                            Value="{StaticResource SolidBrush_Blue}" />
                                    <Setter TargetName="contentPresenter"
                                            Property="TextBlock.Background"
                                            Value="White"/>
                                    <Setter TargetName="contentPresenter"
                                            Property="TextBlock.FontFamily"
                                            Value="{StaticResource FontFamilyRegular}"/>
                                    <Setter TargetName="contentPresenter" 
                                            Property="TextBlock.Foreground" 
                                            Value="White"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </TabControl.Resources>

1 个答案:

答案 0 :(得分:3)

在边框Border设置Margin="5,-1,5,0"的TabItem模板中。边框将向上移动并隐藏TabControl的边界线,默认厚度为1

enter image description here