AvalonDock icon indicating copy to clipboard operation
AvalonDock copied to clipboard

LayoutAnchorable closeable but "CanClose" is False

Open jogibear9988 opened this issue 6 years ago • 6 comments

i use this code:

 <avalondock:LayoutAnchorable x:Name="Tree" Title="Project Explorer" CanClose="False">

but it still shows the close button

jogibear9988 avatar Sep 03 '19 12:09 jogibear9988

Yes, this does not work for me either. The only thing that does work is this:

Set CanHide=False in MlibTest.MainWindow.xaml (at about Line 147) <Setter Property="CanHide" Value="False" />

Ensure that the MLibTest.Demos.LayoutInitializer class contains this line anchorableToShow.CanDockAsTabbedDocument = false;

in the method BeforeInsertAnchorable definition

        public bool BeforeInsertAnchorable(LayoutRoot layout,
                                           LayoutAnchorable anchorableToShow,
                                           ILayoutContainer destinationContainer)
        {
            // AD wants to add the anchorable into destinationContainer
            // just for test provide a new anchorablepane 
            // if the pane is floating let the manager go ahead
            LayoutAnchorablePane destPane = destinationContainer as LayoutAnchorablePane;
            if (destinationContainer != null &&
                destinationContainer.FindParent<LayoutFloatingWindow>() != null)
                return false;

            var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "ToolsPane");
            if (toolsPane != null)
            {
                // do not allow this as Tabbed Document
                anchorableToShow.CanDockAsTabbedDocument = false;
                toolsPane.Children.Add(anchorableToShow);
                return true;
            }

            return false;

        }

Now, the close button is not shown and only AutoHide is available. There is also a realated issue here: https://github.com/xceedsoftware/wpftoolkit/issues/1500#issuecomment-527164771

I'll ask Boris if he can suggest a default value or change in the serialization behavior to get this fixed...

Dirkster99 avatar Sep 03 '19 16:09 Dirkster99

Hi Guys, in our project commenting out _canClose = false in LayoutAnchorable's constructor was the solution in particular with deserialization of CanClose property. We want to be able to close 'anchorables' so showing close button is desired. I haven't investigated the case when we don't want close button.

bdachev avatar Sep 03 '19 21:09 bdachev

Further to my previous post it turned out that I am wrong and reverting _canClose to true does not help. We have other issues due to the fact that the anchorable is completely closed instead of only hidden. So I reverted my previous fix and now _canClose = false for anchorables. I also fixed the serialization code in the base class introducing new field _defaultCanClose which is true for documents and false for anchorables and serialization now checks against that field in order to properly work in both cases.

bdachev avatar Sep 19 '19 07:09 bdachev

@jogibear9988 @bdachev The project just received a pretty cool resolution from @skyneps via issue #182 and Pr #183. The PR ensures that the Hide (X) button is shown instead of the Close (X) button when CanClose=False. The all but obvious fix was to overide the default value of the CanClose dependency property in LayoutAnchorableItem 👍 to @skyneps

Can you guys please check if this resolves this issue also (I think it does)?

Dirkster99 avatar Jul 29 '20 19:07 Dirkster99

Hi @Dirkster99, in our fork we have similar fix for CanClose property but directly in LayoutAnchorable and LayoutContent code as it also has impact on XML serialization. I can try to prepare PR with that change if you like but not sure when will have some time to do it.

bdachev avatar Jul 30 '20 08:07 bdachev

Hi @bdachev I'd like to see your fix - maybe its faster on your side if you ust copy/paste the relevant code section you changed with an explaination of the issue fixed and whether your change should be done without PR #183 or not?

Dirkster99 avatar Jul 30 '20 15:07 Dirkster99