1

我正在尝试为我的 tabitems 创建一个模板,但我遇到了问题。我不知道如何设置它们的宽度。我希望 tabitem 自动调整到 tabcontrol 大小,即使它是空的。

这是我的代码:

<Style x:Key="StyleTabItem" TargetType="{x:Type TabItem}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">

                    <Border Height="30" Name="Border" Margin="0,0,0,0"
                                        BorderThickness="0" Background="Transparent" BorderBrush="Transparent">
                        <Grid>
                            <Image Name="img" RenderOptions.BitmapScalingMode="Fant" Source="images/design/in game/onglet_off.png"/>
                            <ContentPresenter Grid.Column="1" VerticalAlignment="Center"
                              HorizontalAlignment="Center"
                                TextBlock.Foreground="#fbffba"
                                TextBlock.FontFamily="Verdana"
                                TextBlock.FontSize="11"
                                Name="textTab" 
                                   Width="{Binding Value, ElementName=Header}"                     
                              ContentSource="Header" Margin="2,0,0,0"
                              RecognizesAccessKey="True">
                            </ContentPresenter>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="img" Property="Source" Value="images/design/in game/onglet_on.png"/>
                            <Setter Property="Cursor" TargetName="Border" Value="Hand"/>
                            <Setter TargetName="textTab" Property="TextBlock.Foreground" Value="#393939"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="img" Property="Source" Value="images/design/in game/onglet_on.png"/>
                            <Setter TargetName="textTab" Property="TextBlock.Foreground" Value="#393939"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

我无法让我的 tabitems 中的网格自动调整为 tabcontrol 的大小。

我试图将我的 tabcontrol 放在 dockPanel 中,但它没有改变。

<DockPanel LastChildFill="True">
            <TabControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Style="{DynamicResource StyleTabControl}" Margin="10,39,10,10" Name="tabControl1" IsEnabled="True" SelectionChanged="tabControl1_SelectionChanged">
                <TabItem   Style="{DynamicResource StyleTabItem}"  Header="tabItem1" Name="tabItem2" IsEnabled="True">
                    <Grid>
                    </Grid>
                </TabItem>
                <TabItem   Style="{DynamicResource StyleTabItem}" Header="tabItem1" Name="tabItem3" IsEnabled="True">
                    <Grid>


                    </Grid>
                </TabItem>
            </TabControl>
            </DockPanel>

谢谢

4

0 回答 0