@PNJeffries wrote:
I’m updating a Rhino 5 plugin to work in Rhino 6. As part of that, I’m using a custom panel in Rhino as a host for some WPF controls. The following code worked for this in Rhino 5:
using RUI = Rhino.UI; using R = Rhino; public void CreateHostDockPanel() { if (!RUI.Panels.IsPanelVisible(typeof(SideBarUIHost).GUID)) { if (!RUI.Panels.OpenPanelAsSibling(typeof(SideBarUIHost).GUID, RUI.PanelIds.Layers)) RUI.Panels.OpenPanel(typeof(SideBarUIHost).GUID); } SideBarControl selectPanel = new SideBarControl(); selectPanel.DataContext = Core.Instance; SideBarUIHost host = (SideBarUIHost)RUI.Panels.GetPanel(typeof(SideBarUIHost).GUID); host.Host(selectPanel); }
In Rhino 6, however, this causes a problem because while it creates the panel OK, trying to retrieve it with the second-to-last line returns null, unless I create the panel, manually click on it to make it topmost and then re-run the code, in which case it retrieves the SideBarUIHost panel successfully.
Looking in the docs, Panels.GetPanel(Guid) is marked as deprecated. Fair enough; there are quite a few overloads which are not so I tried switching to some of them. I’ve tried replacing that line with all of:
SideBarUIHost host = (SideBarUIHost)RUI.Panels.GetPanel(typeof(SideBarUIHost).GUID); SideBarUIHost host = (SideBarUIHost)RUI.Panels.GetPanel(typeof(SideBarUIHost).GUID, R.RhinoDoc.ActiveDoc); object[] panels = RUI.Panels.GetPanels(typeof(SideBarUIHost).GUID, R.RhinoDoc.ActiveDoc); SideBarUIHost host = panels.FirstOrDefault() as SideBarUIHost; SideBarUIHost host = RUI.Panels.GetPanel<SideBarUIHost>(R.RhinoDoc.ActiveDoc);
These are not marked as obsolete, but they all display the same behaviour, returning null or an empty array unless I first manually give the panel focus.
Is this expected behaviour?
What is the correct way of accessing created custom panels in Rhino 6?
Posts: 1
Participants: 1