c# - 更改选项卡控制面板背景的颜色
问题描述
我有一个TabControl
这样的:
<TabControl ItemsSource="{Binding TabItems, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedIndex="0"
BorderThickness="0"
TabStripPlacement="Left"
Padding="10,0,0,10">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Grid Name="Panel">
<ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="20,5"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Panel" Property="Background" Value="#d9534f" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Panel" Property="Background" Value="#E6E3DB" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Header" Value="{Binding Header, Mode=OneTime}"/>
<Setter Property="Content" Value="{Binding Content, Mode=OneTime}"/>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
有没有办法改变Panel
所在位置的颜色TabItems
:
感谢您的任何建议。
解决方案
OP澄清问题后编辑。
你所指的 are 与 theTabItem
甚至TabControl
. 它只是TabControl
驻留的控件。
请看以下简单示例:
<Window x:Class="StackOverflowWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StackOverflowWPF"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="300">
<Grid Background="LightSeaGreen">
<TabControl Background="Red">
<TabItem Header="Tab1" Background="Yellow">
</TabItem>
<TabItem Header="Tab1" Background="Green">
</TabItem>
</TabControl>
</Grid>
</Window>
这就是它在设计器中的样子:
所以回到你的例子,我假设你想设置箭头指向的区域的颜色,同时保持表单的其余部分为不同的颜色。我会Grid
为此使用控件。
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="LightGreen">
<TabControl Grid.Row="0" Background="Red" Height="100">
<TabItem Header="Tab1" Background="Yellow">
</TabItem>
<TabItem Header="Tab1" Background="Green">
</TabItem>
</TabControl>
</Grid>
<Grid Grid.Row="1"/>
</Grid>
它看起来像这样:
推荐阅读
- wpf - 在 WPF 数据网格 MVVM 中创建倒数计时器列
- scrapy - Scrapy过滤器相同的url在“http”和“https”中不同
- swift - “minimumFetchInterval”未在“RemoteConfigSettings”中定义
- python - 为什么我尝试在 Windows PC 上安装 PySide2 时总是出错?
- javascript - 提取大括号之间的字符串但排除一些
- python - 在 Python 的多个目录中查找相同的文件
- angular - 如何在响应标头中设置缓存控制
- c# - C# Switch 表达式返回不同的结果
- r - 如何在R语言中将标签文本转换为数值
- python - 具有默认枚举值的枚举类方法失败