private void OnPivotSelectionChanged(object sender, SelectionChangedEventArgs e)
{
PivotItem pivotItem = e.AddedItems[0] as PivotItem;
this.viewModel.ProcessPivotSelectionChange(pivotItem, this.favoritesListView,
this.favoritesNoItems);
/* If this is the first time this function is called, the pivot is hidden so
* that we will be able to navigate to the desired pivot
* item before showing the pivot control.
* However, the header animation does not always complete before the pivot is shown.
* To compensate for this, if we are not going to the default pivot page, we will
* enable a layout event handler on the pivot that will be called as the header
* animation progresses. A Background thread will monitor the updates, and on the
* last update, will wait some time, and then display the pivot
*/
if (this.pivot.Opacity != 1)
{
if (this.requestedPivotDataSelectionIndex != 1)
{
Dispatcher.BeginInvoke(() =>
{
this.pivot.LayoutUpdated += new EventHandler(pivot_LayoutUpdated);
this.worker.RunWorkerAsync(null);
});
}
else
{
this.pivot.Opacity = 1;
}
}
}