Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which method/function is called during PivotItem navigation WP7

I am just getting started on Windows phone 7 development and am stuck at this problem while using Pivot control:

I have 3 pivotitems and the swipe movement to navigate between pivots are working fabulously well, But the problem is...

I need to call a different function, say function1() when one pivotitem is visible and then call a function say function2() as soon as user swipes to another pivotitem.

Is there any delegate method which handles this..?

Thanks for your help!

like image 900
ChethanRao Avatar asked Jun 15 '11 11:06

ChethanRao


2 Answers

You can handle the Pivot control's LoadingPivotItem event. This event passes PivotItemEventArgs which includes a property letting you know what pivot is about to be shown. Using this, you can then load the relevant controls and properties. For example,

private void pivotMain_LoadingPivotItem(object sender, PivotItemEventArgs e)
{
      if (e.Item == pivotItem1)
      {
          //Load Pivot Item 1 stuff
      }

      if (e.Item == pivotItem2)
      {
          //Load Pivot Item 2 stuff      
      }
}

In the example above, pivotItem1 and pivotItem2 are the names I've given each PivotItem so you can give whatever names you want to each PivotItem and check if they're about to be shown. If you want to handle the event after the PivotItem has loaded, you can use the Pivot.LoadedPivotItem method.

If you want to know which PivotItem is currently being displayed at any time, you can use the Pivot.SelectedIndex method. It's zero-based, so the first PivotItem will have an index of 0, the second will have 1 and so on.

like image 126
keyboardP Avatar answered Oct 27 '22 16:10

keyboardP


You can use SelectionChanged. In this function you'll be able to check to see which PivotItem is the SelectedItem and choose which function you want to call.

like image 20
Mark Synowiec Avatar answered Oct 27 '22 15:10

Mark Synowiec