Create a custom event

1258
2
03-21-2017 02:00 AM
CollinKleiboer
New Contributor III

I want to create a custom event. What's the best way to do that?

Using the Pro SDK classes (like CompositePresentationEvent) or create a 'regular' .NET event?

If it's the best way to use the Pro SDK classes, could you provide me an example?

Thanks.

Kind regards,

Collin Kleiboer

GisSense BV

0 Kudos
2 Replies
CollinKleiboer
New Contributor III

I found it (thanks to the IlSpy disassembler!), see files below as an example of an event and eventarg class.

Event-class

public class GetJsonSelectionFinishedEvent : CompositePresentationEvent<GetJsonSelectionFinishedEventArgs>
{
   public static SubscriptionToken Subscribe(Action<GetJsonSelectionFinishedEventArgs> action, bool    keepSubscriberAlive = false)
   {
      return FrameworkApplication.EventAggregator.GetEvent<GetJsonSelectionFinishedEvent>().Register(action,       keepSubscriberAlive);
   }
   public static void Unsubscribe(Action<GetJsonSelectionFinishedEventArgs> action)
   {
      FrameworkApplication.EventAggregator.GetEvent<GetJsonSelectionFinishedEvent>().Unregister(action);
   }

   public static void Unsubscribe(SubscriptionToken token)
   {
      FrameworkApplication.EventAggregator.GetEvent<GetJsonSelectionFinishedEvent>().Unregister(token);
   }

   internal static void Publish(GetJsonSelectionFinishedEventArgs activeMapViewEventArgs)
   {
      FrameworkApplication.EventAggregator.GetEvent<GetJsonSelectionFinishedEvent>().Broadcast(activeMapViewEventArgs);
   }
}

EventArg-class

public class GetJsonSelectionFinishedEventArgs : System.EventArgs
{
   public BasicFeatureLayer BasicFL
   {
      get;
      private set;
   }

   public GetJsonSelectionFinishedEventArgs(BasicFeatureLayer bfl)
   {
      this.BasicFL = bfl;
   }
}

And then you can use it just like the other available events.

Collin.

CharlesMacleod
Esri Regular Contributor

Nice job Collin.

0 Kudos