Select to view content in your preferred language

Hide/Close dock pane when creating or moving to new project from an existing one

793
5
08-30-2023 01:22 AM
GISNewbieDev
Emerging Contributor

 

Hi,

It seems dock pane is sticky and seems to remain opened after opening it once. It will remain still open when creating a new project when an existing project is opened (so basically when moved from opened to a new project). 

In my use case my dock pane will be opened when certain feature layers are added to the map. If not then the dock pane button will be disabled using state/condition. So for example I have created a project for the first time and added all the required layers to the map which will enable the button to open the dock pane. But now if I will create or move from that project and create a new one which will definitely not having the required layers. As per the implementation the button is disabled. But the problem is the dock pane is already opened besides the usual dock panes like Attributes, Catalog etc. 

I tried to check my condition and then try to hide the dock pane but it is still there.

FrameworkApplication.DockPaneManager.Find("MyDockpaneId")?.Hide();

What is the best way to hide or close the dock pane in this use case?

@Wolf  @GKmieliauskas @CharlesMacleod 

Tags (1)
0 Kudos
5 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

I am trying to catch project closing event in dock pane code:

        /// <summary>
        /// Override to implement custom initialization code for this dockpane
        /// </summary>
        /// <returns></returns>
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            ProjectClosingEvent.Subscribe(OnProjectClosing);
        }

And on project closing execute code below:

        private Task OnProjectClosing(ProjectClosingEventArgs args)
        {
            // if already cancelled, ignore
            if (args.Cancel)
                return Task.CompletedTask;

            var vm = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
            if (vm != null) vm.Hide();

            return Task.CompletedTask;
        }
0 Kudos
GISNewbieDev
Emerging Contributor

But in the project closing I will not know whether the project we are opening contains the required layers in the active map since that will be the condition to hide the dock pane. If we are creating a new project in that case it will work since we know there will be no layers. But if we are opening the existing project then this will not work. And also I will know whether the project contains the required layers after the map is initialized since that logic to know is written in ActiveMapViewChangedEvent. Since project related event will be triggered before ActiveMapViewChangedEvent therefore also at the time of project related event is triggered I will not have that info to know which are layers are in the map.

@GKmieliauskas 

0 Kudos
GKmieliauskas
Esri Regular Contributor

I catch project open event In addin module.

In project opening event handler I initiate DrawCompleteEvent catching

In DrawCompleteEvent handler I stop DrawCompleteEvent catching and reload layers from toc where I need.

0 Kudos
GISNewbieDev
Emerging Contributor

I couldnt understood @GKmieliauskas 

0 Kudos
GKmieliauskas
Esri Regular Contributor

I wrote how to get info which layers are in the map when project loads

0 Kudos