Having an outline for MouseOver for a WPF ListView
I am using Windows 7 and the current item selection (by default) is to paint the background with cornflower blue. Is it possible to get rid of this and replace it with a 1px outline/border over the listview 开发者_JAVA百科item that the mouse is over?
I basically want to draw a 1px outline/border over any listview item with 1 pixel spacing between the listview item and the outline/border.
I am using a WrapPanel with an Image in it for each item.
Use ItemContainerStyle to override the default background behaviour, and in your style, use a trigger on IsMouseOver to show your outline (for example by having a Setter for BorderThickness).
EDIT: Rough example (not tested):
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="White" BorderThickness="5" Name="Bd">
<Border.Style>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="White" />
</Style>
</Border.Style>
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="BorderBrush" Value="HotPink" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
精彩评论