Ecko Freezy
Ecko Freezy

Reputation: 23

Change Color of a selected Row in a Listview

I want to change the Color of a Listview Row in XAML when I:

  1. Have the Cursor over it
  2. Have the Row selected

I tried many different Solutions I found here in the Forum and also on other websides, but I never found a solution that really changed any of the Color. I just get it to Change the text Color when I select a Item but thats not what I want. Maybe someone can help me, this is my XAML Listview:

<ListView ItemsSource="{Binding Files}" x:Name="listBox2" Margin="269,32,10.286,0" Height="119" VerticalAlignment="Top" Drop="DropEvent" AllowDrop="True">
   <ListView.View>
      <GridView>
         <GridViewColumn 
            DisplayMemberBinding="{Binding Path}"
            Width ="1000"/>
         </GridView>
      </ListView.View>
   </ListView>
</ListView>

Upvotes: 1

Views: 931

Answers (1)

mm8
mm8

Reputation: 169150

You could define an ItemContainerStyle:

<ListView ItemsSource="{Binding Files}" x:Name="listBox2">
    <ListView.View>
        <GridView>
            <GridViewColumn DisplayMemberBinding="{Binding}" Width="1000"/>
        </GridView>
    </ListView.View>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="Green" />
                </Trigger>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="Red" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

Upvotes: 4

Related Questions