2017-02-06 4 views
0

У меня есть ListView WPF, содержащий другой UserControl. Он отлично работает, но я не могу удалить выделение и выделение мыши blu.WPF ListView remove 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 используется, чтобы связать вид с соответствующим ViewModel. Здесь мышь над стилем я хотел бы, чтобы удалить

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

Great! Он работает точно так, как я ожидаю! – andrea