BUG? Docking MVVM features share instance of view?

Docking/MDI for WPF Forum

Posted 13 years ago by SledgeHammer01
Version: 11.1.0543
Platform: .NET 4.0
Environment: Windows 7 (32-bit)
Avatar
I'm using the MVVM features for creating document windows. My ItemsSource is the property:

public ObservableCollection<DocumentViewModelBase> Documents

At this time, I have one type of ViewModel: RangeViewDocVM.

I am mapping RangeViewDocVM -> RangeViewDocCtrl.xaml like this:

<DataTemplate DataType="{x:Type local:RangeViewDocVM}">
<local:RangeViewDocCtrl />
</DataTemplate>

When I add an item to the ItemsSource, everything seems to be created on first glance. Documents are added to the tabbed interface one on top of each other.

HOWEVER, it seems like only a single instance of RangeViewDocCtrl is created (unless I drag the windows around so they are in different docking containers).

This seems like a MAJOR flaw to me since now the RangeViewDocCtrl properties that are internal to the class and not bound to VM properties become shared across ALL the documents.

For example, lets say I have a ListView with column sorting.

Doc1 opens
Doc2 opens

Click Col1 on Doc1, now Doc2 is sorted on Col1
Click Col2 on Doc2, now Doc1 is sorted on Col2

All because they share the same instance of the control and it seems like you are just swapping out data contexts???

Also, going back to the list control or data grid, etc... the column width & arrangement would also be shared across all tabs... VERY weird.


[Modified at 06/24/2011 07:05 PM]

Comments (2)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

This is actually a default behavior of WPF. Our TabbedMdiContainers work just like the native WPF TabControls. They both have a single ContentPresenter, which shows the content of the selected tab. The ContentPresenter has an optimization to reuse the implicit DataTemplate if the underlying Content type did not change. So in essence, the ContentPresenter is just swapping the DataContext as you said.

We have a TODO item marked down to effectively retain the child visuals of the various tabs, which is useful even apart from the MVVM pattern. I've added this forum post to that TODO item so you will be notified when it is completed.

Currently, the only work arounds are to ensure the entire state is in the view-model or wrap each view-model in the appropriate UserControl before adding to DockSite's item sources.


Actipro Software Support

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

We have come up with a work around for this issue, which is described in this post. We will be including this code in the next maintenance release as well as an optional feature.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.