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
Solved! Go to Solution.
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
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
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.
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
Hi @Wolf ,
I'm also looking modal use using the ProWindow and have implemented something similar to your example as below. However ShowDialog() doesn't appear to be blocking and the code continues executing although close() is never called and I've tested this by debugging on the closed event handler
if (_oauthConsent != null)
return;
_oauthConsent = new OAuthConsent();
_oauthConsent.Owner = FrameworkApplication.Current.MainWindow;
_oauthConsent.Closed += _oauthConsent_Closed;
this._oauthConsent.webBrowser.NavigationStarting += new EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs>(browser_Navigated);
this._oauthConsent.webBrowser.Source = new Uri(this._uri);
var result = this._oauthConsent.ShowDialog();
I tested your code snippet and it works fine. I don't understand what you mean with "ShowDialog() is not blocking". What version of Pro are you using and how do you close the Pro Window? Try using the 'X' on the top right of the window to close it.
Here's the snippet i used for the ProWindow above (it's identical to what you have except for the properties).
try
{
if (_oauthConsent != null)
return;
_oauthConsent = new ModalProWindow();
_oauthConsent.Owner = FrameworkApplication.Current.MainWindow;
_oauthConsent.Closed += (o, e) => { _oauthConsent = null; };
//this._oauthConsent.webBrowser.NavigationStarting += new EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs>(browser_Navigated);
//this._oauthConsent.webBrowser.Source = new Uri(this._uri);
var result = this._oauthConsent.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show($@"ex");
}
I'm running ArcGIS Pro 3.1.0. What I mean by "not blocking" is the window doesn't act modal when calling "ShowDialog()". I've tested calling the IsModal() method before and after ShowDialog and it always returns false. In the example it seems to return false as the result and it keeps execution continues to any code following even though the window isn't closed. I've even checked by debugging the window closed event and it's never called until the window is explicitly closed (as expected).
Not sure what your code is doing, but i attached a project with two Modal ProWindows. One is WinForms based and one is Mvvm based. Please build and run this project and see if this satisfies your needs.
Here is one of these 'modal' Pro Windows, and no user input for ArcGIS Pro is accepted until you close the Pro Window.