How to perform any action on pivot change(on pivot page swipe) | Techbirds

Hi all,

To perform any action on swiping a pivot page just write the code inside Pivot selection change event.
For example if I have to enable or disable an app bar button on pivot change, I want button[2] to be disabled when we navigate on pivot page index 2.

private void pivotecontrol_SelectionChanged(object sender, SelectionChangedEventArgs e) { Pivot pivot = sender as Pivot; if (pivot == null) { return; } switch (pivot.SelectedIndex) { case 0: ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = true; break; case 1: ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = true; break; case 2: ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = false; break; case 3: ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = false; break; } }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

private void pivotecontrol_SelectionChanged(object sender, SelectionChangedEventArgs e)

        {

            Pivot pivot = sender as Pivot;

            if (pivot == null)

            {

                return;

            }

            switch (pivot.SelectedIndex)

            {

                case 0:

                    ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = true;

                    break;

                case 1:

                    ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = true;

                    break;

                case 2:

                    ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = false;

                    break;

                case 3:

                    ((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IsEnabled = false;

                    break;

            }

        }

It will disable the app bar button[2] whenever the pivot 2 is selected.

1,000 total views, 1 views today

Share this Onfacebook-4204222twitter-9324835linkedin-2356803google-6805142