我有一个如下所示的ListView:
<ListView x:Name="LocationList"
BorderBrush="{x:Null}"
Margin="50,20,20,50"
ItemsSource="{Binding Locations}" />
这样的样式和控件模板:
<ControlTemplate x:Key="SelectedTemplate" TargetType="ListViewItem">
<Border SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}" >
<ContentControl SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Margin}"
FontSize="{TemplateBinding FontSize}"/>
</Border>
</ControlTemplate>
<Style x:Name="ListStyle" TargetType="ListViewItem">
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="FontSize" Value="30"/>
<Setter Property="Margin" Value="3,3,3,3"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Gray"/>
<Setter Property="Template" Value="{StaticResource SelectedTemplate}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="Selector.IsSelectionActive" Value="true" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="Red" />
<Setter Property="Template" Value="{StaticResource SelectedTemplate}" />
</MultiTrigger>
</Style.Triggers>
</Style>
使用鼠标时,这可以正常工作;将光标悬停在列表项上会激活“IsMouseOver”样式并单击它会激活“IsSelected”样式。但是,当使用触摸屏单击列表项时仅激活“IsMouseOver”样式并且未选择该项目,要选择它我必须再次单击相同的项目。当手指向下(导致光标出现)时,当我将手指拖过它时,“IsMouseOver”样式不会被激活。