I'm having a problem with my ListView/GridView. In fact, my grid has 285 rows, and 24 columns constructed dynamically.
My grid was so slow then I decided to do some other tests directly in XAML (which theorically should be more efficient). All the columns have a CellTemplate.
You can easily reproduce the issue with this :
<Window x:Class="WpfApplication2.HighColumns"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="HighColumns" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="myCellTemplateMonth">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
<TextBlock Grid.Column="0" Text="{Binding}"/>
</Border>
<Border Grid.Column="1" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
<TextBlock Grid.Column="0" Text="{Binding}"/>
</Border>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<ListView Background="Transparent" BorderThickness="0" Name="lv2" Grid.Column="1">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView x:Name="gv1">
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
<!--<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
<TextBlock Grid.Column="0" Text="{Binding}"/>
</Border>
<Border Grid.Column="1" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
<TextBlock Grid.Column="0" Text="{Binding}"/>
</Border>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>-->
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
<GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
</GridViewColumn>
</GridView>
</ListView.View>
<sys:DateTime>1/2/3</sys:DateTime>
<sys:DateTime>4/5/6</sys:DateTime>
<sys:DateTime>7/8/9</sys:DateTime>
<sys:DateTime>10/11/12</sys:DateTime>
[paste the previous 4 ligns here in order to have around 300 rows]
</ListView>
</Grid>
You can see a "double column" style in each column (with a little graphic bug, but don't pay attention to this fact).
The main issue here is the SLOW of the grid, it's clearly not usable as a professional grid... I tried to active virtualization, and to disable it (when virtualization is disabled, it takes around 17-18 seconds to load the grid...)
Is there some tricks to achieve a high speed grid or something I'm doing wrong ? I was first using the WPF Toolkit Datagrid (I use WPF 3.5 with Windows XP) and I got the same issue so as I only want display of data (and no edition at all), I got back to the "old fashioned" ListView with GridView inside... with no effect IMHO..
Thanks !
EDIT 1 : It seems that I've reached the maximum of a WPF GridView performance possibility... The example written before is just a "simple" list... Consider that I bind not just string but a dictionary and a complex structure. In addition, All this WPF Application is a Class Library, Launched by a VSTO Add-in.
Conclusion : The gridview is unusable as is... and loads in 22 seconds when I disable the virtualization.
It seems that I'll have to use a WinForm DataGridView into my WPF Window... Do you think the problem could be solved using this ?