How to lazy-evaluate wpf: DataGrid, retrieve data only as needed

I have a WPF datagrid related to a list populated by linq-to-sql from a database. The binding is two-way, allowing the user to change the values ​​in each row

        <wpf:DataGrid AutoGenerateColumns="False" 
              ItemsSource="{Binding MyList}" 
              SelectedItem="{Binding SelectedItem}" >

When about 20,000 lines are displayed, the program crashes due to an exception from memory during initialization of the list. Performance becomes unbearably slow even with fewer lines.

I know that upon initialization, the datagrid iterates through each row to measure the maximum column width and other properties. Apparently, this will be done for all lines, regardless of whether they are on the screen.

I tried either bind the datagrid to myQuery.ToList()(to allow the datagrid to be sorted by clicking on the columns), or bind directly to IQueryable. (Sort does not work with this)

Both give the same result. ToList () with only 20,000 elements does not cause mass memory consumption, this only happens when it is bound to a datagrid.

Ignoring the question of how useful 20,000 rows are in a datagrid (these are current requirements, to change them, a working example would be useful).

What is the easiest way to lazily load only the data currently displayed on the screen and ignore everything else until it scrolls in the view?

Can this be done without third-party libraries and major code changes?

If not, what would be the recommended workaround?

+3
2

, :

WPF Datagrid : , , ; datagrid, .

, , , datagrid ScrollViewer. scrollviewer datagrid , . scrollviewer , .

datagrid scrollviewer , datagrid, , scrollviewer.

scrollviewer . Datagrid .

, : datagrid scrollviewer

+4

, , , MyList MyFile (List<MyFile>), MyFile :

 class MyFile
    {
        public string FullPath { get; set; }

        public string Extension
        {
            get
            {
                return Path.GetExtension(FullPath);
            }
        }

        public string PathRoot
        {
            get
            {
                return Path.GetPathRoot(FullPath);
            }
        }

        public DateTime CreationTime
        {
            get
            {
                return File.GetCreationTime(FullPath);
            }
        }

    }

, jut get , . , . ,

0

All Articles