Listview with scrolling background image

2019-07-03 15:06发布

问题:

I am trying to create a ListView that looks like items sitting on a shelf. I am able to get the shelf background on the list view like so:

<ListView.Background>
    <ImageBrush ImageSource="..\Images\bookshelf.png" AlignmentX="Left" AlignmentY="Top" TileMode="Tile" Stretch="None" ViewportUnits="Absolute" Viewport="0,0,319,203" />
</ListView.Background>

but when doing it this way the background is static and doesn't move when the ListView scrolls. I figure I have to add this to the scrollview of the ListView somehow but I'm not sure how.

How do I add an image that tiles and scrolls with the ListView?

回答1:

Instead of setting the background of the ListView, try creating another ScrollViewer which is behind the ListView and contains an image. When the ListView is scrolled, update the ScrollViewer scroll position. This will also allow you to add parallax scrolling if you wanted it.