更改选项卡控制面板背景的颜色

change color of the tab control panel background

我有一个 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>

有没有办法改变 TabItems 所在的 Panel 的颜色:

感谢您提出任何建议。

OP 澄清问题后进行编辑。

你指的是什么与TabItem甚至TabControl无关。它只是 TabControl 所在的控件。

请看下面的简单例子:

<Window x:Class="WhosebugWPF.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:WhosebugWPF"
        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>

它看起来像这样: