@@ -163,39 +163,46 @@ private void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEve
163163 // Drag = mouse down + move by a certain amount
164164 private void DragSource_PreviewMouseMove ( object sender , MouseEventArgs e )
165165 {
166- if ( this . draggedData != null )
167- {
168- // Only drag when user moved the mouse by a reasonable amount.
169- if ( Utilities . IsMovementBigEnough ( this . initialMousePosition , e . GetPosition ( this . topWindow ) ) )
170- {
171- this . initialMouseOffset = this . initialMousePosition - this . sourceItemContainer . TranslatePoint ( new Point ( 0 , 0 ) , this . topWindow ) ;
172-
173- DataObject data = new DataObject ( this . format . Name , this . draggedData ) ;
174-
175- // Adding events to the window to make sure dragged adorner comes up when mouse is not over a drop target.
176- bool previousAllowDrop = this . topWindow . AllowDrop ;
177- this . topWindow . AllowDrop = true ;
178- this . topWindow . DragEnter += TopWindow_DragEnter ;
179- this . topWindow . DragOver += TopWindow_DragOver ;
180- this . topWindow . DragLeave += TopWindow_DragLeave ;
181-
182- DragDropEffects effects = DragDrop . DoDragDrop ( ( DependencyObject ) sender , data , DragDropEffects . Move ) ;
183-
184- // Without this call, there would be a bug in the following scenario: Click on a data item, and drag
185- // the mouse very fast outside of the window. When doing this really fast, for some reason I don't get
186- // the Window leave event, and the dragged adorner is left behind.
187- // With this call, the dragged adorner will disappear when we release the mouse outside of the window,
188- // which is when the DoDragDrop synchronous method returns.
189- RemoveDraggedAdorner ( ) ;
190-
191- this . topWindow . AllowDrop = previousAllowDrop ;
192- this . topWindow . DragEnter -= TopWindow_DragEnter ;
193- this . topWindow . DragOver -= TopWindow_DragOver ;
194- this . topWindow . DragLeave -= TopWindow_DragLeave ;
195-
196- this . draggedData = null ;
197- }
198- }
166+ try
167+ {
168+ if ( this . draggedData != null )
169+ {
170+ // Only drag when user moved the mouse by a reasonable amount.
171+ if ( Utilities . IsMovementBigEnough ( this . initialMousePosition , e . GetPosition ( this . topWindow ) ) )
172+ {
173+ this . initialMouseOffset = this . initialMousePosition - this . sourceItemContainer . TranslatePoint ( new Point ( 0 , 0 ) , this . topWindow ) ;
174+
175+ DataObject data = new DataObject ( this . format . Name , this . draggedData ) ;
176+
177+ // Adding events to the window to make sure dragged adorner comes up when mouse is not over a drop target.
178+ bool previousAllowDrop = this . topWindow . AllowDrop ;
179+ this . topWindow . AllowDrop = true ;
180+ this . topWindow . DragEnter += TopWindow_DragEnter ;
181+ this . topWindow . DragOver += TopWindow_DragOver ;
182+ this . topWindow . DragLeave += TopWindow_DragLeave ;
183+
184+ DragDropEffects effects = DragDrop . DoDragDrop ( ( DependencyObject ) sender , data , DragDropEffects . Move ) ;
185+
186+ // Without this call, there would be a bug in the following scenario: Click on a data item, and drag
187+ // the mouse very fast outside of the window. When doing this really fast, for some reason I don't get
188+ // the Window leave event, and the dragged adorner is left behind.
189+ // With this call, the dragged adorner will disappear when we release the mouse outside of the window,
190+ // which is when the DoDragDrop synchronous method returns.
191+ RemoveDraggedAdorner ( ) ;
192+
193+ this . topWindow . AllowDrop = previousAllowDrop ;
194+ this . topWindow . DragEnter -= TopWindow_DragEnter ;
195+ this . topWindow . DragOver -= TopWindow_DragOver ;
196+ this . topWindow . DragLeave -= TopWindow_DragLeave ;
197+
198+ this . draggedData = null ;
199+ }
200+ }
201+ }
202+ catch ( Exception )
203+ {
204+ // This explodes sometimes, dunno why
205+ }
199206 }
200207
201208 private void DragSource_PreviewMouseLeftButtonUp ( object sender , MouseButtonEventArgs e )
0 commit comments