zzz6519003 / gong-wpf-dragdrop

Automatically exported from code.google.com/p/gong-wpf-dragdrop
1 stars 0 forks source link

'System.Windows.Documents.Run' is not a Visual or Visual3D' Exception #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Suddenly an unhandled Exception is thrown namely:
'System.Windows.Documents.Run' is not a Visual or Visual3D'

The exception occurs in
VisualTreeExtensions.cs in the Method GetVisualAncestor<T>(this 
DependencyObject d) where T : class

To solve the problem I would add a check like so:
public static T GetVisualAncestor<T>(this DependencyObject d) where T : 
class
{
    if (d is Visual || d is System.Windows.Media.Media3D.Visual3D)
    {
        DependencyObject item = VisualTreeHelper.GetParent(d);

        while (item != null)
        {
            T itemAsT = item as T;
            if (itemAsT != null) return itemAsT;
            item = VisualTreeHelper.GetParent(item);
        }
    }

    return null;
}

Original issue reported on code.google.com by manfred....@gmail.com on 4 Jun 2010 at 12:57

GoogleCodeExporter commented 9 years ago
Could you give me more information about this issue please? Where is the Run 
defined? If you could provide a minimal XAML example that would be helpful.

Original comment by gro...@gmail.com on 22 Jun 2010 at 10:35

GoogleCodeExporter commented 9 years ago
I was having this problem too. But using a fix like this prevented me from 
dragging something that has a Run in it if the user clicks on the Run.
Here is a patch to fix it. The patch also updates to VS 2010 and dot net 4, but 
you can reverse the changes to the .csproj file if you don't want that.

Original comment by jbo...@gmail.com on 14 Feb 2011 at 5:16

Attachments: