is there a listener for a busy dockpane?

291
6
11-29-2023 02:47 AM
nadja_swiss_parks
Occasional Contributor II

Currently I add whenever possible the following two functions at the start resp. end of a function. This approach is cumbersome and doesnt always work, because sometimes I get a wrong thread error regardless if it is an async method or not... 

 public void ShowBusyIndicator()
 {
     BusyIndicator.Visibility = Visibility.Visible;
 }

 public void HideBusyIndicator()
 {
     BusyIndicator.Visibility = Visibility.Collapsed;
 }

thus i was wondering, if it wasn't possible to listen somehow if the addin is currently busy. I found https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic10430.html this property. now I'm wondering, if it can be used to listen to it and to show or collapse my busyindicator. any help would be appriciated.

0 Kudos
6 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

IsBusy is a property you can override. Without overriding it always returns false. So first step you need to override it :

 

        private bool _isMyDockpaneBusy = false;
        public override bool IsBusy
        {
            get
            {
                return _isMyDockpaneBusy;
            }
        }

 

Then in your dockpane calculation method you must update _isMyDockpaneBusy depending on your calculation status:

 

private void DoMyJob()
{
    _isMyDockpaneBusy = true;
    NotifyPropertyChanged("IsBusy");
    try
    {

    }
    catch (Exception)
    {

    }
    finally {
        _isMyDockpaneBusy = false;
        NotifyPropertyChanged("IsBusy");
    }

}

 

Last step would be to bind in xaml your BusyIndicator Visibility to dockpane property IsBusy. For that you need to use Converter which converts bool value to visibility enum. You can make a search on web with string "wpf bool to visibility converter invert" and you will find different implementations of converter.

0 Kudos
nadja_swiss_parks
Occasional Contributor II

Thank you @GKmieliauskas for your prompt reply. Unfortunately, I don't understand it entirely. Could you specifiy the following for me: 

1. All the code you provided belongs in my dockpane.xaml.cs file, correct? 

I tried various locations. if i put the first codeblock in front of my public Dockpane1View() in my xaml.cs file I get CS0115 no suitable method found to override. But I'm stating "using ArcGIS.Desktop.Framework.Contracts;"

I tried also various locations for DoMyJob() - but at any place I get CS0103 NotifiyPropertyChanged does not exist in the current context. 

 

2. Am I assuming correctly, that DoMyJob() shows me the basic syntax of any function coded? meaning I replace DoMyJob with any functionname of my existing functions and add its code to try?

thank you in advance and sorry, this is my first dockpane ever..

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

1. No. All code must be placed in dockpane viewmodel class. Search for file like dockpaneViewModel.cs

We are toking about MVVM architecture of dockpane.

2. Yes. Button on dockpane xaml  which calls your function must be binded to ICommand type property  in dockpane ViewModel. Look into ArcGIS Pro community sample DockpaneSimple how "Get Maps" button is binded.

0 Kudos
nadja_swiss_parks
Occasional Contributor II

thank you @GKmieliauskas 

the functions are accepted in my viewmodel.cs - that's great.  but my dockpane doesn't only work with buttons. I've got also a double-click action implemented and the code for that is in my xaml.cs (I hope that's correct - it works at least..). how do I link an existing function of xaml.cs to DoMyJob() or the other way round? sorry, I'm still a bit stuck 

0 Kudos
GKmieliauskas
Esri Regular Contributor

There are few ways to resolve double-click action: your way or use behaviors. You can find double click behavior implementations on web. It would be MVVM way.

You can call ViewModel public method from code behind (*.xaml.cs) via DataContext, but it is not MVVM way:

(this.DataContext as viewmodel).YourMethodOnViewModel();

viewmodel is your view model class name

0 Kudos
nadja_swiss_parks
Occasional Contributor II

Thank you @GKmieliauskas 

Your method was certainly correcter than mine, but I would have needed to adapt a lot of code and in the end I would still need to change IsBusy for each method at the start and the end. that's why I stuck with my method. 

0 Kudos