I have a component which creates a WPF Window when it is double clicked. The owner of the Window is registered as the handle of its parent document.
public sealed class MyComponent : GH_Component
{
public MainWindow MyMainWindow {get; set;}
protected override void CreateAttributes()
{
MyAttribs = new AttributesB(this);
}
private class AttributesB : GH_ComponentAttributes
{
public AttributesB(IGH_Component component) : base(component) { }
public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvaseMouseEvent e)
{
((MyComponent)Owner).ShowMainWindow();
return GH_ObjectResponse.Handled;
}
}
public void ShowMainWindow()
{
if(MyMainWindow == null || MyMainWindow.IsClosed())
{
MyMainWindow = new MainWindow(MyComponent);
}
GH_DocumentEditor owner = Grasshopper.Instances.DocumentEditor;
WindowInteropHelper helper = new WindowInteropHelper(MyMainWindow);
helper.Owner = owner.Handle;
MyMainWindow.Show();
}
}
When I minimize the Grasshopper window, this new window also minimizes along with it. However, when I close the Grasshopper window, the new window does not close with it. After I close the new window manually, Rhino becomes unresponsive, as if the user cannot interact with it.
Is there a way to call the new window to close when Grasshopper closes?