Click here to Skip to main content
15,891,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i hopefully have a simple question for most of you. Since 3 weeks
i am developing my first WPF application. I am using a Datagrid
with an ListCollectionView as Itemsource. The Collection
has approximatly 500-600 items. Each item has about 7 properties
which i am displaying in the grid.
My problem is when i load the data into the grid, my whole gui
freezes for about 1-2 seconds. The same happens if i apply any filter
to the Collection.
For me this seems really weird because 500 items is not very much, and
regarding to microsoft the rendering time of the control only increases
with a lot of items > 10000 and a lot of properties > 1000.

Is there any possibility to let the control render its content in a
different thread than the main UI Thread, or what can i do to avoid
freezing the gui.

Thanks in advance
Manu
Posted
Comments
fct2004 31-Mar-12 22:46pm    
Do any of those properties lead to things like images because that can really slow things down. Are you doing anything that may disable UI virtualization? Why aren't you binding it an ObservableCollection?

Hi Seems that you aren't using Binding. I have had same problem and I solved it by using Binding.

Look at the example - How to Navigate, Group, Sort and Filter Data in WPF[^]

Note: Grouping disables virtualization! This can bring huge performance issues on large data sets. So be careful when using it.(from the same source)


I had serious problem with "virtualization memory leak" when I used regular data binding. Than I used DataTemplate and all performance problems are gone. Take a look at my code sample. Also you can try to check if there are no items drawed out of screen by overriding "OnRender" method.
List in my program can hold > 500000 items.
SingleVisualTemplate is custom control derived from FrameworkElement. AFAIK using DataTemplate may help.


HTML
<Setter Property="ItemTemplate">
    <Setter.Value>
        <DataTemplate>
            <sve:SingleVisualTemplate
                Scale="{Binding Scale}"
                Gain="{Binding Gain}"
                State="{Binding State, Mode=TwoWay}"
                SingleBitView="{Binding SingleBitView, ElementName=local}"
                MouseUp="svt_MouseUp"
                MouseDown="svt_MouseDown"
                />
        </DataTemplate>
    </Setter.Value>
</Setter>


Sorry for my English.
Roman
 
Share this answer
 
v5
Comments
m.bleimuth 1-Apr-12 8:04am    
please have a look at solution 2 there is my current XAML and C# Code that
I am using for binding.
Thats my XAML code for the datagrid:

XML
<DataGrid AutoGenerateColumns="false" CanUserAddRows="False" Grid.Row="2" VirtualizingStackPanel.VirtualizationMode="Standard" IsSynchronizedWithCurrentItem="True" Name="dgStartlists">
    <DataGrid.Resources>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Padding" Value="2"/>
            <Setter Property="BorderThickness" Value="0.5"/>
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="FontSize" Value="14"/>
        </Style>
    </DataGrid.Resources>

    <DataGrid.Columns>
        <DataGridTextColumn Header="Competitor" Width="120" Binding="{Binding Competitor}" CanUserSort="False" IsReadOnly="True"/>
        <DataGridTextColumn Header="Race" Width="110"  Binding="{Binding Race}" IsReadOnly="True" CanUserSort="False"/>
        <DataGridTextColumn Header="Run" Binding="{Binding Run}" Width="30" FontSize="12" />
        <DataGridTextColumn Header="Pos" Binding="{Binding Startposition}" Width="30" FontSize="12"/>
        <DataGridTextColumn Header="Bib" Binding="{Binding Bib}" Width="30" FontSize="12"/>
        <DataGridTextColumn Header="Heat" Binding="{Binding Heat}" Width="35" FontSize="12" />
        <DataGridCheckBoxColumn Header="Pending" Binding="{Binding Pending}" Width="60" />
        <DataGridComboBoxColumn Header="State" Width="50" ItemsSource="{Binding Source={StaticResource ResourceKey=StateEnum}}" SelectedItemBinding="{Binding State}"/>
        <DataGridTextColumn Header="Class" Binding="{Binding Classname}" Width="80" FontSize="12" />
        <DataGridTextColumn Header="Start Time" Binding="{Binding Starttime, StringFormat=H:mm:ss}" Width="80" FontSize="12" />
    </DataGrid.Columns>
</DataGrid>



Thats my C# Code:

C++
private ListCollectionView _cventries;

public dcStartlists()
{
  InitializeComponent();
}

#region Usercontrol load/unload

private void dcStartlists_Loaded(object sender, RoutedEventArgs e)
{
    if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
        return;

    _cventries = new ListCollectionView(App.Competition.Entries);
    dgStartlists.ItemsSource = _cventries;
}

private void SetFilter()
{
   _cventries.Filter = obj => ((Entry)obj).Run == 1;
}


App.Competition.Entries is an ObservableCollection with about 500-600 items. I am using the ListCollectionView because i need to filter my data.

When the control loads first time my GUI freezes for about 1-2 sec, and when I am calling the SetFilter Function the GUI also freezes. I think its no virtualisationproblem or something like that, maybe i do something wrong by setting the itemsource?
 
Share this answer
 

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