在Silverlight中隐藏选项卡标题

时间:2016-05-30 08:13:40

标签: c# xaml silverlight

我尝试了几种方法,但我无法做到。如何在 Silverlight 中的tabcontrols中隐藏选项卡标题。我在互联网上搜索过,但主要是针对WPF的解决方案。

我有按钮在标签之间导航,但我不希望用户看到标题。

感谢。

1 个答案:

答案 0 :(得分:0)

正如Martin所说,我使用微软模板来解决问题。

首先,site上的TabItem和TabControl有很好的默认模板。我用过它们。

此代码适用于silverlight 5,而对于silvelight 3或4,您需要更改“sdk”。您需要使用我提供的网站中的那个。

我刚刚接受了模板的相关部分,我不确定是否采用所有模板并仅更新此相关部分。但是,当使用类似下面的代码,即只有模板的相关部分时,它可以正常工作。

<StackPanel Grid.Row ="1" Grid.Column="1" >
<StackPanel.Resources>
    <Style TargetType="sdk:TabControl" x:Key="HeaderTemplate">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sdk:TabControl">
                    <!--here comes the template-->  
                    <Grid x:Name="TemplateTop" Visibility="Collapsed">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <controlsPrimitives:TabPanel x:Name="TabPanelTop" Margin="2,2,2,-1" Canvas.ZIndex="1" Visibility="Collapsed"/>
                        <Border MinHeight="10" MinWidth="10" Grid.Row="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0,0,3,3">
                            <ContentPresenter x:Name="ContentTop" Cursor="{TemplateBinding Cursor}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
                        </Border>
                        <Border x:Name="DisabledVisualTop" IsHitTestVisible="False" Opacity="0" Grid.Row="1" Grid.RowSpan="2" Canvas.ZIndex="1" Background="#8CFFFFFF" CornerRadius="0,0,3,3"/>
                    </Grid>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</StackPanel.Resources>

<sdk:TabControl Style="{StaticResource HeaderTemplate}">
    <sdk:TabItem>
    </sdk:TabItem>
    <!--your tabes comes here-->  
</sdk:TabControl></StackPanel>

我认为你可以直接使用

之间的部分
<StackPanel.Resources>...</StackPanel.Resources>

我希望它可以帮助那些有同样问题的人。

还有一个类似的问题并回答here