Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I apply a style to the ListViewItems in WPF?

First of all, I am new to WPF.


I have this style ready for my items:

    <Style x:Key="lvItemHover" TargetType="{x:Type ListViewItem}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Foreground" Value="Black" />
            </Trigger>
        </Style.Triggers>
    </Style>

How do I give this style to the items in my ListView?

like image 301
Vercas Avatar asked Mar 22 '11 10:03

Vercas


1 Answers

Try this

     <ListView x:Name="listView">
        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
               <Style.Triggers>
                  <Trigger Property="IsMouseOver" Value="true">
                     <Setter Property="Foreground" Value="Black" />
                  </Trigger>
               </Style.Triggers>
            </Style>
        </ListView.ItemContainerStyle>
        <ListViewItem>Item1</ListViewItem>
        <ListViewItem>Item2</ListViewItem>
        <ListViewItem>Item3</ListViewItem>
    </ListView>
like image 124
Stecya Avatar answered Oct 20 '22 04:10

Stecya