从 ListViewItem 中删除高光效果 [英] Remove Highlight Effect from ListViewItem

查看:33
本文介绍了从 ListViewItem 中删除高光效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ListView 中有 ListviewItems,当鼠标悬停在它们上面或它们被选中时,它们不能改变外观.

In a ListView there are ListviewItems where they must not change appearance when the mouse is over them or they are selected.

我试图用这种风格来实现这一点,并且在某种程度上成功了:

I tried to accomplish that with this style and did somewhat succeed:

<Style x:Key="ItemContainerStyle1" TargetType="ListViewItem">
    <Setter Property="HorizontalContentAlignment" Value="Left"/>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Focusable" Value="False" />
        </Trigger>
    </Style.Triggers>
</Style>

但是它提出了一个新问题.当背景设置为透明"时,当鼠标悬停在列表视图项上时,我现在可以看到下图所示的悬停/光泽效果.

But the it raised a new issue. When the background is set to "Transparent" I am now able to see this hover/glossy effect that is shown at the picture below, when the mouse is over a list view item.

我试图通过这次尝试解决问题,但没有成功.

I have tried to solve the problem with this attempt, but with no luck.

<Style TargetType="{x:Type ListViewItem}">
    <Style.Resources>
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#00000000"/>
      <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#00000000"/>
    </Style.Resources>
</Style>

有人知道如何去除这种悬停效果吗?

Anyone have an idea how to remove this hover effect?

推荐答案

我不知道这是否是唯一的解决方案,但我这样做了如下(通过设置 Template 属性的 Template代码>ListViewItems):

I don't know if this is the only solution but I did it as follows (by setting the Template property of the ListViewItems):

<ListView.ItemContainerStyle>
    <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>
</ListView.ItemContainerStyle>

<小时>

或者正如格兰特温尼所建议的那样(我自己没有测试过):

Or as Grant Winney suggests (I did not test that myself):

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListViewItem}">
                    <ContentPresenter />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ListView.ItemContainerStyle>

这篇关于从 ListViewItem 中删除高光效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆