2013-01-25 24 views
0

为什么TabItems的颜色始终为黑色?我想要黑色Background和白色字母。 Button也应该是白色的,但它也是黑色的,不可见。有一些冲突,但无法找到哪里。有任何想法吗? Thx提前为您提供帮助。XAML中的款式不起作用

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

我试了很多东西,也没有工作。所以我所做的是把TextBlockTabItem.Header内:

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

现在我可以改变TextBlock的颜色与Foreground。但不知道如何改变TextBlock的颜色,如果我点击TabItem。也许我应该为此打开一个新话题。感谢您的贡献。

+1

你如何指望我们给你一个答案。我们不知道所有资源字典中的内容。 –

+0

我删除了字典,仍然没有变化 – Georg

+0

你能分享你最新的xaml代码吗? –

回答

1

根本没有设置您的TabControlBackgroundForeground属性,所以它使用的是默认颜色。

任何Control对象的Background属性的默认颜色是Brushes.Transparentsource),而默认Foreground属性基于您的系统颜色(source)。

您可以使用隐式的风格在UserControl.Resources设置属性指定类型的所有对象,如使用这种风格的所有控制对象:

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

或者,如果你可以添加一个新刷您.Resources并设置它的x:KeySystemColors之一的系统密钥,这样的:

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

(您可能需要测试了一下,以找出哪些是正确的systemColors中键使用哟你可以找到他们的名单here

+0

我把你的代码放入我的xaml(在之前),但仍然无法正常工作..我将在稍后创建新项目并重试..thx – Georg

+0

@Georg看到我更新的答案。我可能有SystemColors键不正确。 – Rachel