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

Try to catch an InvalidOperationException? #469

Closed
PatrickKursawe opened this issue May 26, 2023 · 2 comments
Closed

Try to catch an InvalidOperationException? #469

PatrickKursawe opened this issue May 26, 2023 · 2 comments

Comments

@PatrickKursawe
Copy link

I know this is a poor report, but it is all information I have got - just a stacktrace.

InvalidOperationException: This Visual is not connected to a PresentationSource.
[GongSolutions.WPF.DragDrop]GongSolutions.Wpf.DragDrop.DragDrop/<>c
internal void b__34_0(Point point);
IL Offset=0x0013.
[GongSolutions.WPF.DragDrop]GongSolutions.Wpf.DragDrop.Utilities.MouseHelper/<>c__DisplayClass1_0
internal void b__0(object _, EventArgs _);
IL Offset=0x0028.
[...] skipping parts in Windows
[GongSolutions.WPF.DragDrop]GongSolutions.Wpf.DragDrop.DragDrop
private static void DoDragSourceMove(object sender, Func`2<class [PresentationCore]System.Windows.IInputElement,valuetype [WindowsBase]System.Windows.Point> getPosition);
IL Offset=0x01b8.
[GongSolutions.WPF.DragDrop]GongSolutions.Wpf.DragDrop.DragDrop
private static void DragSourceOnMouseMove(object sender, MouseEventArgs e);
IL Offset=0x007c.

System is Windows 10.0.19045.0
The drag/drop operation is on a DataGrid inside an element host of a windows forms app.

As this error already happened a few times, but I really can't find a way to reproduce it at will, I would suggest that you maybe just catch this kind of exception in DoDragSource move and ignore the attempted operation?

I am using version 3.2.1 or your package. Thanks!

@punker76
Copy link
Owner

punker76 commented Oct 9, 2023

@PatrickKursawe You can handle exceptions by yourself. You need to derive (as an example) from the DefaultDragHandler or create a complete new one from IDragSource and use then that at your ItemsSource.

    public class DefaultDragHandlerImpl : DefaultDragHandler
    {
        public override bool TryCatchOccurredException(Exception exception)
        {
            if (exception is InvalidOperationException)
            {
                // log or do something special

                // with this you say that you handle this exception
                return true;
            }

            return base.TryCatchOccurredException(exception);
        }
    }

@punker76 punker76 closed this as completed Oct 9, 2023
@PatrickKursawe
Copy link
Author

Thanks for the hint, will do.

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

2 participants