views:

126

answers:

1

Im using WPFToolkit datagrid control and do the binding in such way:

<WpfToolkit:DataGrid x:Name="dgGeneral" SelectionMode="Single"
                              SelectionUnit="FullRow"
                              AutoGenerateColumns="False"
                              CanUserAddRows="False"
                              CanUserDeleteRows="False" 
                              Grid.Row="1"  ItemsSource="{Binding Path=Conversations}" >


public List<CONVERSATION> Conversations
        {
            get { return conversations; }
            set
            {
                if (conversations != value)
                {
                    conversations = value;
                    NotifyPropertyChanged("Conversations");
                }
            }
        }  

public event PropertyChangedEventHandler PropertyChanged; 

public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

public void GenerateData()
         {
            BackgroundWorker bw = new BackgroundWorker();

            bw.WorkerSupportsCancellation = bw.WorkerReportsProgress = true;
            List<CONVERSATION> list = new List<CONVERSATION>();

            bw.DoWork += delegate { list = RefreshGeneralData(); };

            bw.RunWorkerCompleted += delegate
                                         {
                                             try
                                             {
                                                 Conversations = list;
                                             }
                                             catch (Exception ex)
                                             {
                                                 CustomException.ExceptionLogCustomMessage(ex);
                                             }

                                         };

            bw.RunWorkerAsync();
        }


And than in the main window i call GenerateData() after setting DataCotext of the window to instance of the class, containing GenerateData().

RefreshGeneralData() returns some list of data i want and it returns it fast.
Overall there are near 2000 records and 6 columns(im not posting the code i used during grid's initialization, because i dont think it can be the reason) and the grid hangs for almost 10 secs!
---
PS i found the project, that is written in similar way, but even binding of 50000 records is done without UI hang there! What am i doing wrong?
UPDATE i think that's because of ScrollViewer, which contains the whole grid in it. But why?

+1  A: 

Unless you explicitely disable it, the items in the DataGrid are virtualized, i.e. only the items currently shown are rendered. You might be having a problem due to UI Automation (this was fixed in .NET 4). See http://wpf.codeplex.com/Thread/View.aspx?ThreadId=41964

This can happen if you have a Wacom tablet or a screen reader installed.

Daniel Rose
No..I use .NET4 Client Profile and just regular PC.
nihi_l_ist
Hmm. Perhaps you could post more of the code? Particularly the complete XAML of the DataGrid. Does the hang happen after you assign the data (the `Conversations = list;` part). Are you sure that you are assigning it only once and the data doesn't change afterward?
Daniel Rose
I'm assigning only once and hang happens right after Conversations = list;
nihi_l_ist
You may need to look into data virtualization as well.
Jeff Wilcox