We are currently using the tabcontrol with IsContentPreserved="true". This works beautifully at preserving the viewmodels, that is until we drag the tabs to re-order them. When the tabs are reordered the tab being dragged loses it content and the viewmodel is recreated. As a result a user loses all their data etc.
Background
- We are utilising the CINCH V2 MVVM framework which makes use of MEF as a viewmodel locator
- Our viewmodels are all set to non-shared (in MEF) and are set to the views datacontext via
meffed
:ViewModelLocator.ViewModel="{x:Static ViewModels:ViewModelKeys.MainWindowViewModel}"
- Our tabcontrol has it's item source bound as ItemsSource="{Binding Views}"
- We dynamically add tabs programmatically via
var workspace = new ValidatingAwareWorkspace(null, viewToDisplayInTab, workspaceDataParameter, tabLabel, true);
Views.Add(workspace);
- This also uses MEF to determine which view to display via the key "viewToDisplayInTab" and displays that view on the tab via the following datatemplate
<DataTemplate DataType="{x:Type CinchV2:WorkspaceData}">
<AdornerDecorator>
<Border HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="2"
CinchV2:NavProps.ViewCreator="{Binding}"/>
</AdornerDecorator>
</DataTemplate>
What i'm after:
I understand that there are obviously a lot of factors at play here that could be breaking the IsContentPreserved when reordering tabs but i thought i would post here to see if you guys have any ideas because it only breaks when i set AllowDragReorder to true
Thanks,
Brock