Using DocumentItemsSource (MVVM), how to destroy project when clicking the x

Docking/MDI for WPF Forum

Posted 10 years ago by Martin Deslongchamps - Software Specialist, SES
Version: 14.2.0611


We are using the mvvm approach with the dock site. We make a binding on DocumentItemsSource to a DeferrableObservableCollection in the view model of the main window.

Then in the constructor of the window, we take a handler on the CollectionChanged to be notified of any activity in the collection.

When we hit the [x] button on the DocumentWindow, the window disappears but the collection is never modified.

Why? Is the DocumentWindow only deactivated? How to close the document window and make sure it's destroyed?




Here is the dock site xaml code of the window:


        <docking:DockSite x:Name="dockSite"
                          themes:ThemeManager.Theme="{Binding ElementName=window, Path=(themes:ThemeManager.Theme)}"
                          DocumentItemsSource="{Binding Projects, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                          DocumentItemContainerStyle="{StaticResource DocumentItemStyle}"
                <DataTemplate DataType="{x:Type projVM:ProjectInstanceViewModel}" >
                    <projView:ProjectInstanceView />
            <docking:SplitContainer Orientation="Horizontal">
                <docking:Workspace >
                    <docking:TabbedMdiHost x:Name="tabbedMdiHost" IsCloseButtonOnTab="True" CanDocumentsCloseOnMiddleClick="True"/>

                <docking:ToolWindowContainer Width="300" >
                    <docking:ToolWindow Title="Properties" CanClose="False" x:Name="PropertiesPnl">
                        <!-- Property View -->
                        <ContentControl Name="PropertiesInterface" 
                                        prism:RegionManager.RegionName="{x:Static inf:RegionNames.PropertiesRegion}" />


Comments (1)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Martin,

That is correct, as we don't modify the source collection.  It would be up to you to watch an event like WindowClosed and if it is a DocumentWindow, remove the related item from your source collection.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.