Loading the data source of the DataGrid requires a lot of Io operations. It cannot be displayed on the UI only after all the data is read. Since you are not familiar with WPF data binding, you do not have much time to study observecollection and other content. You can only use some clever methods.
To set the data source of the DataGrid, you only need to modify the itemssource attribute, as shown below:
List dataList = new List()datagrid1.ItemsSource = dataList;
However, if no data binding is performed, adding datalist will not update the UI. Unless you click the column title to sort the columns, the UI thread will update the data display. The active method is to use the refresh method as follows:
dataGrid1.Items.Refresh();
I have seen some articles saying that using updatelayout is not very useful. This solves the problem of UI update.
Loading data sources requires another thread. in WPF, non-UI threads are not allowed to perform direct operations on controls in the UI thread. This is the same for Android, it should be from the security perspective. However, if you really need to update the UI space, it is not unsolved. Handler can be used in Android, while dispatcher of the control is used in WPF. The begininvoke method of the dispatcher must be called. See an article (http://msdn.microsoft.com/en-us/library/757y83z4 (V = vs.100) on msdn ). aspx), we will talk about using the begininvoke method to update the UI control in multiple threads. However, this article is about Windows form, which is different from WPF, begininvoke is the control method. Begininvoke can be viewed as calling a callback method, so it uses the delegate.
The following is a sample code (for WPF ):
//... //new Thread(ThreadMethod).Start(); private void ThreadMethod() { object[] param = { 1000 }; dataGrid1.Dispatcher.BeginInvoke(new updateDateGridDelegate(UpdateDateGrid), param); } private delegate void updateDateGridDelegate(int time); private void UpdateDateGrid(int time) { Thread.Sleep(time); dataGrid1.Items.Refresh(); return; }
Of course, it is better to study data binding. Because only a small part of the job has a limited time, this non-mainstream approach is used.