How to determine the closed documentwindow in mvvm?

Docking/MDI for WPF Forum

Posted 6 years ago by Michael Bayer
Version: 16.1.0633


according to your mvvm samples I've created a test application using the docking control. The application contains a few viewmodels that inherits from a class called DocumentWindowViewModelBase (not of further interest).

The application also contains a DeferrableObserableCollection called _documentWindows and a property GetDocumentWindows, that is the binding source for the DockSite:

Private _documentWindows As New DeferrableObservableCollection(Of DocumentWindowViewModelBase)()

Public ReadOnly Property GetDocumentWindows() As IList(Of DocumentWindowViewModelBase)
        Return _documentWindows
    End Get
End Property


<docking:DockSite x:Name="dockSite"
    DocumentItemContainerStyle="{StaticResource DocumentWindowStyle}"
    DocumentItemsSource="{Binding GetDocumentWindows}"
    WindowsClosing="{dxmvvmb:DXEvent Handler='OnWindowsClosing (@args)'}">


 (I'm using the DevExpress MVVM Framework as you can see in the line WindowsClosing).


In the method OnWindowsClosing, which will be accomplished when a docking window is closed, I want to determine the underlying viewmodel of the closed window. For instance, I have three viewmodels: "vm1", "vm2" and "vm3". Adding them to  _documentWindows, I see three DocumentWindows: "Window A" based on "vm1, "Window B" based on "vm2" and "Window C" based on "vm3".

Imagine, the user closes "Window C" (which mustn't be the active window) via the X - Icon. How can I access the underlying viewmodel "vm3"? I can't see a connection between DocumentWindow and the viewmodel.

Thanks in advance


Comments (2)

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

Hi Michael,

Docking windows are ContentControls and thus when used in a MVVM scenario, the DocumentWindow.Content would be your view model.

Actipro Software Support

Posted 6 years ago by Michael Bayer


great. That works fine. You did a great job.

Thank you.

The latest build of this product (v22.1.4) was released 25 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.