4

I have a LongListSelector in a Windows Phone Application.
Each item has a picture and a text.
I want to use two different ItemTemplates for them alternatively.
The first one to have the picture on the right and the text on the left, the 2nd one the picture on the left and text on the right and so on.

I tried to use the loaded event to set the template for each item, but for a large number of data (over 10-15) items they don't load in the same order as they appear in the list.
How can I do it other way?

csharpwinphonexaml
  • 3,659
  • 10
  • 32
  • 63
Dacian Mujdar
  • 585
  • 2
  • 17

1 Answers1

0

The thing you're looking for is known as a DataTemplate selector. The best place to start (since you didn't share anything that you've tried) would be to search for that term online, or to look at one of the following resources:

The main idea of the DataTemplate selector is very simple - choose which DataTemplate to apply depending on a certain criteria. In your case it's based on index of item in the list, in some other case it may be the type of the data used for binding (you want to show more details if item is of type 'Car', and less details if item is of type 'Skateboard' because skateboards are (usually) less complex than cars and have less properties and details) etc.

Community
  • 1
  • 1
Igor Ralic
  • 14,975
  • 4
  • 43
  • 51