navigation 에서는 goback을 두번해야 할떄가 있다…
여러가지 방법이 있겠지만 효율적인 방법을 소개~
바로 stack 에 있는 엔트리를 remove해서 back 하는 방법이다.
public class NavigationHelper
{
public static PhoneApplicationFrame RootFrame
{
get
{
if (App.Current.RootVisual is PhoneApplicationFrame)
{
return App.Current.RootVisual as PhoneApplicationFrame;
}
return null;
}
}
public static void Navigate(string url)
{
if (GlobalStates.Instance.IsLogging)
return;
if (url.Contains("http://"))
{
var asy = Launcher.LaunchUriAsync(new Uri(url, UriKind.Absolute));
}
else
{
RootFrame.Tag = null;
RootFrame.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
}
}
public static void Navigate(string url, object parameter)
{
RootFrame.Tag = parameter;
RootFrame.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
}
public static void GoBack()
{
if (RootFrame.CanGoBack != false)
{
try
{
RootFrame.Dispatcher.BeginInvoke(() =>
{
RootFrame.GoBack();
});
}
catch
{ }
}
else
{
if (RootFrame.CanGoForward)
{
RootFrame.Navigate(new Uri("/Views/HubPages/HubPage.xaml", UriKind.RelativeOrAbsolute));
}
System.Diagnostics.Debug.Assert(false);
}
}
public static int BackEntryCount()
{
return RootFrame.BackStack.Count();
}
public static void RemoveBackEntryLatest()
{
if (RootFrame.CanGoBack != false)
{
RootFrame.RemoveBackEntry();
}
}
public static void RemoveBackEntry(int removeCount)
{
for (int i = 0; i < removeCount; i++)
{
if (RootFrame.CanGoBack == false)
{
goto finalizing;
}
RemoveBackEntryLatest();
}
finalizing:
return;
}
public static void RemoveBackEntryAll()
{
RemoveBackEntry(RootFrame.BackStack.Count());
}
public static void DumpBackEntryAll()
{
#if DEBUG
int i = 0;
foreach (JournalEntry entry in RootFrame.BackStack)
{
if (entry == null)
{
continue;
}
LogHelper.Debug("BackStack: entry[{0}]={1}", i, entry.Source);
i++;
}
#endif
}
public static void GoHome()
{
RootFrame.Navigate(new Uri("/Views/HubPages/HubPage.xaml", UriKind.RelativeOrAbsolute));
//if (RootFrame.CanGoBack)
//{
// NavigatedEventHandler handler = null;
// handler = delegate
// {
// RootFrame.Navigated -= handler;
// GoHome();
// };
// RootFrame.Navigated += handler;
// RootFrame.GoBack();
//}
//else if (RootFrame.CurrentSource.OriginalString.Contains("/HubPage.xaml") == false)
//{
// RootFrame.Navigate(new Uri("/Views/HubPages/HubPage.xaml", UriKind.RelativeOrAbsolute));
//}
}
internal static void GoToLogin()
{
NavigationHelper.Navigate(PageUrls.Login);
}
}
이건 navigationHelper class이고
실제는
NavigationHelper.RemoveBackEntryLatest();
NavigationHelper.GoBack();
이렇게 사용하면 된다.
'Windows Phone 8' 카테고리의 다른 글
the activation request failed with error 가 뜨면서 실행이 안될때 (0) | 2013.05.07 |
---|---|
[WP8] List Reserve 거꾸로 정렬 (0) | 2013.03.04 |
[wp8] wp8에서 파일 읽고 쓰기 (0) | 2012.12.10 |
[wp8] ViewModel에서 Applicaionbar를 변경해보자. (0) | 2012.12.06 |
[wp8] Generic 형식 전역(global)에서 사용하기 (0) | 2012.10.18 |