How to determine the closed documentwindow in mvvm?

Docking/MDI for WPF Forum

Posted 3 years ago by Michael Bayer
Version: 16.1.0633
Avatar

Hi,

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)
    Get
        Return _documentWindows
    End Get
End Property

 

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

...
</docking:DockSite>

 (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

Michael

Comments (2)

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

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 3 years ago by Michael Bayer
Avatar

Hi,

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

Thank you.

The latest build of this product (v2018.1 build 0675) 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.