locked
Data virtualization is broken when using a DataTemplateSelector RRS feed

  • Question

  • Utilizing different data templates through a data template selector, setting the ItemTemplateSelector in a GridView, seem to break virtualization and I have not found a solution to this since having a fixed size of the root element in all data templates and even the item container style made no difference.

    Suggestions?

    Thanks!

    Tuesday, June 26, 2012 9:26 AM

All replies

  • After some more investigation I have found...

    Setting a fixed size for the item container does not help, virtualization is still broken.

    However...

    Using an ItemTemplate containing nothing but a ControlControl that in turn has the same DataTemplateSelector applied to it seems to work (but not a ContentPresenter)?

    Sample:

            <styles:ResourceTemplateSelector x:Key="ResourceTemplateSelector" FolderDataTemplate="{StaticResource FolderItemTemplate}" FileDataTemplate="{StaticResource FileItemTemplate}" />

            
            <DataTemplate x:Key="ResourceItemTemplate">
                <ContentControl HorizontalAlignment="Left" Width="250" Height="250" ContentTemplateSelector="{StaticResource ResourceTemplateSelector}" Content="{Binding}" />
            </DataTemplate>

    This might be a workaround but it's more complicate and not as natural as to use the DataTemplateSelector directly on the ItemTemplateSelector property of GridView.

    Saturday, July 7, 2012 8:58 AM
  • hi Joel_F,it's a known issue by design as said in the text:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh994637.aspx


    • Edited by waot Monday, July 9, 2012 6:51 AM
    Sunday, July 8, 2012 3:18 AM
  • I'm doing something similar in one of my apps but I can't confirm the issue you are describing. However, I assume you are using a WrapGrid as the items panel. In that case it might be helpful to specify the ItemHeight and ItemWidth properties of that panel.

    <GridView x:Name="contentGrid"
    		  ItemsSource="{Binding itemsSource}"
    		  ItemTemplateSelector="{StaticResource itemTemplateSelector}">
    	<GridView.ItemsPanel>
    		<ItemsPanelTemplate>
    			<WrapGrid Orientation="Vertical" ItemWidth="250" ItemHeight="250" />
    		</ItemsPanelTemplate>
    	</GridView.ItemsPanel>
    </GridView>

    Sunday, July 8, 2012 8:39 AM
  • Hi, no it's a VirtualizingStackPanel.

    <GridView.ItemsPanel>
    <ItemsPanelTemplate>                        
    <VirtualizingStackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
    </GridView.ItemsPanel>

    Sunday, July 8, 2012 7:45 PM