问题
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