locked
controlling the pivot item in pivot RRS feed

  • Question

  • I want to control that , which pivot item to be displayed first when the application starts...??
    Monday, January 30, 2012 6:18 PM

Answers

  • You can do it in either file. If you do it in xaml, then that will be set on page load, if you don't change it in any Load events. But if you want to programatically control when the page is loaded, then you should do it in PivotControl_Loaded event. But as this event fires after control is initialized, you may first see the default pivot item, as set in xaml, and then changed to the required one.

    private void pivotControl_Loaded (object sender, RoutedEventArgs e)  
    {  
      ...  
     
      pivotControl.SelectedIndex = selectedPivotItemIndex;  
     
      ...  
    }  
     
    Monday, January 30, 2012 7:19 PM

All replies

  • Set the Pivot control's SelectedIndex property.
    Monday, January 30, 2012 6:29 PM
  • can you give the code please. where i should use it, means in .xaml or .cs file..??
    Monday, January 30, 2012 6:35 PM
  • You can do it in either file. If you do it in xaml, then that will be set on page load, if you don't change it in any Load events. But if you want to programatically control when the page is loaded, then you should do it in PivotControl_Loaded event. But as this event fires after control is initialized, you may first see the default pivot item, as set in xaml, and then changed to the required one.

    private void pivotControl_Loaded (object sender, RoutedEventArgs e)  
    {  
      ...  
     
      pivotControl.SelectedIndex = selectedPivotItemIndex;  
     
      ...  
    }  
     
    Monday, January 30, 2012 7:19 PM
  • Thank You very much..!!
    Monday, January 30, 2012 7:21 PM
  • One word of warning if you are changing the pages on the page load.  I have not tested this with Mango and the 7.1 development kit, but in the previous versions, only the first, second, and last pivot items were loaded when the page_loaded event was hit and to pivot to any other control, I had to increment or decrement the index to get to the one I wanted.  I have not test this with 7.1 and Mango yet.
    Monday, January 30, 2012 9:10 PM
  • SelectedItem is working fine but SelectedIndex is Showing the "ArgumentException was Unhandled" with a new dialog box..??
    Monday, January 30, 2012 11:34 PM