【问题标题】:WPF TabControl overrides TabItem Background?WPF TabControl 覆盖 TabItem 背景?
【发布时间】:2021-03-30 06:37:26
【问题描述】:
<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(通过使用设计器拖动)时,它会跟随背景颜色。

我可能只是在这里缺少一个属性,但我不知道是什么。

【问题讨论】:

    标签: c# wpf windows xaml


    【解决方案1】:

    您可以如下尝试。

    <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>
    

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

    【讨论】:

      【解决方案2】:

      你看过这个链接吗: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"

      【讨论】:

      • 它和 TabControl 不一样。无论如何它都是白色的。
      猜你喜欢
      • 2012-02-18
      • 1970-01-01
      • 2018-04-21
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 2011-09-10
      相关资源
      最近更新 更多