1

我有一个看起来像这样的 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”样式时,它不会被激活。

4

0 回答 0