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.