1

I am trying to create a grid containing elements such as

| 1 | 4 | 7 | 
| 2 | 5 | 8 | ===> extend
| 3 | 6 | 9 |

Since the data is very large, I need to use UI virtualization and what I see in most example is the VirtualizingStackPanel

Here is how I have setup my Gridview in XAML . The problem is that the following code creates a horizontal row of single element (which makes sense given it is just a stack panel).

| 1 | 2 | 3 | 4 | .....


        <GridView
        x:Name="itemGridView"
        AutomationProperties.AutomationId="ItemsGridView"
        AutomationProperties.Name="Items"
        TabIndex="1"
        Grid.RowSpan="3"
        Padding="116,136,116,46"
        ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
        ItemTemplateSelector="{StaticResource CellStyleSelector}"
        ItemClick="ItemView_ItemClick"            
        IsItemClickEnabled="True"
        SelectionMode="Extended"
        SelectionChanged="ItemView_SelectionChanged"
        IsSwipeEnabled="true">
        <GridView.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </GridView.ItemsPanel>
    </GridView>

How would one go about making it display a grid that extends horizontally using virtualizingstackpanel? I have no groups in my data so all the examples that show virtualizingstackpanel show this ? I am completely new at Windows Store app dev (mostly have been on iOS and Android ) so would appreciate any code sample or resources.

Thank you

1
  • It looks like the default ItemsPanel of GridView itself is virtualizing. So this question itself is invalid. It looks like Virtualization can get broken due to other conditions (such as grouping etc) Commented Jul 24, 2013 at 21:15

1 Answer 1

1

I think you are doing UI virtualization by implementing your data source to interface ISupportIncrementalLoading. Try WrapGrid, and set MaximumRowsOrColumns.

<GridView
    x:Name="itemGridView"
    AutomationProperties.AutomationId="ItemsGridView"
    AutomationProperties.Name="Items"
    TabIndex="1"
    Grid.RowSpan="3"
    Padding="116,136,116,46"
    ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
    ItemTemplateSelector="{StaticResource CellStyleSelector}"
    ItemClick="ItemView_ItemClick"            
    IsItemClickEnabled="True"
    SelectionMode="Extended"
    SelectionChanged="ItemView_SelectionChanged"
    IsSwipeEnabled="true">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapGrid MaximumRowsOrColumns="3" Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Xyroid. My datasource is actually retrieved in one shot (the actual XML data is not very large to be retrieved but the number of elements could be 1000 and the elements will do lazy load when they are displayed (like retrieve thumb image asynchronously). So my understanding was to use virtualizingStackPanel to display the grid.
Thank you. Let me check those links!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.