2016-11-16 29 views
0

我有一個ListView,當我用鼠標選擇一行時,當我按下時,該行得到一些填充或邊距,我不知道它是什麼,我只是希望它不會發生,只需選擇一行而無需任何效果,例如當我用鍵盤選擇一行時。如何清除ListViewItem上的按下效果?

回答

1

要更改默認行爲,您必須更改ListViewItem的樣式。你可以找到關於msdn或本地驅動器上這些樣式:

C:\ Program Files文件(x86)的\的Windows套件\ 10 \設計時\ CommonConfiguration \中性\ UAP \ 10.0.14393.0 \通用\ 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> 
      ... 
+0

我應該帶上它的所有代碼嗎?我可以帶上壓縮和...塊(我想改變的)嗎? – Maryam

+0

你必須在Setter Property =「Template」下引入所有東西,因爲這是一個塊。 – Bart

+0

有關樣式和模板的更多信息,如果您想了解更多信息:https://msdn.microsoft.com/en-us/library/ee230084(v=vs.110).aspx – Bart