I figured out a solution to get the current FlowDocumentViewModel for the corresponding SpokenViewModel for a NonSharedobject. After the TabItem is added to the Collection it causes a OnItemsChanged(NotifyCollectionChangedEventArgs e) event. And here is where I search for the Composite View to obtain the the Model:
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
{
base.OnItemsChanged(e);
.
..
...
if (e.Action == NotifyCollectionChangedAction.Add && SelectNewTabOnCreate)
{
SpokenTabItem tabItem = (SpokenTabItem)this.ItemContainerGenerator.ContainerFromItem(e.NewItems[e.NewItems.Count - 1]);
SelectedItem = tabItem;
SpokenTabPanel itemsHost = Helper.FindVirtualizingTabPanel(this);
if (itemsHost != null)
{
itemsHost.MakeVisible(tabItem, Rect.Empty);
SelectedReferenceState selectedReferenceState = tabItem.SelectedReferenceState;
selectedReferenceState.contentControl = LogicalTreeHelper.FindLogicalNode(tabItem, "FlowDocumentDetails") as ContentControl;
if (selectedReferenceState.contentControl != null)
{
selectedReferenceState.flowDocumentReader = FindVisualChild<FlowDocumentReader>(selectedReferenceState.contentControl);
selectedReferenceState.flowDocumentFilter = Parameters.FlowDocumentChangedEvent;
IEventAggregator eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
eventAggregator.GetEvent<FlowDocumentChangedEvent>().Publish(selectedReferenceState);
}
}
tabItem.Focus();
}
...
..
.
}
..then I execute an Event for the SpokenViewModel and update the reference to the FlowDocumentViewModel:private void OnFlowDocumentChangedEvent(SelectedReferenceState parameter)
{
.
..
...
FlowDocumentView myFlowDocumentView = TreeHelper.FindVisualChild<FlowDocumentView>(parameter.contentControl);
this.flowDocumentViewModel = myFlowDocumentView.ViewModel;
this.SelectedReferenceState = parameter;
this.flowDocumentViewModel.ReadReference(selectedReferenceState);
...
..
.
}
:) Any suggestion?