YosiFZ
YosiFZ

Reputation: 7900

LongListSelector with two ItemTemplate

I use this code to add ListBox to my app:

<phone:LongListSelector x:Name="searchList" Margin="0,72,0,0" SelectionChanged="DidPressSelectSearchList">
            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="0,20,0,0">
                        <TextBlock Text="{Binding}" FontSize="25" />
                    </StackPanel>
                </DataTemplate>
            </phone:LongListSelector.ItemTemplate>
        </phone:LongListSelector>

Now my issue is that i want to use two kind of ItemTemplate, because there is two ways i show data to the user:

1) Array of Strings

2) Array of objects(2 Strings)

Any help how i can use the list to show two kind of objects?

Upvotes: 0

Views: 1407

Answers (1)

Silver Solver
Silver Solver

Reputation: 2320

The easiest way to do this in WP7 is with a Template Selector. Like this one

Though I cant test it right now, WP8 should support the DataType property on the DataTemplate class, which means you can define implicit Data Templates for each data type and skip the selector altogether.

Upvotes: 1

Related Questions