This is a migrated thread and some comments may be shown as answers.

MVVM data templating not working

3 Answers 85 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Jochen
Top achievements
Rank 1
Jochen asked on 11 May 2015, 10:58 AM

Hello,

we used to use a third-party docking control in our application which had some problems with the RadScheduler control. 
Hence we've decided to exchange it with the RadDocking control, thus getting rid of any problems but the following.

We use a single-window application based on the MVVM pattern. Our window's ViewModel contains a collection of ViewModels and a "CurrentViewModel" property. 
At this time we use the document host functionality only, resulting in the docking control displaying the "current" view via data templates.
Each ViewModel instance has its own view instance, which is required to be able to save the visual state of each view when switching from one view (model) to another. Views get created in a separate ViewCache class that returns either an already cached or a newly-created view.

I've provided a sample so you can easily reproduce the following steps (see attachment, needs to be renamed to *.zip):

1. Click button "Blue":
A blue ViewModel is created and added to the collection of ViewModels. The RadDocking control creates a new RadDocumentPane making use of a custom DockingPanesFactory. 
The related view is created by the view cache via the above-mentioned data templates - getting the blue ViewModel and the blue view's type.
So far everything works fine.

2. Click button "Red":
A red ViewModel is created and added to the collection of ViewModels. Again, the RadDocking control creates a new RadDocumentPane. 
But now something strange is happening: the view cache receives the red ViewModel and the blue view's type, which isn't supposed to happen because no such data template even exists (intermediate state?).
The view cache gets queried a second time immediately, this time with the correct parameters (red ViewModel and red view's type). As an aftereffect the blue view, which was provided in the step before, gets returned by the cache.

3. Click another color button:
Each time another color button is clicked, the same issue occurs.

So why does this "intermediate state" happen? Is this the intended behavior or just a bug?

 

Thanks in advance,

Jochen

3 Answers, 1 is accepted

Sort by
0
Jochen
Top achievements
Rank 1
answered on 11 May 2015, 11:05 AM

Forgot one thing:

Replacing the RadDocking control by a common TabControl results in the expected behavior (can be done by uncommenting the TabControl and commenting the RadDocking control in the given sample).

0
Nasko
Telerik team
answered on 12 May 2015, 02:07 PM
Hi Jochen,

In order to achieve the desired behavior of RadDocking you need to set the IsContentPreserved property of the PaneGroup to True - the default value is False. When this property is set to false when a new Pane is opened the content of the others is unloaded. The idea is that you don't have to preserve content that is not visible at the moment. However, for your concrete scenario if you do not preserve it the constructor could not define properly the current content of the Group and thus that unexpected behavior is observed. You should also need to override the AddPane method of the DockingPanesFactory class in order to be sure the Panes are added to the right PaneGroup whose IsContentPreserved property is set to True.

We have modified your sample project with the described above approach and you could run and evaluate it.

Hopes this helps.

Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Jochen
Top achievements
Rank 1
answered on 13 May 2015, 08:12 AM

Hi Nasko,

that does the trick, thanks a lot!

 

Cheers

Jochen

Tags
Docking
Asked by
Jochen
Top achievements
Rank 1
Answers by
Jochen
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or