0

我正在实现我自己的假TabControl以看起来像 IE8-tabs(我知道 tabcontrol 的其他实现)。

MyTabControl派生自Selector,而 my TabItems 派生自ContentControl。选择选项卡时,我将IsSelected(依赖属性)设置为 true。我的Trigger样子是这样的:

<Trigger Property="IsSelected" Value="true">
    <Setter Property="Margin" Value="0,0,0,0"/>
</Trigger>

我的默认边距TabItem是 0,2,0,0。换句话说,未选中TabItem的 s 应该与选中的有轻微的偏移。我已经尝试反向执行此操作,并改用高度。结果是TabItem被选中的 s 似乎被剪裁而不是改变边距。当直接在标签上设置属性时,我得到正确的视觉效果,即:

<local:TabItem IsSelected="true"/>

我试过在我的依赖属性中使 , 无效,但没有太大成功ArrangeVisualMeasureIsSelected

我在这里想念什么?

编辑:

这是完整TabItem的样式(样式部分基于此项目: http: //www.codeproject.com/KB/WPF/WpfTabControl.aspx):

    <Style TargetType="{x:Type local:TabItem}">
    <Setter Property="Background" Value="{Binding Path=TabItemNormalBackground, RelativeSource={RelativeSource Self}}"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Height" Value="26"/>
    <Setter Property="Margin" Value="0,2,0,0"/>
    <Setter Property="HorizontalAlignment" Value="Stretch" />
    <Setter Property="VerticalAlignment" Value="Bottom" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:TabItem}">
                <Border CornerRadius="3,3,0,0"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{StaticResource TabItemOuterBorderBrush}"
                        BorderThickness="1,1,1,0">
                    <Border CornerRadius="3,3,0,0"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{StaticResource TabItemInnerBorderBrush}"
                        BorderThickness="1,1,1,0">
                        <Grid HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <ContentPresenter Grid.Column="0" Content="{TemplateBinding Icon}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            <ContentPresenter Grid.Column="1"
                                    SnapsToDevicePixels="True"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Center"
                                    RecognizesAccessKey="True"/>
                            <Button x:Name="PART_CloseButton" 
                            Grid.Column="2" 
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center"
                            Margin="5,0,5,0"
                            Style="{StaticResource CloseButtonStyle}"
                            Visibility="Collapsed"
                            />
                        </Grid>

                    </Border>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="true">
                        <Setter Property="Background" Value="{Binding Path=TabItemSelectedBackground, RelativeSource={RelativeSource Self}}"/>
                        <Setter Property="Margin" Value="0,0,0,0"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
4

1 回答 1

0

没关系。我将 tabitemsdesiredsize 存储在 MeasureOverride 中,并忘记在后续调用中清除它们。

于 2010-01-07T20:54:00.513 回答