mitevpi / revit-wpf-template

Template for a Revit add-in using WPF and executing valid external commands within the Revit API context.
https://revit-wpf-template-docs.now.sh
MIT License
171 stars 46 forks source link

Revit EventHandlers #11

Closed RyanPatrickDaley closed 1 year ago

RyanPatrickDaley commented 1 year ago

@mitevpi , In the context of this WPF template, where should Revit EventHandlers be placed? For example, I am trying to use the Application.DocumentChanged event. Where should this be in order to be in the "Valid Revit API Context?"

RyanPatrickDaley commented 1 year ago

I ended up putting the DocumentChanged event in the Constructor for the UI.Xaml.Cs, and it is working fine. I'm not sure if this is ideal, but it does work

public Ui(UIApplication uiApp, EventHandlerWithWindowArg evExternalMethodStringArg, ControlledApplication m_CtrlApp)
{
_uiDoc = uiApp.ActiveUIDocument;
_doc = _uiDoc.Document;
_uiApp = uiApp;
 Closed += MainWindow_Closed;

 InitializeComponent();

DataModel = new ViewModel();
this.DataContext = DataModel;
m_CtrlApp.DocumentChanged += new EventHandler<Autodesk.Revit.DB.Events.DocumentChangedEventArgs>(CtrlApp_DocumentChanged);
 }