English 中文(简体)
wpf 工具包数据网
原标题:wpf toolkit datagrid performance
  • 时间:2009-11-06 09:07:18
  •  标签:

i 正在把我的申请从窗户表格上传给计生基金。 我发现,数据网只能通过WPF工具包提供。 然而,我有一些业绩问题。 这可能是因为在窗户表格中行使right权的情况并不大,因为必须区别对待。 不管怎样,我也这样做:

// XAML
<toolkit:DataGrid x:Name="dataGrid" ItemsSource="{Binding Path=.}"/>


// C#
DataTable dataTable = new DataTable();
MyViewModel viewModel = new MyViewModel();

 this.dataGrid.AutoGenerateColumns = false;
 this.dataGrid.CanUserAddRows = false;
 this.dataGrid.CanUserDeleteRows = false;
 this.dataGrid.CanUserReorderColumns = true;
 this.dataGrid.CanUserResizeColumns = true;
 this.dataGrid.CanUserResizeRows = false;
 this.dataGrid.CanUserSortColumns = true;
 this.dataGrid.IsReadOnly = true;
 this.dataGrid.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
 this.dataGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

     this.dataGrid.ColumnHeaderHeight = 18;
     this.dataGrid.RowHeight = 18;
     this.dataGrid.DataContext = vm.dataGrid;

    List<string> s = new List<string>();

    for (int i = 0; i < 80; ++i)
    {
        s.Add("col" + i);
    }

    for (int i = 0; i < s.Count; ++i)
    {
        dataTable.Columns.Add(new DataColumn(s[i], typeof(string)));

        Binding items = new Binding();
        PropertyPath path = new PropertyPath(dataTable.Columns[i].ColumnName);
        items.Path = path;

        DataGridColumn dc = new DataGridTextColumn()
        {
            Header = dataTable.Columns[i].ColumnName,
            Width=70,
            Binding = items
        };

        this.dataGrid.Columns.Add(dc);
    }

  viewModel.dataGrid = dataTable;
  this.dataGrid.DataContext = viewModel.dataGrid;

  for (int i = 0; i < 1000; ++i)
  {
      var row = dataTable.NewRow();
      for (int j = 0; j < s.Count; ++j)
      {
          row[s[j]] = "text" + s[j] + j;
      }
      dataTable.Rows.Add(row);
  }

The above is a sample of simply generating same number of columns by binding each header. When this loads, i get all the elements displayed correctly, but scrolling is really slow. I know that someone might say that i am rendering 80 columns and 1000 elements, but i had more than 10000 displayed in my windows forms application and had no issues with it. The only difference with Windows Forms is that instead of using Binding i was setting the dataGridView s dataSource to the DataTable each time i was updating it. Any ideas? What am i doing wrong?

最佳回答

Try establishing EnableRowVirtualization=True

问题回答

暂无回答




相关问题
热门标签