Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a WPF MVVM project where i have a user control which displays some statistics. This user control is embedded in the listbox. usually i load around 400 to 500 objects of user control in the listbox. As i load around 400 to 500 instances of user control it usually takes more time to load. Now i want to load items which are present in the view.

Note: i can not use VirtualizingPanel.VirtualizationMode because as per client requirement the items should not display one below another. He wants it to be like grid. To achieve this i am using wrap panel inside items panel of listbox.

Listbox code:
<ListBox Name="lvDataBinding"  SelectionMode="Single" ItemsSource="{Binding AllTiles}" VirtualizingPanel.VirtualizationMode="Recycling">
                <ListBox.ItemsPanel >
                    <ItemsPanelTemplate>
                        <WrapPanel Width="{Binding (FrameworkElement.ActualWidth), 
                        RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}">
                        </WrapPanel>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <custom:TileControl Margin="10" DataContext="{Binding}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style>
                        <Style.Resources>
                            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                             Color="Transparent"/>
                        </Style.Resources>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.ContainerStyle>
                            <Style TargetType="{x:Type GroupItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate>
                                            <Expander Header="{Binding}" IsExpanded="True">
                                                <Expander.HeaderTemplate>
                                                    <DataTemplate>
                                                        <StackPanel Orientation="Horizontal" Background="Transparent">
                                                            <TextBlock Text="{Binding Name}" TextBlock.FontSize="20" />
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </Expander.HeaderTemplate>
                                                <ItemsPresenter />
                                            </Expander>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </GroupStyle.ContainerStyle>
                    </GroupStyle>
                </ListBox.GroupStyle>               
            </ListBox>


How can i draw items which are present in view?
As it violates my company policy i can not add complete source code.

What I have tried:

Tried virtualizing panel property but it will work only if the panel is stack panel
Posted
Updated 7-Mar-17 23:18pm
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900