5

我在 WPF 中有一个带有 3 个选项卡的 TabControl,每个选项卡在选项卡标题旁边都有一个图像。这是一个例子

        <TabItem>
            <TabItem.Header>
                <StackPanel Orientation="Horizontal">
                    <Image Name="img" Height="auto" Width="auto" Source="images/1.png" />
                    <TextBlock Text="Login" Margin="2,0,0,0" VerticalAlignment="Center" />
                </StackPanel>
            </TabItem.Header>
        </TabItem>

When the tab is selected the text is black and the background is white, when its not it's a light gray color and a slightly darker text. 这很好用,但我不知道如何更改未选择的选项卡上的图像?现在,图像看起来都一样,内部有一个数字的绿色圆圈,但是当未选择一个数字时,我希望它更改为其他映像,即ia images/1_notselected.png和images/2_notselected.png。是被选中的。谢谢!

4

1 回答 1

6

为 TabItem 声明一个样式,并在内部样式更改触发器中的图像。

声明一个 HeaderTemplate,然后像这样使用 Trigger:

   <Trigger Property="IsSelected" Value="True">
       <Setter Property="Source" TargetName="img" Value="images/customimage.png"/>
   </Trigger>
于 2009-11-14T07:06:18.237 回答