Reset properties when a dockpane closes [edited: or close an Add-In]

1048
9
Jump to solution
02-23-2021 06:11 AM
GyanendraGurung
New Contributor III

I am trying to figure out:

a. How to reset the properties in the dockpane when it closes [edited: or close an Add-In]. The following code below with "SaveDirectory" is initialized when I open the dockpane for the first time, then even after closing it and opening several different projects, the value of "SaveDirectory" does not change. How do I do that?

b. I thought of resetting the value inside "UninitializeAsync()" method, but I guess "UninitializeAsync()" method is not used for that. 

Thanks. 

Kenny

 

 

 

namespace Test
{
    internal class TestDockPaneViewModel : DockPane
    {
        private string _saveDirectory;
        /// <summary>
        /// Default Directory to save all user input data.
        /// </summary>		
        public string SaveDirectory
        {
            get { return _saveDirectory; }
            set { _saveDirectory = value; NotifyPropertyChanged(() => SaveDirectory); }
        }        
        /// <summary>
        /// Constructor
        /// </summary>
        protected TestDockPaneViewModel() 
        {
            SaveDirectory = System.IO.Directory.GetCurrentDirectory();
        }
        /// <summary>
        /// Called when the pane is uninitialized.
        /// </summary>
        protected async override Task UninitializeAsync()
        {
		    // Reset Default Save Directory when dockpane closes // 
            SaveDirectory = null;
            await base.UninitializeAsync();
        }	
		 
}

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
GintautasKmieliauskas
Regular Contributor II

Hi,

What do you mean by "Dockpane closing"? By pressing x at the right upper corner you just hide dockpane.

So if it's right place for your reset code, so you can override OnShow Dockpane class method:

protected override void OnShow(bool isVisible)
{
if (!isVisible)
{
SaveDirectory = null;
}
}

UninitializeAsync will be called on ArcGIS Pro closing.

View solution in original post

9 Replies
KirkKuykendall1
Occasional Contributor III

Did you try overriding OnHidden?

GyanendraGurung
New Contributor III

Thanks for the suggestion. I shall look into the OnHidden() method as well. The problem was currently solved by overriding the OnShow() method. I think I will try out the OnHidden() method as well. 

0 Kudos
KirkKuykendall1
Occasional Contributor III

I just noticed where you say "even after closing it and opening several different projects"

I'm not sure if OnHidden gets called when you simply open a different project.  If not, you might also need to subscribe to ArcGIS.Desktop.Core.Events.ProjectOpenedEvent in your PaneViewModel and reset when that event fires too.

GintautasKmieliauskas
Regular Contributor II

Hi,

What do you mean by "Dockpane closing"? By pressing x at the right upper corner you just hide dockpane.

So if it's right place for your reset code, so you can override OnShow Dockpane class method:

protected override void OnShow(bool isVisible)
{
if (!isVisible)
{
SaveDirectory = null;
}
}

UninitializeAsync will be called on ArcGIS Pro closing.

GyanendraGurung
New Contributor III

1. By "Dockpane closing", I meant to close the Dockpane of the Add-In. 

2. Overriding the OnShow() method, as you have shown, solved the problem.

 

0 Kudos
KarthikAditya
New Contributor III

The OnShow method is called not only when the DockPane is opened or closed but also when it's auto hidden - collapsed into the non-client area.

Is there a way to distinguish when the DockPane is closed (by clicking X at top right corner) and when its auto-hidden?

0 Kudos
GintautasKmieliauskas
Regular Contributor II

Hi,

Code behind of Dockpane is based on UserControl so you can’t listen OnClosing event or something similar.

I have attached modified ArcGIS Pro SDK community sample (ContentFileExplorer). This is not brilliant solution which needs many different techniques in code behind and mvvm.

But it works (I think)

0 Kudos
KarthikAditya
New Contributor III

Hi, thank you for your sample. It works and can distinguish when dock pane is closed and when its auto-hidden. 

But, it fails when the 'Auto-hide' (pin symbol) button is clicked. i.e. When the pane is opened, and auto-hide button is clicked, the message box shows 'x'. But it shouldn't?

0 Kudos
GintautasKmieliauskas
Regular Contributor II

Hi,

I don't use that code and didn't check all cases;. I only wanted to show you the way how to do your task.

Try to save previous state of dockpane and check if it changes. then do not react.

0 Kudos