Question

I'm trying to register the DialogBoxShowing event of the UIControlledApplication. But I cannot use the OnStartup / OnShutdown implementation of the IExternalApplication interface. The best I could come up with is...

    public delegate void Handeler(object sender, DialogBoxShowingEventArgs e);

    public void RegesterDialogEvent(UIControlledApplication uicApp)
    {
        UIAppEventHandlers1 uaeh1 = new UIAppEventHandlers1();
        Handeler hdlr = new Handeler(UIAppEventHandlers1.UIAppEvent_DialogBoxShowing_Handler);

        uicApp.DialogBoxShowing += hdlr;

    }

But i'm getting the "Cannot implicitly convert type 'TaskDialogEvent_01.Form1.Handeler' to 'System.EventHandler Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs> " error. My 'UIAppEventHandlers1' method has the same signature as the Handler. What am I doing wrong and can anyone provide an example? Thank you.

Was it helpful?

Solution

You probably want to use the uaeh1 instance you created:

UIAppEventHandlers1 uaeh1 = new UIAppEventHandlers1();
uicApp.DialogBoxShowing += uaeh1.UIAppEvent_DialogBoxShowing_Handler;

This is still weird because you just new'ed that object.

You say you can't just register/unregister in the app class as follows?

public Result OnStartup(UIControlledApplication app)
{
    app.DialogBoxShowing += OnDialogBoxShowing;
    return Result.Succeeded;
}

public Result OnShutdown(UIControlledApplication app)
{
    app.DialogBoxShowing -= OnDialogBoxShowing;
    return Result.Succeeded;
}

void OnDialogBoxShowing(object sender, DialogBoxShowingEventArgs args)
{
}

Handling dialogs with the DialogBoxShowing event isn't the best way in my experience. I would recommend looking into the newer failures processing API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top