WPF TabItem 标题图像

发布于 2024-08-11 07:12:57 字数 696 浏览 2 评论 0原文

我在 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>

当选择选项卡时,文本为黑色,背景为白色,当未选择选项卡时,文本为浅灰色和稍深的文本。这很好用,但我不知道如何更改未选择的选项卡上的图像?现在图像看起来都是一样的,里面有一个数字的绿色圆圈,但是当未选择选项卡时,我希望它更改为不同的图像,即当选项卡为 images/1_notselected.png 和 images/2_notselected.png 时是选定的一个。谢谢!

I've got a TabControl in WPF with 3 tabs, and each tab has an image next to the title of the tab. Here's an example

        <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. This works great, but what I can't figure out is how to change the images on the tabs that aren't selected? Right now the images all look the same, green circle with a number inside, but when a tab is not selected I'd like it to change to a different image, i.e. images/1_notselected.png and images/2_notselected.png when tab is is the selected one. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风几经秋 2024-08-18 07:12:57

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

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

   <Trigger Property="IsSelected" Value="True">
       <Setter Property="Source" TargetName="img" Value="images/customimage.png"/>
   </Trigger>

declare a style for TabItem, and inside style change the image in a trigger.

Declare a HeaderTemplate and then use Trigger like this:

   <Trigger Property="IsSelected" Value="True">
       <Setter Property="Source" TargetName="img" Value="images/customimage.png"/>
   </Trigger>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文