Virtualization and DataTemplates

3 posts, 0 answers
  1. Peter
    Peter avatar
    10 posts
    Member since:
    Apr 2014

    Posted 07 Jul 2014 Link to this post

    Hi, does the RadDocking control use virtualization? And can I disable it? To be more specific, after a user action, I add a new Pane to a PaneGroup and set its Content and DataContext to a new ViewModel. In my App.xaml, I have a DataTemplate so that this ViewModel is shown as a certain UserControl. This works great, except that the UserControl is being reused. I can see that because I'm only entering the constructor once. Subsequent adds of ViewModels won't add new UserControls.

    My real situation is a little more complex (an MVVM pattern, and a command I need to execute when each UserControl is loaded), but you can reproduce it with this setup:

            <Button Click="ButtonBase_OnClick" Grid.Row="0">Click</Button>
            <telerikDocking:RadDocking Grid.Row="1">
                        <telerikDocking:RadPaneGroup x:Name="TheRadPaneGroup">
                                        <Style TargetType="telerik:RadPane">
                                            <Setter Property="ContentTemplate">
                                                        <ContentControl Content="{Binding}"></ContentControl>

    Putting the UserControl explicitly in the DataTemplate (and no longer relying on the App.xaml) makes no difference. Putting x:Shared="False" on the Style and/or the DataTemplate makes no difference either.

    From what I've read on the interent, this has to do with Virtualization. Is there a way to disable this?

    I've made a simple project and put it here. You can see a new ViewModel is added every time (because the milliseconds change for every RadPane that is added), but the second piece of text (the current date, with seconds) does not change, so the UserControl is being reused. I want it to create a new UserControl every time.
  2. George
    George avatar
    1332 posts

    Posted 09 Jul 2014 Link to this post

    Hi Peter,

    The RadPaneGroup doesn't support ItemTemplate property and we would not suggest using it. You can find the full list of not supported properties -

    RadDocking control doesn't support virtualization and the MVVM scenarios are handled differently from the traditional WPF way. Please, refer to the following online articles which describes how to achieve this scenario -

    Hope this helps.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
  3. Peter
    Peter avatar
    10 posts
    Member since:
    Apr 2014

    Posted 18 Aug 2015 in reply to George Link to this post

    In the meantime, I've changed to using the PanesSource property and I also use the PanesFactory (custom implementation). Even then, controls/templates are still re-used. That's why I now wrap the item I want to show in a UserControl first. This seems to force WPF to create a new instance of my template everytime.
Back to Top