Home Customize Listview Selected item and hover item background based on property
Reply: 0

Customize Listview Selected item and hover item background based on property

user4308 Published in July 17, 2018, 7:58 am

I'm using a listview to display the status of an observable list of objects customizing the background according to a property of the object. I managed to customize the background of a listview item with triggers but once I select a item or move the cursor in it it's gone. What I'd like to do is to change the color once I select an item but it should be dependent on a property value too like the background is with triggers. Here's my current status:

        <ListView Name="lvDataBinding" ItemsSource="{Binding List}" HorizontalAlignment="Stretch">
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <DataTrigger Binding="{Binding Stato}" Value="Caricato">
                            <Setter Property="Background" Value="#FF82CA9D" />
                        <DataTrigger Binding="{Binding Stato}" Value="Errore">
                            <Setter Property="Background" Value="#FFF7977A" />
                        <DataTrigger Binding="{Binding Stato}" Value="InCoda">
                            <Setter Property="Background" Value="#FFF79A" />
                    <Grid HorizontalAlignment="Stretch" Width="Auto">
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        <WrapPanel Grid.Column="0" Grid.Row="0" Margin="3">
                            <TextBlock Text="Nome: " />
                            <TextBlock Text="{Binding Name}" FontWeight="Bold" />
                        <WrapPanel Grid.Column="1" Grid.Row="0" Margin="3">
                            <TextBlock Text="ID tessera: " />
                            <TextBlock Text="{Binding ID}" FontWeight="Bold" />
                        <WrapPanel Grid.Column="2"  Grid.Row="0" Margin="3" HorizontalAlignment="Right">
                            <TextBlock Text="Stato: " />
                            <TextBlock Text="{Binding StatoString}" FontWeight="Bold" />
                        <WrapPanel Grid.Column="0" Grid.Row="1"  Margin="3">
                            <TextBlock Text="Data: " />
                            <TextBlock Text="{Binding Time}" FontWeight="Bold" />
                        <WrapPanel Grid.Column="1" Grid.Row="1" Margin="3">
                            <TextBlock Text="N. Documento: " />
                            <TextBlock Text="{Binding Number}" FontWeight="Bold" />
                        <WrapPanel Grid.Column="2" Grid.Row="1" HorizontalAlignment="Right" Margin="3">
                            <TextBlock Text="Cassa: " />
                            <TextBlock Text="{Binding Position}" FontWeight="Bold" />

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.344454 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO