如何删除ListViewItem上的按压效果?

时间:2016-11-16 07:30:24

标签: c# uwp listviewitem uwp-xaml

我有一个ListView,当我用鼠标选择一行时,我正在按下,那行会得到一些填充或边距,我不知道它是什么,我只是希望它不会发生,只需选择一行没有任何效果,就像我选择带键盘的行一样。

1 个答案:

答案 0 :(得分:1)

要更改默认行为,您必须更改ListViewItem的样式。您可以在spinlock或本地驱动器上找到这些样式:

  

C:\ Program Files(x86)\ Windows Kits \ 10 \ DesignTime \ CommonConfiguration \ Neutral \ UAP \ 10.0.14393.0 \ Generic \ generic.xaml

有问题的视觉状态很可能是PressedPressedSelected。将这些视觉状态改变为ListView要做的任何事情。

<!-- Style for Windows.UI.Xaml.Controls.ListViewItem -->
<Style TargetType="ListViewItem" x:Key="ListViewItemExpanded">
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="IsHoldingEnabled" Value="True"/>
<Setter Property="Padding" Value="12,0,12,0"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/>
<Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}"/>
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="ListViewItem">
      <Grid x:Name="ContentBorder"
              Background="{TemplateBinding Background}"
              BorderBrush="{TemplateBinding BorderBrush}"
              BorderThickness="{TemplateBinding BorderThickness}">
        <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
            ...
            <VisualState x:Name="Pressed">
              <Storyboard>
                <DoubleAnimation Storyboard.TargetName="BorderBackground"
                                 Storyboard.TargetProperty="Opacity"
                                 Duration="0"
                                 To="1"/>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Fill">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListMediumBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <PointerDownThemeAnimation TargetName="ContentPresenter" />
              </Storyboard>
            </VisualState>
            ...
            <VisualState x:Name="PressedSelected">
              <Storyboard>
                <DoubleAnimation Storyboard.TargetName="MultiSelectCheck"
                                 Storyboard.TargetProperty="Opacity"
                                 Duration="0:0:0"
                                 To="1"/>
                <DoubleAnimation Storyboard.TargetName="BorderBackground"
                                 Storyboard.TargetProperty="Opacity"
                                 Duration="0"
                                 To="1"/>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Fill">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListAccentHighBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <PointerDownThemeAnimation TargetName="ContentPresenter" />
              </Storyboard>
            </VisualState>
          </VisualStateGroup>
          ...
相关问题