How to set the selecteditem background color in List View (.net MUAI)

Sowndarrajan Vijayaragavan 450 Reputation points
2023-05-02T07:24:02.4966667+00:00

How to set the selecteditem background color in List View (.net MUAI)

Developer technologies | .NET | .NET MAUI
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-05-02T09:44:01.41+00:00

    Hello,

    There is a known issue reported at GitHub- Android: ListView Item selected color is by default Orange and no property available to change this color #13812, please follow the progress.

    And there is a workaround for iOS and Android at GitHub, you have to customize the ViewCell with Microsoft.Maui.Controls.Handlers.Compatibility.ViewCellRenderer, then overwrite the iOS and Android native methods to set the background color for the cell.

    Please refer to Customizing a ViewCell - Xamarin | Microsoft Learn

    and Reuse custom renderers in .NET MAUI - .NET MAUI | Microsoft Learn

    In addition, it's recommended that you try to use CollectionView instead of ListView, and change selected item color.


    Update

    Windows platform is based on WinUI, you could try to open App.xaml under Platforms/Windows folder, then modify the default resource.

    <maui:MauiWinUIApplication ......>
        <maui:MauiWinUIApplication.Resources>
            <ResourceDictionary>
                <SolidColorBrush x:Key="ListViewItemBackgroundSelected" Color="#Ff0000" />
                <SolidColorBrush x:Key="ListViewItemBackgroundSelectedPointerOver" Color="#Ff0000" />
                <SolidColorBrush x:Key="ListViewItemBackgroundSelectedPressed" Color="#Ff0000" />
                <SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="#Ff0000" />
            </ResourceDictionary>
        </maui:MauiWinUIApplication.Resources>
    </maui:MauiWinUIApplication>
    

    For more styles, you can see the WinUI source code: ListViewItem_themeresources.xaml

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.