DataTable placed in a DataGrid freezes when scroll reaches bottom

  • Thread starter Thread starter SebiXDDX
  • Start date Start date
S

SebiXDDX

Guest
I need to generate a table in a wpf window from a tex file. Workflow:

Click button --> pick, open and read file --> parse file --> create table --> update data grid with table view

Code:


private void OpenTexButton_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".tex";
dlg.Filter = "TEX Files (*.tex)|*.tex|Text Files (*.txt)|*.txt";

Nullable<bool> result = dlg.ShowDialog();

// Get the selected file name and display in a TextBox
if (result == true)
{
// Open document
string fileName = dlg.FileName;
RenderTexAsync(fileName);
}
}

private async void RenderTexAsync(string fileName)
{
byte[] result;

using (FileStream SourceStream = File.Open(fileName, FileMode.Open))
{
result = new byte[SourceStream.Length];
await SourceStream.ReadAsync(result, 0, (int)SourceStream.Length);
}

string content = System.Text.Encoding.ASCII.GetString(result);
ParseTable(content);
}

private void ParseTable(string content)
{
DataTable dataTable = InitializeTable(table);
// Set binding
appliedJobs.ItemsSource = dataTable.AsDataView();
}



xml:

<DataGrid Name="appliedJobs" Background="#50000000" Grid.Row="1" Grid.Column="1" Margin="10,10,10,10" ItemsSource="{Binding dataTable, IsAsync=True}" AutoGenerateColumns="False" />


Setting IsAsync to true produces a table with empty rows; setting it to false produces the correct table, but upon scrolling

down to the end, the UI freezes. The UI should be updated asynchronously with the newly created table.

How can I make it async?

Continue reading...
 
Back
Top