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

446
5
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

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

5 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

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

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