Select to view content in your preferred language

Execute Tool from a Behavior

526
4
09-05-2013 05:22 AM
BrianLeroux
Frequent Contributor
So I have a custum add-in that I build to query a service and return results to the map. While useful in one application by clicking a button to execute, I am looking to utilize the same tool in another app but this time I need it to automatically run the tool when the map opens. I am not sure what is the best way to go about this? Can I use a behavior to launch the tool?

The reason I want to use the tool is I also want the user to be able to close after the first launch and have the ability to re-open the tool and change the query to re-run at anytime.

I appreciate any help.
0 Kudos
4 Replies
brettangel
Frequent Contributor
YourTool.Execute("") assuming the execute is public.
0 Kudos
BrianLeroux
Frequent Contributor
So I think I may be getting closer. I reference my add-in tools dll in my new behavior project. I can call te execute method but it is looking for an object parameter. I am not sure what to put here. I tried using null but When the behavior runs it says the parameter is missing.
0 Kudos
BrianLeroux
Frequent Contributor
Well i was able to get the execute method to run from the behavior but it appears all the elements of the tool are not initializing. I have a viewmodel that is supposed to query some data sources and populate combo boxes but that is not working.
0 Kudos
PietaSwanepoel2
Frequent Contributor
Brian,

I used the code from the query tool (publised by SLDevTem) as base for another add-in that I wrote. They have some really nice code in the project
http://www.arcgis.com/home/item.html?id=451259f8e47440f2b727442fe1b2f7c2

My tool runs once the button is clicked (Execute function). Assume that same should be possible with behaviour

Example code from QueryTool project:
public void Execute(object parameter)
{
 ToolExecuting = true;
 try
 {
  toolView = new MyToolView()
  {
   Margin = new Thickness(10),
   MinWidth = 400,
   MinHeight = 400,
   HorizontalAlignment = HorizontalAlignment.Stretch
  };
  toolView.Unloaded += toolViewOnUnloaded;

  // Updates tool DataContext with savedConfiguration.
  var toolViewModel = toolView.DataContext as MyConfigurationViewModel;
  if (toolViewModel == null)
  {
   toolViewModel = savedConfiguration != null ? new MyConfigurationViewModel(savedConfiguration) : new MyConfigurationViewModel();
   toolView.DataContext = toolViewModel;
  }
  else if (savedConfiguration != null)
  {
   toolViewModel.ApplyChanges(savedConfiguration);
  }
...

                // Executes tool on click when there are no visible expression.
                if (toolViewModel.Execute.CanExecute(null))
                        toolViewModel.Execute.Execute(null);
 }
 catch (Exception e)
 {
  MapApplication.Current.ShowWindow("Error", new TextBlock() { Text = e.Message });
 }
}
0 Kudos