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?
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.