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

Exception when using WPF UserControl under ElementHost in an Excel AddIn #59

Closed
rafaelnader opened this issue Apr 2, 2013 · 2 comments

Comments

@rafaelnader
Copy link

In "DragDrop.cs", "static void CreateDragAdorner()" raises an exception. I figured out that: I'm not using any Window, just UserControlers, so "Window parentWindow = m_DragInfo.VisualSource.GetVisualAncestor();" will return null, and then
"rootElement = (UIElement)Application.Current.MainWindow.Content;" raises an exception because Application.Current is null.

I fixed here changing
Window parentWindow = m_DragInfo.VisualSource.GetVisualAncestor();
to
UserControl parentWindow = m_DragInfo.VisualSource.GetVisualAncestor(); (exclusive to this project).

@marioleed
Copy link

Or maybe more in the line of this:

ContentControl parentWindow = m_DragInfo.VisualSource.GetVisualAncestor<Window>();
if (parentWindow == null)
{
    // Except, we would probably want to find the top most UserControl, 
    // the child of the ElementHost.
    parentWindow = m_DragInfo.VisualSource.GetVisualAncestor<UserControl>(); 
}

punker76 pushed a commit that referenced this issue Jun 5, 2013
fix Exception when using WPF UserControl under ElementHost in an Excel AddIn.
if no window is found, search again for a UserControl.
@punker76
Copy link
Owner

punker76 commented Jun 5, 2013

this issue will be published in 0.1.3.7

@punker76 punker76 closed this as completed Jun 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants