내 MVVM 기반 WPF 응용 프로그램의 viewModel에서 서로 다른 두 가지 상태에서 두 개의 다른 취소 클릭을 처리하는 두 개의 명령이 있습니다.전역 X 닫기 버튼에서 viewModel에 정의 된 호출 메서드
- 진행중인 작업 진행이없는 경우 -
view.close()
메서드를 중계합니다. - 진행 상황이 진행 중일 때 진행 확인 콜백에
cancelWaiting = true
을 중계합니다. 그러면 취소 확인 메시지 상자를 가져 오는 동안 진행을 일시 중지하고 예/아니요에 따라 취소하거나 계속합니다.
이 두 명령에는 두 상태에 따라 해결되는 canExecute 속성이 있습니다.
나는 두 개의 명령을 캡슐화하는 (동일한 viewModel에서) 새 메서드를 만들었습니다. 이제 전역 "X"닫기 버튼을 클릭 할 때이 메서드를 호출해야합니다.
Closing += (sender, e) => viewModel.CloseWindowCommand();
이 처리되지 않은 예외 결과 :
는 가시에 가시성을 설정하거나 표시, ShowDialog를, 닫기, 또는 WindowInteropHelper.EnsureHandle 창을 닫는 동안을 호출 할 수 없습니다 나는 다음 시도했다. 내가 잘못 뭐하는 거지
at System.Windows.Window.VerifyNotClosing()
at System.Windows.Window.InternalClose(Boolean shutdown, Boolean ignoreCancel)
at System.Windows.Window.Close()
at Myapp.ViewModel.RootViewModel.<get_CloseCommand>b__0()
at Myapp.RelayCommand.Execute(Object parameter)
at Myapp.ViewModel.RootViewModel.CloseWindowCommand()
at Myapp.View.RootView.WindowClose(Object sender, CancelEventArgs e)
at System.Windows.Window.OnClosing(CancelEventArgs e)
at System.Windows.Window.WmClose()
at System.Windows.Window.WindowFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
: 같은 호출 스택
?관련 질문 및 게시물 (here, here)을 보았지만 지금까지 문제를 찾을 수 없었습니다.
모든 포인터가 감사하겠습니다.
+1 가능성이 계속되는 것은보기에서 클릭 한 단추입니다.보기는 명령을 실행하고 명령은보기를 닫으라고 다시 지시합니다. VM이 자체적으로 닫히지 않는지 확인하기위한 플래그를 추가하십시오. – stijn