Georg
Georg

Reputation: 117

Styles in XAML doesn't work

Why the color of the TabItems is always black? I want black Background and white letters. Also the Button should be white, but it's black too and not visible. There is some conflict but can't find where. Any ideas? Thx in advance for your help.

<UserControl x:Class="Test.Test"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         xmlns:cal="http://www.caliburnproject.org"   
         xmlns:cm="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
         mc:Ignorable="d" d:DesignHeight="252" d:DesignWidth="894" Background="#FF111111">    

<Grid>        
    <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="48" Margin="70,-14.668,0,0" FontWeight="Light"><Run Language="de-at" Text="test test"/></TextBlock>
    <Button x:Name="Close" Content="➔" HorizontalAlignment="Left" VerticalAlignment="Top" Width="58" Foreground="White" Height="58" RenderTransformOrigin="0.5,0.5" FontSize="40" Margin="-7.625,-8,0,0" Padding="1,-5,1,1" Clip="M50.333,8 L-1.667,8 L-1.667,59.843 L50.333,59.843 z" cm:Message.Attach="Close()">
        <Button.RenderTransform>
            <TransformGroup>
                <ScaleTransform ScaleY="1" ScaleX="-1"/>
                <SkewTransform AngleY="0" AngleX="0"/>
                <RotateTransform Angle="0"/>
                <TranslateTransform/>
            </TransformGroup>
        </Button.RenderTransform>
    </Button>

    <TabControl Margin="42,52,0,0">
        <TabItem Header="Start">

        </TabItem>
            <TabItem Foreground="White" Header="Start 1" >

        </TabItem>
        <TabItem Foreground="White" Header="Start 1">

        </TabItem>
        <TabItem Foreground="White" Header="Start 1">

        </TabItem>
        <TabItem Foreground="White" Header="Start 1">

        </TabItem>
    </TabControl>       
</Grid>

I tried many things and it didn't work. So what i did is put a TextBlock inside the TabItem.Header:

<TabItem>
    <TabItem.Header>
        <TextBlock FontSize="25" Text="Start1" />
    </TabItem.Header>
</TabItem>

Now I can change the color of the TextBlock with Foreground. But don't know how to change the TextBlock color if I click on the TabItem. Maybe I should open a new topic for that. Thanks all for your contribution.

Upvotes: 0

Views: 196

Answers (1)

Rachel
Rachel

Reputation: 132618

You're not setting the Background or Foreground properties of your TabControl at all, so it's using the default colors.

The default color of the Background property of any Control object is Brushes.Transparent (source), while the default Foreground property is based on your system colors (source).

You can use an implicit style in your UserControl.Resources to set a property for all objects of the specified type, such as using this style for all Control objects:

<UserControl.Resources>
    <Style TargetType="{x:Type Control}">
        <Setter Property="Background" Value="Black" />
        <Setter Property="Foreground" Value="White" />
    </Style>
</UserControl.Resources>

Or if you can add a new Brush to your .Resources and set it's x:Key to the System Key of one of the SystemColors , like this:

<UserControl.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.WindowColorKey}" Color="Black"/>
    <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrush}" Color="White"/>
</UserControl.Resources>

(You might need to test a bit to figure out which is the correct SystemColors Key to use. You can find a list of them here)

Upvotes: 1

Related Questions