Trouble Getting Dockable Window from AddIn.FromID

3554
5
08-20-2010 02:02 PM
ScottDavis
Occasional Contributor
I get a null reference when I try to get my dockable window using FromID.

dock = AddIn.FromID<DockableWindow1>(ThisAddIn.IDs.DockableWindow1);


Is this the wrong way to get it? Anyone else been able to get it to work?
0 Kudos
5 Replies
EagerIp
New Contributor II
DockableWindow is a bit tricky here since it is implemented by two classes - 1) the UI part is the designer surface derived from controls and 2) the non-UI part is the class actually inherits from DockableWindow base class.

FromID can only handle types derived from base classes declared in ESRI.ArcGIS.Desktop.AddIns.dll. You have to pass in the type that inherits DockableWindow, which is the inner class of the designer window itself if you are using the Add-in Wizard.

If you go to the xml declaration of the dockable window, you will see the class attribute is set to �??DockableWindow1+AddinImpl�?�. You have to pass this type to get the dockablewindow implementation class first, then you have to expose a property there get a hold of the UI window.

public class DockableWindow1 : UserControl
{
...

/// <summary>
/// Implementation class of the dockable window add-in. It is responsible for 
/// creating and disposing the user interface class of the dockable window.
/// </summary>
public class AddinImpl : ESRI.ArcGIS.Desktop.AddIns.DockableWindow
{
  private DockableWindow1 _windowUI;
  ...
  internal DockableWindow1 UI
  {
    get { return _windowUI; }
  }
}

}


var winImpl = AddIn.FromID<DockableWindow1.AddinImpl>(ThisAddIn.IDs.DockableWindow1);
DockableWindow1 dock = winImpl.UI;
0 Kudos
ScottDavis
Occasional Contributor
That was it! I've now got it working.

Thank you very much, Eager!
0 Kudos
DavidLednik
Occasional Contributor II
Is there more code that explains this anywhere?

My setup function in UserCommand always returns null on Win7 64bit

private void SetupDockableWindow()
        {
            if (m_dockableWindow == null)
            {
                IDockableWindowManager dockWindowManager = m_application as IDockableWindowManager;
                if (dockWindowManager != null)
                {
                    UID windowID = new UIDClass();
                    windowID.Value = DockableWindowGuid;
                    m_dockableWindow = dockWindowManager.GetDockableWindow(windowID);  // here I get NULL returned
                }
            }
        }


any ideas?
0 Kudos
ScottDavis
Occasional Contributor
I wrote a post on this a while ago that may be helpful.
http://geospatialscott.blogspot.com/2010/08/how-to-get-arcgis-add-in-dockable.html
0 Kudos
DavidLednik
Occasional Contributor II
I saw that article and I tried to implement the code on my sample.

The problem is that in this line
GazSearchDockableWindow.AddinImpl winImpl = AddIn.FromID<GazSearchDockableWindow.AddinImpl>(ThisAddIn.IDs.GazGazSearchDockableWindow);
The ThisAddIn is not recognized and I can't figure out which object I need to pass in here.

Regards,
David
0 Kudos