Johan Danforth
Johan Danforth

Reputation: 4579

Programmatically slide to next Panorama item

Is it possible to programmatically move from one panorama page/item to the next and get the same kind of animated sliding effect you get when sliding with a finger?

I can use the PanoramaControl.DefaultItem property to move to the expected item/page, but you won't get the animated sliding effect. Any ideas here?

Upvotes: 5

Views: 8480

Answers (5)

Herman van der Blom
Herman van der Blom

Reputation: 131

Its possible, just put the setting of the DefaultItem between a SlideTransition Completed event and you are done:

public static class PanoramaExtensions
{
    public static void SlideToPage(this Panorama self, int item)
    {

        var slide_transition = new SlideTransition() { };
        slide_transition.Mode = SlideTransitionMode.SlideLeftFadeIn;
        ITransition transition = slide_transition.GetTransition(self);
        transition.Completed += delegate
        {
            self.DefaultItem = self.Items[item];
            transition.Stop();
        };
        transition.Begin();
    }
}

Use my_panorama.SlideToPage(1) to slide to the second page.

Upvotes: 13

Blounty
Blounty

Reputation: 3358

it is not programatically possible to change the selected index of a panorama control. As you mention the only way of setting the index is using the DefaultItem property which is only useful when navigationg to the page which contains the panorama.

Here is another post that discusses it.

Upvotes: 1

Sajjan Kumar
Sajjan Kumar

Reputation: 61

You can use below code :

panoramaRoot.DefaultItem = (PanoramaItem)panoramaRoot.Items[1];

Upvotes: 6

Stuart
Stuart

Reputation: 66882

No - the panorama control doesn't support programmatic manipulation like this.

If you want an experience like this, then you could try a hand-written panorama control - e.g. http://phone.codeplex.com/

Upvotes: 1

Derek Lakin
Derek Lakin

Reputation: 16319

I think the easiest way to achieve this would be to create separate visual states for each item and create animated slide transitions for transitioning to each state. Then you can use VisualStateManager.GoToState(<page>, <state>, true); to initiate the state change.

Upvotes: 1

Related Questions