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

phate89
1#
phate89 Published in 2017-10-24 07:31:21Z

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:

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

    </Grid>
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO