将鼠标悬停在 - UWP (Windows 10) 上时,列表视图项目不突出显示

Listiview Item not highlighting when hovering over - UWP (Windows 10)

我有一个 UserControl 用作 ListView 中的项目模板,当我将鼠标悬停在特定项目上时,它不会突出显示它,但我的项目中还有其他 ListViews,其中突出显示了特定项目。

我已经从我的 UserControl 中删除了代码,copy/pasted 它直接在我的 DataTemplate 中删除,以检查它是否与我使用的 UserControl 有关,但没有区别。

此 ListView 包含在 SemanticZoom 中,因此我再次删除了 SemanticZoom 以检查行为是否会改变,但无济于事!仍然没有突出显示。

我所有的 ListView 都将它们的 SelectionMode 设置为 Single,并且我在应用程序级别定义了一个应用于我所有 ListView 的样式

这是我的用户控件中的代码:

<UserControl
    x:Class="MyApp.UserControls.ZoomedIn"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyApp.UserControls"
    xmlns:converters="using:MyApp.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="470">

    <UserControl.Resources>
        <converters:WrapOnConverter x:Key="WrapOnConverter"/>
    </UserControl.Resources>

    <Grid x:Name="Details" 
          Background="White" 
          Grid.Column="0" 
          Grid.Row="0"
          Margin="12,5,12,5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Image x:Name="Image" 
               Source="{Binding Image}" 
               Width="100" 
               Height="100" 
               Stretch="UniformToFill" 
               Grid.Row="0" 
               Grid.Column="0" 
               Grid.RowSpan="2" 
               HorizontalAlignment="Left" 
               VerticalAlignment="Top" />
        <Image x:Name="Image2" 
               Source="{Binding Image2}" 
               Width="30" 
               Height="30" 
               Margin="67,67,0,0" 
               Stretch="UniformToFill" 
               Grid.Row="0" 
               Grid.Column="0" 
               Grid.RowSpan="2" 
               HorizontalAlignment="Left" 
               VerticalAlignment="Top" />
        <Image x:Name="Image3" 
               Source="{Binding Image3}" 
               Width="30" 
               Height="30" 
               Margin="32,67,0,0" 
               Stretch="UniformToFill" 
               Grid.Row="0" 
               Grid.Column="0" 
               Grid.RowSpan="2" 
               HorizontalAlignment="Left" 
               VerticalAlignment="Top" />        
        <StackPanel Margin="5,0,5,0" 
                    Grid.Row="0" 
                    Grid.Column="1" 
                    VerticalAlignment="Top">
            <TextBlock x:Name="Title" 
                       Text="{Binding Title}" 
                       Foreground="{ThemeResource
                       SystemControlForegroundAccentBrush}"
                       FontWeight="SemiBold"
                       VerticalAlignment="Top" 
                       TextWrapping="{Binding 
                       Converter={StaticResource WrapOnConverter}}" />
            <TextBlock x:Name="Time" 
                       Text="{Binding Time}" 
                       Foreground="DarkCyan" 
                       VerticalAlignment="Top" 
                       HorizontalAlignment="Left"
                       Margin="0,5,0,5" />
            <TextBlock x:Name="Description"
                       Text="{Binding Description}" 
                       Foreground="Black" 
                       TextWrapping="Wrap" 
                       VerticalAlignment="Top" 
                       HorizontalAlignment="Left"
                       MaxLines="2"/>
        </StackPanel>
    </Grid>
</UserControl>

而我的ListView定义如下:

<ListView ItemsSource="{Binding Source={StaticResource cvsDetails}}"
          SelectionMode="Single"
          SelectedIndex="{Binding SelectedDetailIndex}"
          SelectedItem="{Binding SelectedDetail, Mode=TwoWay}" 
          ItemContainerStyle="{StaticResource ListViewItemStyle}">
          <ListView.ItemTemplate>
              <DataTemplate>
                  <usercontrols:ZoomedIn DataContext="{Binding}" />
              </DataTemplate>
          </ListView.ItemTemplate>
          <ListView.GroupStyle>
              <GroupStyle>
                  <GroupStyle.HeaderTemplate>
                      <DataTemplate>
                          <TextBlock FontSize="20" 
                                     Text="{Binding CategoryName}" 
                                     Foreground="{ThemeResource
                                     SystemControlForegroundAccentBrush}" 
                                     FontWeight="SemiBold" />
                      </DataTemplate>
                  </GroupStyle.HeaderTemplate>
              </GroupStyle>
          </ListView.GroupStyle>
          <Interactivity:Interaction.Behaviors>
              <Core:EventTriggerBehavior EventName="Tapped">
                  <Core:InvokeCommandAction 
                      Command="{Binding ItemClickCommand}"
                      CommandParameter="{Binding SelectedDetail}" />
              </Core:EventTriggerBehavior>
          </Interactivity:Interaction.Behaviors>
  </ListView>

有没有人知道为什么一个 ListView 的行为与其他 ListView 不同?

谢谢。

该项目没有突出显示,因为您设置了 Background="White",并且此颜色将始终位于突出显示颜色之上。 UserControl背景需要设置为Transparent

要使其按您希望的方式工作,您需要更改 ListViewItemContainerStyle。如果您的 ListView 中有不同的元素,您可以使用 ItemContainerStyleSelector.

您可以阅读更多关于 ListViewItem here

您需要更改列表视图项的 Background 属性,例如:

<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Background" Value="White"/>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>