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

Virtualization and DataTemplates

2 Answers 195 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 07 Jul 2014, 08:15 AM
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:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Button Click="ButtonBase_OnClick" Grid.Row="0">Click</Button>
        <telerikDocking:RadDocking Grid.Row="1">
            <telerikDocking:RadDocking.DocumentHost>
                <telerikDocking:RadSplitContainer>
                    <telerikDocking:RadPaneGroup x:Name="TheRadPaneGroup">
                        <telerikDocking:RadPaneGroup.ItemTemplate>
                            <DataTemplate>
                                <telerik:RadPane>
                                    <Style TargetType="telerik:RadPane">
                                        <Setter Property="ContentTemplate">
                                            <Setter.Value>
                                                <DataTemplate>
                                                    <!--<userControlEvents:UserControl1></userControlEvents:UserControl1>-->
                                                    <ContentControl Content="{Binding}"></ContentControl>
                                                </DataTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </telerik:RadPane>
                            </DataTemplate>
                        </telerikDocking:RadPaneGroup.ItemTemplate>
                    </telerikDocking:RadPaneGroup>
                </telerikDocking:RadSplitContainer>
            </telerikDocking:RadDocking.DocumentHost>
        </telerikDocking:RadDocking>
    </Grid>

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 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 09 Jul 2014, 03:11 PM
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 - http://www.telerik.com/help/wpf/not-supported-properties.html

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 - http://www.telerik.com/help/wpf/raddocking-features-panes-panesource.html

Hope this helps.

Regards,
George
Telerik
 
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.
 
0
Peter
Top achievements
Rank 1
answered on 18 Aug 2015, 02:00 PM
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.
Tags
Docking
Asked by
Peter
Top achievements
Rank 1
Answers by
George
Telerik team
Peter
Top achievements
Rank 1
Share this question
or