WPF:从ListViewItem的删除突出显示效果
我正在开发具有日志WPF应用程序。日志设计有ListView控件。该listviewitems当鼠标悬停或项目选择了最没有变化的外观。我已经解决了这种风格对于ListView:
I'm developing a WPF application that has a log. The log is designed with a listView. The listviewitems most not changes appearance when the mouse is over or item is selected. That i have solved with this style for the listview:
<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>
这风格固定我的问题,但提出了一个新的问题。当背景被设置为透明我现在能够看到显示在下面的图片此悬停/镜面效果,当鼠标悬停在列表视图项。
This style fixed my problems but 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 annoying hover effect?
在此先感谢
我不知道这是唯一的解决办法,但我做了如下(通过设置模板
的的ListViewItem
的S属性):
I don't know if this is the only solution but I did it as follows (by setting the Template
property of the ListViewItem
s):
<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>
编辑:
或者格兰特Winney建议(我没有测试自己):
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>