WPF listviewItem样式触发器无法正常工作

时间:2013-10-14 14:18:43

标签: wpf styling listviewitem

<ListView ScrollViewer.VerticalScrollBarVisibility="Disabled" Grid.Column="1" Grid.Row="3" ItemsSource="{Binding TeamTagsLiveDTO}" x:Name="teamTagsGrid" HorizontalAlignment="Left" SelectionChanged="SortByPlayerTags" Style="{StaticResource TeamTagsListViewStyle}">
  <ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
      <Setter Property="BorderThickness" Value="0"/>
      <Setter Property="Padding" Value="0"/>
      <Setter Property="BorderBrush" Value="{x:Null}"/>
      <Style.Triggers>
        <Trigger Property="IsSelected" Value="true">
          <Setter Property="BorderThickness" Value="0"/>
          <Setter Property="Background" Value="Black"/>
        </Trigger>
        <Trigger Property="IsMouseOver" Value="true">
          <Setter Property="BorderThickness" Value="0"/>
          <Setter Property="BorderBrush" Value="{x:Null}"/>
        </Trigger>
      </Style.Triggers>
    </Style>
  </ListView.ItemContainerStyle>
  <ListView.ItemsPanel>
    <ItemsPanelTemplate>
      <StackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
  </ListView.ItemsPanel>
  <ListView.ItemTemplate>
    <DataTemplate>
      <TextBlock Style="{StaticResource teamtagsstyleLive}" Text="{Binding TeamTagsName1}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

我有如上所示的片段代码:

setter元素工作正常,但触发器无效。这有什么不对吗?

1 个答案:

答案 0 :(得分:1)

解决了它。结果控制模板处理背景属性和ListView项的高亮颜色,而不是ListViewItem本身。