【问题标题】:Hiding Tab headers in Silverlight在 Silverlight 中隐藏选项卡标题
【发布时间】:2016-09-27 23:49:21
【问题描述】:

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

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

谢谢。

【问题讨论】:

  • 我相信您可以设置它们的样式,在您覆盖 TabControl 的控件模板之前尝试使用 TabHeaderStyle / ItemTemplate(TabControl 派生自 ItemsControl)。

标签: c# xaml silverlight


【解决方案1】:

按照 Martin 的建议,我使用了微软模板来解决问题。

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

此代码适用于silvelight 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多