0

I am trying to set the background color of the selected item in a ListView.

I have tried the following code but the default colors are still being shown.

I don't understand what is wrong. Does anyone have any ideas?

<ListView x:Name="videosListView">
    <ListView.Style>
        <Style TargetType="{x:Type ListView}">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue"/>
            </Style.Resources>
        </Style>
    </ListView.Style>

    <ListView.ItemTemplate>
        <DataTemplate>
            <GroupBox x:Name="headerGroupBox" Margin="0" 
                      Header="Title/Series" Foreground="Red" 
                      FontWeight="DemiBold">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <TextBlock x:Name="titleTextBox" Grid.Row="0"
                               Text="{Binding Title}"
                               Foreground="RoyalBlue"
                               FontSize="20" FontWeight="Bold"/>
                    <TextBlock x:Name="seriesTextBox" Grid.Row="1"
                               Text="{Binding SeriesName}" 
                               Foreground="DarkCyan" FontSize="15"/>
                </Grid>
            </GroupBox>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
PeterG629
  • 1
  • 1
  • Have you checked this out? https://stackoverflow.com/questions/895309/listview-selection-color – Gerrit May 30 '19 at 20:33
  • Thanks for the link. I looked at it but it does not address my issue. it puts a border around the ListViewItem but the background color I wish to apply on selection of an item is still being overriden by the ListView default color. – PeterG629 May 30 '19 at 21:04
  • 1
    This actually works fine on Windows 7... to be compatible with multiple OS versions, I believe you may have better luck overriding the control template of the ListViewItem. This other post may be of some assistance: https://stackoverflow.com/questions/35804844/wpf-listbox-highlight-in-windows-10 – Mash May 31 '19 at 00:25
  • Thanks for the link. This worked fine. – PeterG629 May 31 '19 at 14:19

0 Answers0