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

Docking/MDI for WPF Forum

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

Hi,

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?

Thanks.

Martin


 

Here is the dock site xaml code of the window:

 

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

                <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}" />
                    </docking:ToolWindow>
                </docking:ToolWindowContainer>


            </docking:SplitContainer>
        </docking:DockSite>

Comments (1)

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

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 (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.