1

I have some problems with ChildWindow control, I have created an error window control that is shown after unhandled exception is caught in app.xaml.cs. The problem is when I try to show the error window, sometimes it works fine, but sometimes I get this nasty exception:

Message: Error HRESULT E_FAIL has been returned from a call to a COM component.

Stack Trace: at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, Boolean b) at System.Windows.DependencyObject.SetValue(DependencyProperty property, Boolean b) at System.Windows.Controls.Primitives.Popup.set_IsOpen(Boolean value) at System.Windows.Controls.ChildWindow.Show() at FrontEnd.SL.Util.GuiLogger.ShowErrorWindow(ErrorDetails details, ErrorSeverity severity)


the trace you see is inside the Show() method of the ChildWindow.
In another words, my code is:
ErrorWindow errorWin= new ErrorWindow();
errorWin.Show();
where ErrorWindow:ChildWindow

any help is greatly appreciated..

Boris
  • 13
  • 3

2 Answers2

1

It seems to me that the use of a ChildWindow control is going to be prone to some problems. What happens if the incumbent VisualTree is in an inconsistent/broken state as result of the exception?

The best chance you have to "handling" an unhandled exception within the bounds of the application would be to completely replace the existing object held by the VisualRoot.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Hello Anthony, You are right, it seems that VisualTree state was indeed broken as a result of an error that was caught. Instead of using .Show() method in these cases, I need to manually add ChildWindow to RootVisual. A bit of a botched job, but what can you do :S – Boris Dec 29 '09 at 16:03
  • +1, could you please elaborate on why the use of ChildWindow control is prone to problems? Thanks! – VoodooChild Nov 25 '10 at 18:26
  • @VoodooChild: The child window creates an illusion of being modal by creating a translucent rectangle which covers the whole of the Sliverlight client area. Hence all mouse moves after the Childwindow is opened goes to the child window. If a control underneath basis its MouseOver state entirely on MouseEnter/MouseLeave events and a childwindow is launched when it is in the MouseOver state it will not get the corresponding MouseLeave event. By the time the child window is dismissed the mouse is no longer over the original element. – AnthonyWJones Nov 26 '10 at 09:12
0

This can also happen if there is a problem loading the content of the childwindow. In my case I had specified different namespaces in a usercontrol's code-behind and its xaml, which caused this cryptic error.

Lars Holm Jensen
  • 1,645
  • 1
  • 12
  • 14