Prashant Cholachagudda
Prashant Cholachagudda

Reputation: 13090

How to use Pivot Effectively?

I have following data structure in my WP7 app. And I'm generating three PivotItems through databinding, contents of binding. Interesting part is when Binding happens for Pivot items contents(Items) are queried for three time and again selection changes.

Is there anything I'm doing wrong?

Code:

<controls:Pivot Title="{StaticResource ApplicationName}" ItemsSource="{Binding Folders}" SelectedItem="{Binding SelectedFolder, Mode=TwoWay}" Name="_pivot">
    <controls:Pivot.ItemTemplate>
        <DataTemplate>
            <ListBox DataContext="{Binding Source={StaticResource Locator}}" ItemsSource="{Binding ThingsListViewModel.Items}"  />
        </DataTemplate>
    </controls:Pivot.ItemTemplate>

I have three folders items, when Pivot control is created ThingsListViewModel.Items property executed thrice, and once every time selection changes.

I'm expecting ThingsListViewModel.Items to execute only selection chage on Pivot control.

Upvotes: 1

Views: 828

Answers (1)

Ade A
Ade A

Reputation: 146

I think you need to listen to the LoadedPivotItem and Loaded events of the pivot. The Loaded event will always load the first PivotItem (LoadedPivotItem) will not be called. The LoadedPivotItem is called when the user swipes to another PivotItem.

Based on these events you should then run your queries for the currently SelectedPage. You may also want a flag to indicate once you have loaded the data for each Pivot to avoid running the queries again.

Upvotes: 3

Related Questions