I have the 'How' in brackets because I'm not sure whether I have to do this.
Consider the following:
I have an MVVM application with the AvalonDock control. The control is implemented as follows:
<xcad:DockingManager Grid.Row="1" DocumentsSource="{Binding Workspaces}" Background="White" ActiveContent="{Binding ActiveWorkspace, Mode=TwoWay}">
<xcad:DockingManager.LayoutItemContainerStyle>
<Style TargetType="{x:Type li:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Header}"/>
</Style>
</xcad:DockingManager.LayoutItemContainerStyle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="DocumentClosed">
<cmd:EventToCommand Command="{Binding CloseWorkspaceCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</xcad:DockingManager>
All the bindings work except for the CloseWorkspaceCommand, which is implemented as such:
public RelayCommand CloseWorkspaceCommand
{
get { return _closeWorkspaceCommand ?? (_closeWorkspaceCommand = new RelayCommand(CloseWorkspace)); }
}
void CloseWorkspace()
{
Workspaces.Remove(ActiveWorkspace); RaisePropertyChanged(string.Empty);
}
The RaisePropertyChanged
is for some other unrelated functionality.
Now here's the issue I have. Assume I have open 3 workspaces, let's call them A,B and C.
- If I close A, C closes with it.
- If I close B, C closes with it.
- If I close C, B closes with it.
How should I implement this so that only the tab I've clicked the close button for will close?
I've seen some examples where the underlying collection doesn't remove the workspaces, but in this application, I need to be able to remove closed workspaces as I want some works spaces to only be allowed to be opened once.
Update: This appears to be a problem with working out which TabItem is actually being removed. If the tab that's being closed isn't the selected Item, that's why it removes two of them. The question, is how do I tell it which tab is being closed?