1

최종 업데이트에게 가기 backstack에게COMException 내가 문제를 발견했습니다

를 조작하면서. 그것은 백 스택 조작과 아무 관련이 없습니다. 원인은 제가 올바르게 등록하지 않은 리소스 사전이었습니다.


저는 Windows Phone 8.1 App을 작성하고 있습니다. MVVMcross를 사용하고 있기 때문에 ViewModels가 포함 된 이식 가능한 프로젝트와 Views가 포함 된 Windows Phone 8.1 프로젝트를 사용합니다.

일부 경우 백 스택에서 페이지를 제거하여 백본을 클릭 할 때 제거 된 페이지 이전 페이지가 표시되도록하려는 경우가 있습니다.

내가 혼자 예를 따랐이 동작을 달성하기 https://edsnider.net/2014/04/07/clearing-windows-phone-nav-back-stack-in-mvvmcross/

모든 것은 내가 응용 프로그램에있어 다시 응용 프로그램을 다시하는 동안 완전한 재시작을 할 경우를 제외하고 잘 작동합니다. 이 경우 배 스택 조작을 수행 할 때 COM 예외가 발생합니다.

The operation identifier is not valid. 
The BackStack or ForwardStack cannot be changed while navigating. 

질문 : 코드가 잘못되었습니다.

메소드 DropPageAndShowViewModel가 내 ViewModels의 기본 클래스에 정의되어 있습니다 : 여기

는 관련 코드 조각입니다. 이 예외를 ViewModel에서 호출하면 예외가 발생합니다.

DropPageAndShowViewModel<TourdatenSummaryViewModel>(
    new TourdatenSummaryViewModel.NavObject 
    { 
     Tournummer = _tour.Nummer 
    }); 

내 ViewModels의 기본 클래스입니다. BaseViewModel은 MvxViewModel에서 파생됩니다. 내가 웹에서이 COM 예외에 대한 하나의 참조를 찾았지만 나에게 도움이되지 않았습니다

public class DropCurrentBackStackEntryHint : MvxPresentationHint 
{ 
} 


public class CustomViewPresenter : MvxWindowsViewPresenter 
{ 
    private readonly IMvxWindowsFrame _rootFrame; 

    public CustomViewPresenter(IMvxWindowsFrame rootFrame) : base(rootFrame) 
    { 
     _rootFrame = rootFrame; 
    } 

    protected Frame RootFrame 
    { 
     get { return (Frame) _rootFrame.UnderlyingControl; } 
    } 

    public override void ChangePresentation(MvxPresentationHint hint) 
    { 
     if (hint is DropCurrentBackStackEntryHint) 
     { 
      if (RootFrame.BackStack.Any()) 
      { 
       RootFrame.BackStack.RemoveAt(RootFrame.BackStackDepth - 1); 
      } 
     } 
     base.ChangePresentation(hint); 
    } 
} 

: https://github.com/Windows-XAML/Template10/issues/454

public class BasePageViewModel : BaseViewModel 
{ 
    ... 

    protected void DropPageAndShowViewModel<TViewModel>() 
     where TViewModel : BasePageViewModel 
    { 
     ShowViewModel<TViewModel>(); 
     ChangePresentation(new DropCurrentBackStackEntryHint()); 
    } 

    protected void DropPageAndShowViewModel<TViewModel>(object parameterValuesObject) 
     where TViewModel : BasePageViewModel 
    { 
     ShowViewModel<TViewModel>(parameterValuesObject); 
     ChangePresentation(new DropCurrentBackStackEntryHint()); 
    } 
} 

IT는 가기 backstack 조작을 수행하는 CustomViewPresenter입니다 업데이트

나는 처리되지 않은 예외를 이 핸들러 :

void App_UnhandledException(object sender, UnhandledExceptionEventArgs e) 
{ 
    if (Debugger.IsAttached) 
     Debugger.Break(); 

    e.Handled = true; 

    var message = "Error: \n\n" + 
     e.Message + "\n\n" + 
     e.Exception.HResult + "\n\n" + 
     e.Exception.Message + "\n\n" + 
     e.Exception.StackTrace; 

    new MessageDialog(message).ShowAsync(); 
} 

예외가 나는이 텍스트를 얻을 발생합니다 :

The operation identifier is not valid. 

The BackStack or ForwardStack cannot be changed while navigating. 

-2147020579 

The operation identifier is not valid. (Exception from HRESULT: 0x800710DD) 

HRESULT 코드도 도와 수행합니다

C:\> err 0x800710DD 
# as an HRESULT: Severity: FAILURE (1), Facility: 0x7, Code 0x10dd 
# for hex 0x10dd/decimal 4317 : 
    ERROR_INVALID_OPERATION          winerror.h 
# The operation identifier is not valid. 
# 1 matches found for "0x800710DD" 

업데이트 2

앱이 출시 모드로 제작 된 경우에만 예외가 발생합니다. 디버그 모드에서는 발생하지 않습니다. 그리고 난 장치를 다시 시작해야 효과가 있습니다.

+0

나는 비슷한 것을 보았습니다. 제 경우에는 Bing 맵이 릴리즈되지 않고 COMException이 발생했습니다. – Cheesebaron

+0

"탐색하는 동안 BackStack 또는 ForwardStack을 변경할 수 없습니다." 너에게 충분한 징조를 줘? – Cheesebaron

+0

아니요, 충분하지 않습니다! 나에게 힌트를 줄 수 있니? – Olaf

답변

0

문제는 당신이 이것을 부르는 방식이라고 생각합니다. 처음에는 ShowViewModel을 호출 한 다음 스택에서 페이지를 제거하려고합니다. 그리고 릴리스 모드에서는 동시에 호출되므로이 메시지가 표시됩니다.

public override void ChangePresentation(MvxPresentationHint hint) 
{ 
    ... 

    if (hint is DropCurrentBackStackEntryHint) 
    { 
     var dropHint = (DropCurrentBackStackEntryHint) hint; 
     var nativeView = Mvx.Resolve<IMvxViewsContainer>().GetViewType(dropHint.ViewModelType); 

     RootFrame.Navigate(nativeView, null); 

     // Perhaps you need here a await Task.Delay(200); here. You have to test the value 

     if (RootFrame.BackStack.Any() && RootFrame.BackStack.Count > 1) 
     { 
      RootFrame.BackStack.RemoveAt(RootFrame.BackStackDepth - 2); 
     } 
    } 

    ... 
} 

타 솔루션, 그리 좋은 방법 : 당신은 항상 당신이이 페이지를 탐색 할 때, 스택에서 마지막 페이지를 삭제할 때 , 당신은 할 수

public class DropCurrentBackStackEntryHint : MvxPresentationHint 
{ 
    public Type ViewModelType; 

    public DropCurrentBackStackEntryHint(Type viewModelType) 
    { 
     ViewModelType = viewModelType; 
    } 
} 

그리고 당신의 발표자에

보기의 코드 뒤에있는 백 스택에서 마지막 페이지를 삭제하십시오.

public partial class XyzView 
{ 
... 
protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 

    if(Frame.BackStack.Any() && Frame.BackStack.Count > 1) 
     Frame.BackStack.RemoveAt(Frame.BackStackDepth - 2); 
} 
... 
} 
관련 문제