WPF TabControl是否覆盖TabItem背景


<Window x:Name="Editor" x:Class="Editor.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:Editor"
mc:Ignorable="d"
Title="Editor" Height="450" Width="800" AllowsTransparency="True" WindowStyle="None" Icon="src/Assets/Core/Lively.ico" Cursor="Arrow">
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterY="0.5" CenterX="0.5" ScaleY="2"/>
<SkewTransform CenterY="0.5" CenterX="0.5"/>
<RotateTransform Angle="-133.069" CenterY="0.5" CenterX="0.5"/>
<TranslateTransform/>
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="#FF360606" Offset="1"/>
<GradientStop Color="#FF150303" Offset="0.474"/>
<GradientStop Color="#FF2E0606" Offset="1"/>
<GradientStop Color="#FF0E0707" Offset="1"/>
</LinearGradientBrush>
</Window.Background>
<Window.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.207"/>
<GradientStop Color="Black" Offset="0.007"/>
</LinearGradientBrush>
</Window.OpacityMask>
<Grid x:Name="EditorBody" Background="Transparent">
<TabControl Height="44" Margin="0,0,0,406" Background="Transparent">
<TabItem Background="Black" Height="44" Width="150" BorderBrush="Black">
<Label Content="Untitled note" />
</TabItem>
</TabControl>
</Grid>
</Window>

在这里的底部;我似乎无法让TabItem对其Background属性的更改做出反应。不管怎样,它都是白色的。

然而,当我将TabItem从TabControl中移出时(通过使用设计器拖动(,它会跟随背景色。

我可能只是错过了这里的一处房产,但我不知道是什么。

您可以按如下方式尝试。

<Grid  x:Name="EditorBody" Background="Transparent">
<TabControl Height="100" Background="Transparent" Margin="0,0,0,406">
<TabItem Header="Tab A" Background="Red" Foreground="Black">
<Grid>
<Label Content="Untitled note" Foreground="White"/>
</Grid>
</TabItem>
<TabItem Header="Tab B" Background="Orange" Foreground="Black">
<Grid></Grid>
</TabItem >
<TabItem Header="Tab C" Background="Yellow" Foreground="Black">
<Grid></Grid>
</TabItem>
</TabControl>
</Grid>

如果你有任何问题,请写一条评论。

您看到这个链接了吗:https://social.msdn.microsoft.com/Forums/vstudio/en-US/bb8022a0-89ba-4753-b2df-6a48e67ca834/how-to-set-tabitem-background-color?forum=wpf根据以上链接中对拟议问题的回答:"TabControl将其ContentPresenter的内容绑定到所选TabItem的内容。这将解释为什么内容的背景与TabControl而不是TabItem"相同;

最新更新