在悬停时,Listiview项目不突出显示 - UWP(Windows 10)

时间:2016-01-23 04:28:25

标签: xaml listview winrt-xaml win-universal-app uwp

我有一个UserControl用作ListView中的项目模板,当我悬停特定项目时它没有突出显示它我的项目中有其他ListViews突出显示特定项目。

我已从UserControl中删除了代码,并将其直接复制/粘贴到我的DataTemplate中,以检查它是否与我使用UserControl这一事实有关,但没有区别。

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

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

这是我的UserControl中的代码:

<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不同?

感谢。

1 个答案:

答案 0 :(得分:1)

项目未突出显示,因为您设置了Background="White",此颜色将始终高于突出显示颜色。 UserControl背景需要设置为Transparent

要使其按照您想要的方式运作,您需要更改ItemContainerStyle的{​​{1}}。如果ListView中有不同的元素,则可以使用ListView

您可以详细了解ItemContainerStyleSelector here

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

Background