I am using wpf datagrid to display large amounts of data (around 100 columns and 1000 rows). The columns are bound to properties dynamically added using typedescripter. By default the datagrid shows all the column however we have added functionality that allows user to only see subset of all columns and they can also change the order of displayed columns. I am currently achieving this by toggling the visibility property of the columns and changing their displayindex. However the performance of doing so really sucks.

Below is an example to reproduce the issue

The XAML looks pretty straight forward

<Window x:Class="WpfDataGridTestApplication.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    WindowState="Maximized">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Height="Auto" Margin="5">
        <CheckBox x:Name="ApplyColumns" Width="200" Margin="5" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked">Show Predefined Columns</CheckBox>
    </StackPanel>
    <DataGrid 
        x:Name="Grid" EnableColumnVirtualization="False"
         EnableRowVirtualization="False"
        Grid.Row="1" SelectionUnit="Cell"
        ItemsSource="{Binding MyDataView}">
    </DataGrid>
</Grid>

The code behind is as follows

    public partial class MainWindow : Window
{
    /// <summary>
    /// this dictionary stores the column name of columns to display and their displayIndex
    /// </summary>
    Dictionary<string,int> _predefinedColumns=new Dictionary<string, int>()
                                                  {
                                         
Edit
Report