Open modal dialog and wait for user input

710
3
Jump to solution
04-06-2020 02:28 PM
MarvisKisakye1
Occasional Contributor

How can I open a modal dialog from within the code and wait for user to interact with it before proceeding with the rest of the code? The functionality that I am looking for in the pro sdk is similar to the the one at this link https://docs.microsoft.com/en-us/dotnet/api/system.windows.window.showdialog?redirectedfrom=MSDN&vie... Uma Harano Wolfgang Kaiser

1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Marvis,

 You need to add a ProWindow (via the ArcGIS Pro SDK item templates) to your add-in.  By default the ProWindow you add to your project will not be MVVM, but you can use the newly created ProWindow like any out-of-box WPF window.  You can find an example of such a ProWindow in community samples here:  https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/f5f9dda18efa173a56d128f3ea64ca34ac3f68...

 Then you can use the following snippet to instantiate the ProWindow for the Report Categories sample linked above as follows:

 internal class ShowReports : Button
  {
    private UI.ReportsWindow _reportsWnd = null;

    protected override void OnClick()
    {
      //already open?
      if (_reportsWnd != null)
        return;
      _reportsWnd = new UI.ReportsWindow();
      _reportsWnd.Owner = FrameworkApplication.Current.MainWindow;
      _reportsWnd.Closed += (o,e) => { _reportsWnd = null; };
      _reportsWnd.ShowDialog();
    }
  }

  One problem is that the ShowDialog() method is in an internal namespace but Visual Studio should be able to locate the method via intellisense.  This is a bug that we will fix as soon as possible.  This is also the reason why ShowDialog doesn't show up in the Pro SDK API help documentation.  ShowDialog returns true if you set the DialogResult property to true before calling Close() on the ProWindow.   Let me know if you have any questions or if you need of a MVVM sample.

- Wolf

View solution in original post

0 Kudos
3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Marvis,

 You need to add a ProWindow (via the ArcGIS Pro SDK item templates) to your add-in.  By default the ProWindow you add to your project will not be MVVM, but you can use the newly created ProWindow like any out-of-box WPF window.  You can find an example of such a ProWindow in community samples here:  https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/f5f9dda18efa173a56d128f3ea64ca34ac3f68...

 Then you can use the following snippet to instantiate the ProWindow for the Report Categories sample linked above as follows:

 internal class ShowReports : Button
  {
    private UI.ReportsWindow _reportsWnd = null;

    protected override void OnClick()
    {
      //already open?
      if (_reportsWnd != null)
        return;
      _reportsWnd = new UI.ReportsWindow();
      _reportsWnd.Owner = FrameworkApplication.Current.MainWindow;
      _reportsWnd.Closed += (o,e) => { _reportsWnd = null; };
      _reportsWnd.ShowDialog();
    }
  }

  One problem is that the ShowDialog() method is in an internal namespace but Visual Studio should be able to locate the method via intellisense.  This is a bug that we will fix as soon as possible.  This is also the reason why ShowDialog doesn't show up in the Pro SDK API help documentation.  ShowDialog returns true if you set the DialogResult property to true before calling Close() on the ProWindow.   Let me know if you have any questions or if you need of a MVVM sample.

- Wolf

0 Kudos
MarvisKisakye1
Occasional Contributor

Hi Wolfgang Kaiser, the showDialog does what I needed thanks but I would appreciate an MVVM sample as that's what I am familiar with thanks.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Marvis,

 I added a sample showing how to implement a modal ProWindows dialog.  https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Framework/ProWindowMVVM