How to smoothly navigate to a different panorama i

2019-05-11 23:14发布

In a panorama application, I have added a couple of situations where the user is navigated back to a certain panorama item. However this is done in one sudden movement. Is there a way I can do this action more smoothly, with some form of transition? Or something of the like?

2条回答
我只想做你的唯一
2楼-- · 2019-05-11 23:52

From Inder Kumar Rathore's answer and answers in this page I've come to do this:

    #region navigation
    public enum MainPanoramaItem
    {
        None = -1, Mag, Scan, Account, Lists, More, Help, MainPanoramaItemCount
    }
    public void PanoramaNavigateTo(MainPanoramaItemitem)
    {
        int count = (int)MainPanoramaItem.MainPanoramaItemCount;
        int toPosition = (int)item;
        int nowPosition = panorama.SelectedIndex;
        bool left = false;
        if(nowPosition > toPosition){
            int rightDelta = count - nowPosition + toPosition;
            int leftDelta = nowPosition - toPosition;
            left = rightDelta > leftDelta;
        } else {
            int leftDelta = count - nowPosition + toPosition;
            int rightDelta = nowPosition - toPosition;
            left = rightDelta > leftDelta;
        }

        SlideTransition slideTransition = new SlideTransition();
        slideTransition.Mode = left ? SlideTransitionMode.SlideLeftFadeOut : SlideTransitionMode.SlideRightFadeOut;
        ITransition transition = slideTransition.GetTransition(panorama);
        transition.Completed += delegate
        {
            transition.Stop();
            SlideTransition slideTransitionIn = new SlideTransition();
            slideTransitionIn.Mode = left ? SlideTransitionMode.SlideLeftFadeIn : SlideTransitionMode.SlideRightFadeIn;
            ITransition transitionIn = slideTransitionIn.GetTransition(panorama);
            transitionIn.Completed += delegate { transitionIn.Stop(); };

            panorama.SetValue(Panorama.SelectedItemProperty, panorama.Items[(int)item]);
            Panorama temp = panorama;
            LayoutRoot.Children.Remove(panorama);
            LayoutRoot.Children.Add(temp);
            LayoutRoot.UpdateLayout();

            transitionIn.Begin();
        };
        transition.Begin();
    }

    protected override void OnBackKeyPress(CancelEventArgs e)
    {
        if (panorama.DefaultItem != panorama.Items[(int)PanoramaItem.Mag])
        {
            PanoramaNavigateTo(PanoramaItem.Mag);
            e.Cancel = true;
        }
    }
    #endregion

in MainPage.xaml.cs It uses fade out and then fade in AND keeps the title of the panorama at it's original place. I'm not sure yet how it reacts with a real application since mine is quite empty.

查看更多
我命由我不由天
3楼-- · 2019-05-12 00:08

This code worked for me

SlideTransition slideTransition = new SlideTransition();
slideTransition.Mode = SlideTransitionMode.SlideRightFadeIn;
ITransition transition = slideTransition.GetTransition(panorama_main);
transition.Completed += delegate
{
    transition.Stop();
};
PanoramaItem pItem = (PanoramaItem)panorama_main.Items[3];
panorama_main.DefaultItem = pItem; 
transition.Begin();
查看更多
登录 后发表回答