Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidOperationException When Floating A Document Containing A CustomControl With Focus() In It's OnApplyTemplate() #1745

Open
mwagnerEE opened this issue Apr 29, 2023 · 0 comments

Comments

@mwagnerEE
Copy link

While looking to see if this issue was addressed, I feel like I've seen similar issues with focusing or using Keyboard.Focus(). However most of those caused a NullReferenceException.

I am getting an InvalidOperationException when I drag the tab of a document to cause it to float. It seems to occur when the document contains a CustomControl which calls Focus() within it's OnApplyTemplate() method.

It seems to happen because when focusing I think the Dispatcher suspends messages but LayoutFloatingWindowControl sends a message in its OnActivated method.

I was running a local copy of AvalonDock when I encountered it and I changed the code to:

Application.Current.Dispatcher.BeginInvoke(()=> Win32Helper.SendMessage( windowHandle, Win32Helper.WM_NCLBUTTONDOWN, new IntPtr( Win32Helper.HT_CAPTION ), lParam ));

and it works for my purposes so far, although I have no idea if there will be any side effects?

It is extremely simple to reproduce. Attached is a folder containing the solution, a README explaining basically what I said here, and a file called "InvalidOperationException.txt" containing the exception info and CallStack of the error.
AvalonDockError.zip

Also, I believe this is completely unrelated, but while looking into this issue, I found that Microsoft discourages the use of SendMessage without checking InSendMessage to avoid deadlocks. Messages are a little over my head though and again I believe this to be unrelated as I've tried this and InSendMessage returned false but the error still occurred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant