'goback'에 해당되는 글 2건

  1. 2013.03.15 [wp8] Navigation Back Back하기
  2. 2012.02.16 [wp7] MessageBox를 띄운 상태에서 Tombstone
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. 16. 17:12

코레일 만드는도중 앱이 꺼졌다 이유를 보니

MessageBox가 띄워져 있는 상태에서  ok를 누르면 프로세서를 타고

cancel을 누르면 navivation.goback()을 하게 되어 잇는데

메세지 박스가 띄워져 있는 상태에서 tombtone을 하게 되면

cancel 된 분기문으로 가게 되어 있는데

거기에서 navigation.goback()부분에서 에러가 나는거였다.

그래서 혹시 goback()을 하기전에 이걸 체크하는게 있나 싶었는데 없었다. cangoback이거는 딴조건인듯

해결법은

bool _isTombstone; //톰스톤인지 아닌지 구분

protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
      {
          base.OnNavigatedFrom(e);
          _isTombstone = true;
      }
 

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
      {
          base.OnNavigatedTo(e);
          _isTombstone = false;

       }

if (MessageBox.Show(msg, string.Empty, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        XmlGroupManager xgmInside = new XmlGroupManager();
                        xgmInside.GetData(um.GetReserveCancelUrl(StaticManager.JrnyInfoModelSelectedItem));
                        xgmInside.xdmCE.CompleteGroupDataEvent += new EventHandler<Events.XmlGroupDataEventArgs>(xdmCE_CompleteGroupDataEvent);
                        xgmInside.xdmCE.errorEvent += new EventHandler<Events.XmlDataEventArgs>(xdmCE_errorEvent);
                    }
                    else
                    {
                        if (_isTombstone == false)
                        {
                            (Application.Current.RootVisual as PhoneApplicationFrame).GoBack();
                        }
                    }

 

이런식으로 해결했다. NavigatedFrom할때 이것이 톰스톤인지 아닌지를 구분해서 goback을 할지 안할지를 구분했다

 

그리고 만약 저런식이 아닌

 

if (e.Error != null)
            {
                (Application.Current.RootVisual as PhoneApplicationFrame).GoBack();
                MessageBox.Show("네트워크를 확인해 주세요.");
                return;
            }

메세지 박스를 띄운후 goback은 절대 하지 말고

먼저 뒤로 가고 메세지 박스를 띄우는게 낫다.

Posted by 동동(이재동)