none
TabItem的textblock內容如何修改 RRS feed

  • 问题

  • 我參考了版上Bob的作法,但是這個做法沒辦法修改其他TabItem的TextBlock內容,請問要怎麼修改才能改其他TabItem的TextBlock內容呢?謝謝



    2017年11月15日 3:38

答案

  • Hi,

    尝试修改TabItem的模板。

     <TabControl Margin="10">
                <TabControl.Resources>
                    <Style TargetType="{x:Type TabItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type TabItem}">
                                    <Border
                                        x:Name="Spacer"
                                        Width="Auto"
                                        Height="Auto"
                                        Margin="0,0,0,0"
                                        Padding="0,0,40,0"
                                        BorderBrush="Transparent"
                                        BorderThickness="0">
                                        <Border
                                            x:Name="Border"
                                            Width="Auto"
                                            MinWidth="100"
                                            MinHeight="50"
                                            VerticalAlignment="Bottom"
                                            Background="Gray"
                                            BorderBrush="DarkGray"
                                            BorderThickness="0,0,0,0"
                                            CornerRadius="6,6,0,0"
                                            Cursor="Hand">
                                            <Grid>
                                                <Image
                                                    x:Name="TabImage"
                                                    MaxWidth="100"
                                                    MaxHeight="50"
                                                    Source="/Images/China.jpg"
                                                    Stretch="UniformToFill" />
                                                <ContentPresenter
                                                    x:Name="ContentSite"
                                                    Width="Auto"
                                                    Height="Auto"
                                                    Margin="8,3,8,3"
                                                    HorizontalAlignment="Center"
                                                    VerticalAlignment="Center"
                                                    ContentSource="Header"
                                                    TextElement.FontFamily="Arial"
                                                    TextElement.FontSize="10pt"
                                                    TextElement.Foreground="Black" />
                                            </Grid>
                                        </Border>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="TabImage" Property="Source" Value="/Images/China.jpg" />
                                        </Trigger>
                                        <Trigger Property="IsSelected" Value="False">
                                            <Setter TargetName="TabImage" Property="Source" Value="/Images/USA.png" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </TabControl.Resources>
                <TabItem Header="test1" />
                <TabItem Header="test2" />
                <TabItem Header="test3" />
                <TabItem Header="test4" />
            </TabControl>

    Sincerely,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 魏高個 2017年11月16日 8:25
    2017年11月15日 7:12
    版主