views:

232

answers:

1

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 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.

+2  A: 

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>
itowlson
Thanks. I am very new to WPF. Can you show me a small sample? Or maybe a link?
Joan Venge
Rough example added. You may need to experiment a bit to get the exact effect you want, but hopefully this will get you on the right track.
itowlson
Thanks I replaced ListBox with ListView but it says before compiling "the type Setter does not support direct content".
Joan Venge
It outlines everything from ControlTemplate.
Joan Venge
Sorry, forgot the Setter.Value element. Updated.
itowlson