2016-11-07 96 views
0

我在我的應用程序中使用tabcontrol作爲菜單。我想要它的樣式和項目標題看起來很棒。問題在於這會在「內容」區域中產生影響,但這不是我想要的。WPF ItemTab Style

這是在我的窗口

<TabControl Name="Tab_Content" Grid.Row="1" TabStripPlacement="Left" > 
     <TabControl.Resources> 
      <Style TargetType="TabItem"> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="TabItem"> 
          <Grid Name="Panel"> 
           <ContentPresenter x:Name="ContentSite" 
            VerticalAlignment="Center" 
            HorizontalAlignment="Left" 
            ContentSource="Header" 
            Height="25" 
            Margin="5,10,0,0" Width="150" /> 
          </Grid> 
          <ControlTemplate.Triggers> 
           <Trigger Property="IsSelected" Value="True"> 
            <Setter Property="Foreground" Value="Blue" /> 
            <Setter Property="FontWeight" Value="Bold" /> 
            <Setter TargetName="Panel" Property="Background" Value="White" /> 
           </Trigger> 
           <Trigger Property="IsSelected" Value="False"> 
            <Setter Property="Foreground" Value="Black" /> 
            <Setter TargetName="Panel" Property="Background" Value="White" /> 
           </Trigger> 
           <Trigger Property="IsMouseOver" Value="True"> 
            <Setter Property="Foreground" Value="White" /> 
            <Setter TargetName="Panel" Property="Background" Value="Blue" /> 
           </Trigger> 
          </ControlTemplate.Triggers> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </TabControl.Resources> 
     <TabItem Name="item_Home" Header="Home" > 
      <Grid> 
       <Label Name="Test" Content="hello" /> 
      </Grid> 
     </TabItem> 

代碼這是怎麼來看看:

current view how it's look

有沒有辦法來seperatly樣式的內容區域?

回答

0

嘗試設置標題文本塊的樣式並引用祖先TabItem。

XAML:

<Style TargetType="{x:Type TextBlock}" x:Key="toggleTabStyle"> 
    <Setter Property="Foreground" Value="Black" /> 
    <Setter Property="Background" Value="White" /> 
    <Style.Triggers> 
     <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType=TabItem}}" Value="True"> 
      <Setter Property="Foreground" Value="Blue" /> 
      <Setter Property="FontWeight" Value="Bold" /> 
      <Setter Property="Background" Value="White" /> 
     </DataTrigger> 
     <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType=TabItem}}" Value="False"> 
      <Setter Property="Foreground" Value="Black" /> 
      <Setter Property="Background" Value="White" /> 
     </DataTrigger> 
     <DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType=TabItem}}" Value="True"> 
      <Setter Property="Foreground" Value="White" /> 
      <Setter Property="Background" Value="Blue" /> 
     </DataTrigger> 
    </Style.Triggers> 
</Style> 

而在每個TabItem的參考:

<TabItem> 
     <TabItem.Header> 
      <TextBlock Text="Header Text Here" Style="{StaticResource toggleTabStyle}"/> 
     </TabItem.Header>       
     ... 
    </TabItem>