2017-02-06 54 views
0

我有一個包含另一個UserControl的WPF ListView。它工作正常,但我不能刪除鼠標藍光突出顯示和選擇。WPF ListView刪除mouseover higligth

這裏的代碼:

<UserControl.Resources> 

     <Style TargetType="{x:Type ListViewItem}"> 
     <Setter Property="Background" Value="Transparent" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ListViewItem}"> 
        <Border 
        BorderBrush="Transparent" 
        BorderThickness="0" 
        Background="{TemplateBinding Background}"> 
         <GridViewRowPresenter HorizontalAlignment="Stretch" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Width="Auto" Margin="0" Content="{TemplateBinding Content}"/> 
        </Border> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

    <DataTemplate DataType="{x:Type vm:ElementViewModel}" x:Key="ElementTemplate"> 
     <vw:ElementView /> 
    </DataTemplate> 

</UserControl.Resources> 

<GroupBox Header="{x:Static Translate:Translate.CreateLoop}"> 

    <ListView ItemsSource="{Binding Path=ElementList, UpdateSourceTrigger=PropertyChanged}" 
       ItemTemplate="{StaticResource ElementTemplate}" 
       Background="{StaticResource EnvLayout}" 
       BorderBrush="Transparent"> 
     <ListView.ItemContainerStyle> 
      <Style TargetType="{x:Type ListViewItem}"> 
       <Style.Resources> 
        <!--Foreground for Selected ListViewItem--> 
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/> 
        <!--Background for Selected ListViewItem--> 
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/> 
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/> 
        <SolidColorBrush x:Key="ItemBackgroundHover" Color="Transparent"/> 
       </Style.Resources> 
      </Style> 
     </ListView.ItemContainerStyle> 
    </ListView> 


</GroupBox> 

所述的DataTemplate用於與相應的視圖模型的視圖綁定。 在這裏,鼠標的風格,我想刪除

enter image description here

回答

1

試試這個

添加風格

<UserControl.Resources> 
    <Style x:Key="MyStyle" TargetType="ListViewItem"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="ListViewItem"> 
        <Grid Background="{TemplateBinding Background}"> 
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
        /> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</UserControl.Resources> 

刪除你的風格,而是

ItemContainerStyle="{StaticResource MyStyle}" 
+0

太好了!它的工作原理與我預期的完全相同 – andrea