I cannot open a WPF panel from the OnLoad function of the PlugIn class. The call to OpenPanel or OpenPanelAsSibling fails and returns false. However, when I do it from a command it works ok. Is there a way to open the panel automatically when the plugin is loaded?
namespace MyPlugIn
{
public class MyPlugIn : Rhino.PlugIns.PlugIn
{
public MyPlugInPlugIn()
{
Instance = this;
}
//Gets the only instance of MyPlugIn
public static MyPlugIn Instance
{
get;
private set;
}
protected override Rhino.PlugIns.LoadReturnCode OnLoad(ref string errorMessage)
{
// Register and open WPF panel
System.Type panel_type = typeof(PalettePanelHost);
Rhino.UI.Panels.RegisterPanel(this, panel_type, "MyPanel", MyPlugIn.Properties.Resources.MyIcon);
bool ok = Rhino.UI.Panels.OpenPanelAsSibling(PalettePanelHost.PanelId, Rhino.UI.PanelIds.Layers);
if (!ok)
{
// The call always fails when called from OnLoad.
// As a workaround, which I don't like at all, I have to call OpenPanel
// from a command line command (i.e. "Initialize")
}
return Rhino.PlugIns.LoadReturnCode.Success;
}
}
// Rhino framework requires a System.Windows.Forms.IWin32Window derived object for a panel
[System.Runtime.InteropServices.Guid("AEAC7948-CF21-4FA2-8DD7-330DF7AD16B3")]
public class PalettePanelHost : RhinoWindows.Controls.WpfElementHost
{
public PalettePanelHost()
: base(new PalettePanel(), null)
{
}
// Returns the ID of this panel
public static System.Guid PanelId
{
get
{
return typeof(PalettePanelHost).GUID;
}
}
}
}