Windows Phone 82013. 3. 15. 12:10

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

 

이렇게 사용하면 된다.

Posted by 동동(이재동)
Windows Phone 72012. 2. 3. 17:22

그렇다. 버그인지는 모르겟다. 두번 들어온다.

그럴때는 TextBoxChanged 이벤트보다는 KeyUp,Down 이벤트를 활용하자.

Posted by 동동(이재동)