I have a TargetedTriggerAction from a 3rd party library that would like to call/invoke without attaching it to a button. I have no problem getting it to work with the button, but I want to do it in response to some non-UI event.
Here is the action's class declaration:
public class MeasureAction : TargetedTriggerAction<Map>
Here is my setup code so far:
var measure = new MeasureAction();
measure.TargetObject = _mapControl;
measure.MeasureMode = MeasureAction.Mode.Polyline;
measure.MapUnits = DistanceUnit.Miles;
I want to be able to do something like this, but I know Invoke is protected:
measure.Invoke();
To invoke your trigger action, you need a trigger!
The above is a trigger implementation that may be invoked without any UI dependencies. For example:
To make calling this even easier, you could add an extension method to
TriggerAction
.Now you can write what you really wanted:
Old post but may help. I did like this
...
The OnTargetChanged() method will initialize the internal Map of the MeasureAction
Is the 3rd party class sealed?
If not, the "best" answer would probably be to derive your own class from
MeasureAction
and add a invoker (keep it internal/protected if you want to keep things clean).If it's sealed/otherwise frozen, your best bet is probably Reflection - there are ways to cache/otherwise speed up the cost of this call, but the basic code would be something like: