繁体   English   中英

WPF TabControl 覆盖 TabItem 背景?

[英]WPF TabControl overrides TabItem Background?

<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 的内容。这可以解释为什么 Content 的背景与 TabControl 而不是 TabItem 相同"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM