ComponentAdded Event

Hi,

I have another (admitedly very basic) question. How do you access the Component property from the ComponentAddedEventArgs?

I serched the forum, watched the tutorials and the webinars dealing with event handling but couldn’t find an example where the EventArgs are accesed.

Could someone please give me an example (or point me in the right direction) of how to for example print out the name of the component that was added to the layout?

Thanks,

Jure

var app = IoC.Get< IApplication>();
var msger = IoC.Get< IMessageService>();
app.World.ComponentAdded += when_component_added;

private void when_component_added(object sender, ComponentAddedEventArgs e)
{
var component = e.Component;
var name = component.GetProperty(“Name”).Value;
msger.AppendMessage($“Component added: {name}”, MessageLevel.Warning);
}

1 Like

Thank you!

I almost had it, but was using the wrong EventArgs constructor :).

1 Like