Close DockablePane Window EventArgs

Close DockablePane Window EventArgs

jw.vanasselt
Advocate Advocate
970 Views
10 Replies
Message 1 of 11

Close DockablePane Window EventArgs

jw.vanasselt
Advocate
Advocate

Hi all,


Is it necessary to close all my EventArgs form WPF forms?

I close for example (listview item) lv_example.SelectionChanged, but do I need to close my buttons too?

For example my cancel button:

jwvanasselt_0-1705476144812.png

 

0 Likes
Accepted solutions (1)
971 Views
10 Replies
Replies (10)
Message 2 of 11

ricaun
Advisor
Advisor

It's not a Revit API question and, it depends.


Most of the time is not necessary, if the event only gonna trigger if the Window is open and you only add the event when the window is created (new MainWindow()).

 

By the way, the Window has a Closed Event that could be used to unsubscribe or disable some features, when the window is about to close. The Loaded Event could be used to subscribe to an event when the windows open/load.

 

For example, use the Revit SelectionChanged event to only work when the window is opened.

Here is an old example: https://github.com/ricaun-io/RevitAddin.SelectionChangedExample/blob/master/RevitAddin.SelectionChan...

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 3 of 11

jw.vanasselt
Advocate
Advocate

Thank you for the quick response; I provided insufficient information.

I have a dockable window in which I built a library. Upon a double mouse click, the family should be loaded and placed. In this void, there is an IExternalEventHandler that loads and places the family.

Additionally, I have several += handlers that modify the item source of the listview, such as a search bar or organizing families by category. I want to ensure that the library doesn't perform any background actions that could cause the user's project to freeze.

The library's structure is based on an XML.

 

jwvanasselt_0-1705503158741.png

 

 

0 Likes
Message 4 of 11

ricaun
Advisor
Advisor
Accepted solution

DockablePane does not have a close. I guess the only way to know if the Dockable hides is by using the event DockableFrameVisibilityChanged.

 

I did some experiments with DockablePane to check if the Page event IsVisibleChanged is triggered when the DockablePane is hidden and the answer is no... Here is the project: RevitAddin.Dockable.Example

 

Probably in your case if the DockablePane is hidden any event in your UI is not gonna be triggered, but if your code changes the 'search bar' text, the event TextChanged gonna trigger even if your DockablePane is hidden.

 

I guess the way to do it is by using the event DockableFrameVisibilityChanged to disable the events in the Page/Dockable.

 

PS: You could edit the Title of your post to add DockablePane.

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 5 of 11

jw.vanasselt
Advocate
Advocate

Thanks for the information and the example!

0 Likes
Message 6 of 11

ricaun
Advisor
Advisor

Yesterday I was messing with the IFrameworkElementCreator and found out that have an option to add your singleton class FrameworkElement. Using that I could register a new DockablePage() with a GUID and make in the background the DockableFrameVisibilityChanged to force the instance page to be visible or not to match the Revit UI.

 

dockablePaneCreatorService = new DockablePaneCreatorService(application);
dockablePaneCreatorService.Initialize(); // Add events

dockablePaneCreatorService.Register(DockablePage.Guid, new DockablePage());

dockablePaneCreatorService.Dispose(); // Remove events


Using that I could inject something in the constructor as well like, new DockablePage(IRevitTask) and the page knows when is hidden or not.

 

Here is the code in the develop branch: DockablePaneCreatorService.cs

 

Probably gonna create a video or something 😄

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 7 of 11

jw.vanasselt
Advocate
Advocate

I did indeed see it in your development branch!
Good job, I'm looking forward to the video 😄

0 Likes
Message 8 of 11

ricaun
Advisor
Advisor

After testing some approaches I discover some interesting behavior about DockablePane.

 

  • If Revit does not have any documents open, 'application.GetDockablePane(dpid)' or 'new DockablePane(dpid)' gonna throw an exception even after registering the DockablePane.
  • When the first document has opened the Page inside the DockablePane is loaded, the event Loaded in the Page is triggered, and the IsVisibleChanged trigger to 'true'.
  • When two documents are opened inside Revit, if you swap between documents, the event IsVisibleChanged on the Page goes to `false` and goes back to `true`.
  • After closing the last document inside Revit the Page inside the DockablePane is unloaded, the event Unloaded is triggered inside the Page, and the IsVisibleChanged trigger to 'false'.
  • After opening a document and the DockablePane is opened, after closing all documents, if I open a new document in the same Revit section (without closing Revit) the DockablePane gonna be closed, and the event DockableFrameVisibilityChanged in the Revit Application does not trigger. (Maybe this is a bug.)
  • The DockablePane.Show and DockablePane.Hide gonna trigger the event DockableFrameVisibilityChanged in the Revit Application even if the DockablePane is already shown or hidden.
  • The event DockableFrameVisibilityChanged in the Revit Application only triggers when DockablePane.Show or DockablePane.Hide is used, or the user closes the DockablePane inside the Revit UI.

 

The idea of using IsVisibleChanged and Visibility on the Page to link with the DockablePane

is not gonna work as I intended, the most reliable way to know if the DockablePane is open is by using the DockablePane.IsShown.

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 9 of 11

jw.vanasselt
Advocate
Advocate

@ricaun I have an other topic with a Application Hang issue:
Application Hang after using DockablePane (Top level window is idle) - Autodesk Community - Revit Pr...

I don't have a service like this (yet)
 DockablePaneCreatorService.cs

 

My application error report calls it Top-Level Window is idle.
I that why you use the Dispose() function?

0 Likes
Message 10 of 11

ricaun
Advisor
Advisor

I use Dispose to unsubscribe to the Revit events, but there could be another method like Unsubscribe(), in the end, I prefer to have the interface IDisposable with Dispose.

 

Never heard about his Application Hang issue.

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 11 of 11

jw.vanasselt
Advocate
Advocate

It for me the first time too, strange.

0 Likes