How to put ArcGIS Pro MessageBox in Front of closing MessageBox?

804
3
Jump to solution
03-19-2020 01:27 PM
KarstenRank
Occasional Contributor III

Hi,

is it possible to put an ArcGIS.Desktop.Framework.Dialogs.MessageBox in front of the "Closing Project" MessageBox?

Thanks Karsten

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Karsten,

 I tried the following code which seemed to work fine.  In essence i subscribe to the Project Closing event in my module class and execute your MessageBox logic in the subscription method.

First i changed the autoLocad property in the insertModule tag in my config.daml to true:

  <modules>
    <insertModule id="ProjClosing_Module" className="Module1" 
                  autoLoad="true"   caption="Module1">
    ....
    </insertModule>
  </modules>‍‍‍‍‍

This will ensure that my add-in is initialized regardless of any UI interactions.

In the Module's Initialize override i subscribe to the Project Closing event, and in OnProjectClosing i do the customization including the MessageBox.

protected override bool Initialize()
{
  ArcGIS.Desktop.Core.Events.ProjectClosingEvent.Subscribe(OnProjectClosing);
  return base.Initialize();
}

/// <summary>
/// Event handler for ProjectClosing event.
/// </summary>
/// <param name="args">The ProjectClosing arguments.</param>
/// <returns></returns>
private Task OnProjectClosing(ArcGIS.Desktop.Core.Events.ProjectClosingEventArgs args)
{
  // if already canceled, ignore
  if (args.Cancel)
    return Task.CompletedTask;
  var targetProjFolder = @"c:\temp";
  var result = MessageBox.Show($@"Soll das aktuelle Projekt in ein anderes Verzeichnis als          {targetProjFolder} kopiert werden ?", "Projekt sichern", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Question);
  return Task.CompletedTask;
}

the Project closing messagebox doesn't show up until after i answer the popup messagebox.

Hope this helps,

Wolf

View solution in original post

3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Karsten, what is the workflow that you try to accomplish, in order words what event triggers the MessageBox that occurs with the 'Closing Project' message box?

0 Kudos
KarstenRank
Occasional Contributor III

I check the project path and if a part of that is set in the options, a MessageBox appears. The user can choose if the set save path in the options is right or not, can cancel the action.

closing window is in front 

How to call the MessageBox to show it always in foreground (right image)?

static void closedProject()
{
...


if (appSettings.GeneralSetting1 == true && appSettings.GeneralSetting2 == sourceProjFolder.Substring(0, lensourceAppFolder))
   {

      MessageBoxResult result = ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Soll das aktuelle Projekt in ein anderes Verzeichnis als          " + targetProjFolder + " kopiert werden ?", "Projekt sichern", System.Windows.MessageBoxButton.YesNoCancel,          System.Windows.MessageBoxImage.Question); 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Karsten,

 I tried the following code which seemed to work fine.  In essence i subscribe to the Project Closing event in my module class and execute your MessageBox logic in the subscription method.

First i changed the autoLocad property in the insertModule tag in my config.daml to true:

  <modules>
    <insertModule id="ProjClosing_Module" className="Module1" 
                  autoLoad="true"   caption="Module1">
    ....
    </insertModule>
  </modules>‍‍‍‍‍

This will ensure that my add-in is initialized regardless of any UI interactions.

In the Module's Initialize override i subscribe to the Project Closing event, and in OnProjectClosing i do the customization including the MessageBox.

protected override bool Initialize()
{
  ArcGIS.Desktop.Core.Events.ProjectClosingEvent.Subscribe(OnProjectClosing);
  return base.Initialize();
}

/// <summary>
/// Event handler for ProjectClosing event.
/// </summary>
/// <param name="args">The ProjectClosing arguments.</param>
/// <returns></returns>
private Task OnProjectClosing(ArcGIS.Desktop.Core.Events.ProjectClosingEventArgs args)
{
  // if already canceled, ignore
  if (args.Cancel)
    return Task.CompletedTask;
  var targetProjFolder = @"c:\temp";
  var result = MessageBox.Show($@"Soll das aktuelle Projekt in ein anderes Verzeichnis als          {targetProjFolder} kopiert werden ?", "Projekt sichern", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Question);
  return Task.CompletedTask;
}

the Project closing messagebox doesn't show up until after i answer the popup messagebox.

Hope this helps,

Wolf