Firstly, you can set the UIControlledApplication object to global variable, then you can access it in OnApplicationInitialized.
Secondly, after registering a dockable pane, you need to call DockablePane.Show() method on document opened event.
The pane's initial position is applied when RegisterDockablePane method called as the specific GUID onto the addin.
testform m_MyDockableWindow = null;
UIControlledApplication uiapp;
DockablePaneId dpid;
public Result OnStartup(UIControlledApplication UIControlledApp)
{
uiapp = UIControlledApp;
uiapp.ControlledApplication.ApplicationInitialized += OnApplicationInitialized;
uiapp.ControlledApplication.DocumentOpened += OnDocumentOpened;
return Result.Succeeded;
}
public void OnApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
{
testform MainDockableWindow = new testform();
m_MyDockableWindow = MainDockableWindow;
dpid = new DockablePaneId(new Guid("{54761517-118C-4A9A-938D-62384E4BAD72}"));
uiapp.RegisterDockablePane(dpid, "name of dockable pane", MainDockableWindow as IDockablePaneProvider);
}
public void OnDocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
{
DockablePane dp = uiapp.GetDockablePane(dpid);
dp.Show();
}
Third, it is recommended that the dockable dialog in the add-in be the class that implements IDockablePaneProvider and that it be subclassed from System.Windows.Controls.Page.
public partial class testform : Page, Autodesk.Revit.UI.IDockablePaneProvider
{
public testform()
{
InitializeComponent();
}
public void SetupDockablePane(Autodesk.Revit.UI.DockablePaneProviderData data)
{
data.FrameworkElement = this as FrameworkElement;
data.InitialState = new Autodesk.Revit.UI.DockablePaneState();
data.InitialState.DockPosition = Autodesk.Revit.UI.DockPosition.Tabbed;
data.InitialState.TabBehind = Autodesk.Revit.UI.DockablePanes.BuiltInDockablePanes.ProjectBrowser;
}
Best Regards,
Ryuji