AvalonDock 2 / Prism 4 : how to handle close event?

Topics: Prism v4 - WPF 4
May 20, 2013 at 10:32 PM
I want to handle close event of document pane in order to remove the closed view from the prism region. How could i do that?
May 21, 2013 at 7:00 PM

Based on my understanding, the close event is raised in your View, so you will need to tell your ViewModel that you want to handle it and remove the closed View. In order to do that, you can use the InvokeCommandAction from Prism, which executes a command whenever the desired event is raised. The following code is an example on how to use InvokeCommandAction in your View. Based on your scenario, your EventName will be the close event of the document pane, and the binding of the Command will be the command from your ViewModel which will remove the View from the prism region.
      <i:EventTrigger EventName="MyEventName">
           <prism:InvokeCommandAction Command="{Binding MyCommand}" />
Take into account that InvokeCommandAction does not receive any parameter. Therefore, if you need to pass EventArgs to the command, you can use MVVM Light Toolkit, which provides an EventToCommand event trigger that lets you pass EventArgs as a command parameter.

Hope this helps,

Federico Martinez