WPF XAML TabItem标题哦

时间:2013-12-05 14:04:14

标签: c# wpf xaml

我想为XAML WPF应用程序创建一个模板。

我有两个问题:

1)我必须在UserControl

的右上角设置positione TabItem Header

2)我设置TabItem样式,但是当ouse超过tabItem Header时,我会在文本上看到默认的Item effetcs。

<TabControl>
    <TabItem Header="{DynamicResource tab_header_graphic_interface}" Style="{StaticResource generalTabItem}">
      <ScrollViewer CanContentScroll="True" VerticalScrollBarVisibility="Auto" Name="scrDrvPan">
      </ScrollViewer>
    </TabItem>
    <TabItem Header="{DynamicResource tab_header_list_view}" Style="{StaticResource generalTabItem}">
      <ScrollViewer CanContentScroll="True" VerticalScrollBarVisibility="Auto" Name="scrDrvList">
      </ScrollViewer>
    </TabItem>
</TabControl>

我为TabItem设置了样式

<Grid.Resources>
  <Style x:Key="generalTabItem" TargetType="{x:Type TabItem}">
    <Setter Property="FontFamily" Value="/Font/#Futura Std Medium" />
    <Setter Property="FontSize" Value="15" />
    <Setter Property="Foreground" Value="#FF333333" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0 0 0 0" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="Height" Value="30" />

    <Setter Property="HeaderTemplate">
      <Setter.Value>
        <DataTemplate>
          <!--<DockPanel IsItemsHost="True" LastChildFill="False" Margin="2,2,2,0" HorizontalAlignment="Right">
          </DockPanel>-->
          <!--<ContentPresenter Content="{TemplateBinding Property=TabItem.Header}"/>-->
          <TextBlock Background="Transparent" Text="ciao" />
        </DataTemplate>

      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="TabItem.IsSelected" Value="True">
        <Setter Property="FontFamily" Value="/Font/#Futura Std Bold" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="FontSize" Value="15" />
        <Setter Property="Foreground" Value="#FF333333" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0 0 0 0" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Height" Value="30" />
      </Trigger>
      <Trigger Property="TabItem.IsFocused" Value="True">
        <Setter Property="FontFamily" Value="/Font/#Futura Std Bold" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="FontSize" Value="15" />
        <Setter Property="Foreground" Value="#FF333333" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0 0 0 0" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Height" Value="30" />
      </Trigger>
    </Style.Triggers>
  </Style>
</Grid.Resources>

1 个答案:

答案 0 :(得分:0)

你在HeaderTemplate DataTemplate中试过这个吗?`

<TextBlock Background="Transparent" Text="{Binding}" HorizontalAlignment="Right" VerticalAlignment="Top" />