WPF TabItem 标题图像
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为 TabItem 声明一个样式,并在样式内部更改触发器中的图像。
声明一个 HeaderTemplate,然后像这样使用 Trigger:
declare a style for TabItem, and inside style change the image in a trigger.
Declare a HeaderTemplate and then use Trigger like this: