Search code examples
c#xamlxamarinxamarin.formsbackground-image

How do I add a BackgroundImage to a ListView in Xamarin Forms?


I am aware that there is no property called BackgroundImage for the ListView class - only the BackgroundColor property but that is not what I am looking for. Is there a way to add a background image to the ListView so that when I scroll the image stays in place and the tiles simply 'move' over the image as you scroll.

Adding the image to the ContentPage also does not work since the ListView simply overlays it.


Solution

  • Your post is really good, you just miss a doble quotations marks on the Source property

    Set your ListView's BackgroundColor to Transparent:

    <RelativeLayout>
        <Image Source="background.png" 
            BackgroundColor="Transparent" 
            VerticalOptions="CenterAndExpand" 
            HorizontalOptions="CenterAndExpand"/>
        <ListView x:Name="listView" 
            VerticalOptions="CenterAndExpand"
            HorizontalOptions="CenterAndExpand"
            BackgroundColor="Transparent"
                  ItemTapped="OnItemTapped"
                  ItemsSource="{Binding .}" />
    </RelativeLayout>