How to smoothly navigate to a different panorama item

北战南征 提交于 2019-12-07 16:07:03

问题


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?


回答1:


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();



回答2:


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.



来源:https://stackoverflow.com/questions/17980606/how-to-smoothly-navigate-to-a-different-panorama-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!