Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to change background color of selected item in a listview on xamarin form?

$
0
0

Hello,

I have ListView like this

     <StackLayout Spacing="0">
        <ListView x:Name="lvMenu" SeparatorColor="Green">
          <ListView.ItemTemplate>
            <DataTemplate>
              <ViewCell>
                <StackLayout Padding="10">
                  <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" Text="{Binding Title}" TextColor="#03a9f4" />
                </StackLayout>
              </ViewCell>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>
      </StackLayout>

Also have ItemSelected event handler like this

    lvMenu.ItemSelected += GotoPage;
    private void GotoPage(object sender, SelectedItemChangedEventArgs e)
    {
        var item = e.SelectedItem as MasterPageItem;
        if (item != null)
        {
            //Change bg
            if (item.Title == "Logout")
            {
                LogoutUser();
            }
            else
            {
                NavigationPage nPage = new NavigationPage((Page)Activator.CreateInstance(item.TargetType)) {
                    Title = item.Title
                };
                this.Detail = nPage;
                this.IsPresented = false;
            }
        }
    }
    public class MasterPageItem
    {
        public string Title { get; set; }
        public Type TargetType { get; set; }
    }

Can anyone suggest how to change the selected item's default background color?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>