Exception when using WPF UserControl under ElementHost in an Excel AddIn
rafaelnader opened this issue · 2 comments
rafaelnader commented
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 commented
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 commented
this issue will be published in 0.1.3.7