xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.87k stars 871 forks source link

AvalonDock CloseEvent MVVM, remove child? #865

Open xceedsoftware opened 7 years ago

xceedsoftware commented 7 years ago

pixipix[CodePlex]
Hello,

I am currently using Avalondock 2.0 with the mvvm pattern. It seems that when you remove an element present in your datasource, the DockManager does not remove the element from the root panel.

Ex: This is how I bind my sources. ltxcad:DockingManager x:Name=quotdockManagerquot DocumentsSource=quot{Binding Workspace.Tools}quot AnchorablesSource=quot{Binding Workspace.Informations}quot ActiveContent=quot{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}quot gt -Tools amp Informations are ObservableCollectionltTgt

How my content is bind ltSelector:PanesTemplateSelectorgt ltSelector:PanesTemplateSelector.ToolViewTemplategt ltDataTemplategt ltGroupBox Content=quot{Binding UserControl, UpdateSourceTrigger=PropertyChanged}quot BorderThickness=quot0quot /gt lt/DataTemplategt lt/Selector:PanesTemplateSelector.ToolViewTemplategt Then how I bind my CloseCommand. ltSelector:PanesStyleSelectorgt

                    ltSelector:PanesStyleSelector.ToolStylegt
                        ltStyle TargetType=quot{x:Type xcad:LayoutItem}quotgt
                            ltSetter Property=quotTitlequot Value=quot{Binding Model.Title}quot/gt
                            ltSetter Property=quotVisibilityquot Value=quot{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}quot/gt
                            ltSetter Property=quotCloseCommandquot Value=quot{Binding Model.CloseCommand}quot/gt
                        lt/Stylegt
                    lt/Selector:PanesStyleSelector.ToolStylegt

Now when I click on the 'X' button, I will remove my tool panel from my ObservableCollectionltTgt like this.

internal void Close(PaneViewModel fileToClose) { if (fileToClose.IsDirty) { /// }

        var workingScreen = fileToClose as ToolViewModel;
        if (workingScreen != null)
        {
            Tools.Remove(workingScreen);
        }
    }

I tried something I put a timer on my workingScreen and I could noticed that:

Event if the WorkingScreen is removed from the OBSCltTgt the timer is still working. The UserControl present in the OBSCltTgt is never collected.

Is there a way to ask to the DockManager to remove the Child related the ClosingScreen when I remove it from the ObservableCollectionltgt?

I do not have access to the DockPanelRoot, I am working in MVVM.

Regards,

xceedsoftware commented 7 years ago

pixipix[CodePlex]
Sorry for the inconvenient. My timer was causing the memory leak :/

xceedsoftware commented 7 years ago

pixipix[CodePlex]
Sorry I would have to move it on Discussions and not Issues :/