2013-02-14 17 views
0

我正在開發一個使用棱鏡框架[.net 4.0]的wpf應用程序。我使用StockTrader RI中的RegionPopupBehavior實現了一個彈出窗口。現在,當我關閉主窗口,或者使用在窗口的標題欄[主窗口]的右上角的關閉按鈕,或者點擊一個按鈕使用WPF使用PopupRegion的Prism應用程序在關閉時拋出無效的窗口句柄

Application.Current.Shutdown() 

電話,我得到的消息的win32異常「無效的窗口處理「,堆棧跟蹤是所有互操作調用返回到應用程序的Run()調用。

我有搜索谷歌和所以沒有用的答案。我在關閉期間設置了中斷並檢查了Windows集合,但它只顯示主窗口處於活動狀態[如果彈出窗口被隱藏]。請注意,當我點擊關閉時,彈出窗口是否打開會出錯。

這裏是堆棧跟蹤:

at MS.Win32.HwndWrapper.DestroyWindow(Object args) 
    at MS.Win32.HwndWrapper.Dispose(Boolean disposing, Boolean isHwndBeingDestroyed) 
    at MS.Win32.HwndWrapper.Dispose() 
    at System.Windows.Interop.HwndSource.Dispose(Boolean disposing) 
    at System.Windows.Interop.HwndSource.WeakEventDispatcherShutdown.OnShutdownFinished(Object sender, EventArgs e) 
    at System.EventHandler.Invoke(Object sender, EventArgs e) 
    at System.Windows.Threading.Dispatcher.ShutdownImplInSecurityContext(Object state) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Windows.Threading.Dispatcher.ShutdownImpl() 
    at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 
    at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) 
    at System.Windows.Threading.Dispatcher.Run() 
    at System.Windows.Application.RunDispatcher(Object ignore) 
    at System.Windows.Application.RunInternal(Window window) 
    at System.Windows.Application.Run(Window window) 
    at System.Windows.Application.Run() 
    at RNDGroup.App.App.Main() in c:\Users\jgilliland\Projects\Common\Source\Prism GUI\RNDGroup.App\obj\x86\Release\App.g.cs:line 0 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

我的問題是無論我如何在類似情況之前解決這個問題,如果有人看到它,或者我如何去進一步調試這win32異常?謝謝,j

回答

1

我的團隊的技術負責人發現了這個問題並刪除了這個錯誤。彈出區域正被用於顯示/隱藏,或者在其自己的窗口中激活/停用VirtualKeyboardView。當我從用戶單擊按鈕時顯示鍵盤切換到在文本框獲得焦點時顯示鍵盤時,開始出現「無效窗口句柄」win32異常。

焦點事件有點有趣,我看到用戶點擊/焦點相同的多個焦點事件。無論如何,故事的結尾是我意識到這個問題是重複焦點事件,但我找不到問題的根源。我的隊友能夠追蹤這些看似重複的文本框焦點事件引發的遞歸問題。解決方案是跟蹤導致顯示鍵盤的最後一個文本框元素,並且基本上忽略重複的焦點事件。這刪除了無效窗口句柄的win32異常。

我知道這是一個奇怪的問題和更奇怪的答案,但這是我第一次在這樣的論壇上發佈問題,我顯然需要學習如何在第一個問題中更好地提出問題地點。但是,由於我的團隊領導人非常有幫助,我能夠擺脫這個錯誤,並繼續在第二個彈出窗口中以wpf實現此虛擬鍵盤。這一直是一種學習經驗。

下面是一些可能有助於澄清答案的代碼。這來自管理顯示和隱藏鍵盤視圖的VirtualKeyboardService。

/// <summary> 
/// Opens the keyboard. 
/// </summary> 
public void OpenKeyboard() 
{ 
    lock (_lock) 
    { 
     // allow for ignoring a refocus one time 
     if (_ignoreOnce) 
     { 
      _ignoreOnce = false; 
      return; 
     } 
     // open keyboard if not already open 
     if (!_isKeyboardOpen) 
     { 
      var viewName = typeof(VirtualKeyboardView).FullName; 
      _regionManager.RequestNavigate(RegionNames.PopupRegion, new Uri(viewName, UriKind.Relative)); 
      _isKeyboardOpen = true; 
      _lastImpression = null; 
     } 
    } 
} 

這是關閉虛擬鍵盤的方法,這是從鍵盤的視圖模型,當用戶點擊關閉按鈕調用,或者當他們按下回車,製表符,或Esc鍵。它也從MainWindow的Activated事件的事件處理程序調用。
/// ///關閉鍵盤。 /// ///如果設置爲true [還原文本]。 公共無效CloseKeyboard(布爾revertText =假){ 鎖 (_lock) { //關閉鍵盤視圖 VAR視圖= _regionManager.Regions [RegionNames.PopupRegion] .ActiveViews。FirstOrDefault();

 if (view != null) 
     { 
      _regionManager.Regions[RegionNames.PopupRegion].Deactivate(view); 
      _isKeyboardOpen = false; 
      _lastImpression = CurrentTarget; 
     } 

     // revert text if needed 
     if (revertText && CurrentTarget != null) 
     { 
      CurrentTarget.Text = CurrentText; 
     } 
    } 
} 

這也很棘手,那就是忽略一旦發揮作用的地方。當用戶點擊「離開」時,我必須能夠關閉鍵盤視圖,這會激活主窗口,這可能集中在文本框上,導致鍵盤視圖重新出現。忽略一旦選項允許突破該循環。自動顯示虛擬鍵盤涉及很多不同的用例。我學到了很多關於在wpf中使用行爲和複合命令的知識...

相關問題