MVVM data templating not working

4 posts, 0 answers
  1. Jochen
    Jochen avatar
    7 posts
    Member since:
    Oct 2014

    Posted 11 May 2015 Link to this post


    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,


  2. Jochen
    Jochen avatar
    7 posts
    Member since:
    Oct 2014

    Posted 11 May 2015 Link to this post

    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).

  3. DevCraft banner
  4. Nasko
    Nasko avatar
    556 posts

    Posted 12 May 2015 Link to this post

    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.


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

  5. Jochen
    Jochen avatar
    7 posts
    Member since:
    Oct 2014

    Posted 13 May 2015 in reply to Nasko Link to this post

    Hi Nasko,

    that does the trick, thanks a lot!




Back to Top