Is there any way DataGrid can prevent other controls from being drawn?

Asked 2 years ago, Updated 2 years ago, 93 views

We are currently developing applications with WPF+XAML+MVVM.

WPF's DataGrid controls have a known problem (specification…) that takes time to draw when you bind large amounts of data.

That's why virtualization (VirtualMode) is available, but it's gotten a little faster, but it's still not dramatically faster.
So, I'm thinking of trying to make sure that I don't show the user as late as possible by displaying the indicator during DataGrid drawing
The UI thread may be occupied by DataGrid, which causes the indicator to harden.

sample program
(↑I am running a program that I created for verification.Click the Run button to bind to DataGrid on the right side of the screen.At this time, the animation of the image control, which looks like the indicator on the left side of the screen, will be frozen for a moment.)

Enter a description of the image here
(↑The performance profiler results will also be uploaded.DataGrid layout takes 1 second and UI threads are occupied.)

Do you have any good ideas to prevent the indicator from being hardened?
It would be best if there was a way to parallelize UI threads...

There's also a third-party approach to using DataGrid (some company C is saying it's going to be 30 percent faster).However), I would like to use standard controls.
Binding DataGrid with large amounts of data is a must in itself.I'm sure you have some suggestions about reducing the amount of data.

Please let me know.

c# wpf xaml mvvm

2022-09-29 22:22

2 Answers

It will take longer for all cases to be inserted, but
Why don't you add Dispatcher.BeginInvoke to ObservableCollection <> one at a time?

For example, when you click the button, try writing the following code.
Add to the appropriate ViewModel ObservableCollection<> in Dispatcher.BeginInvoke from a separate thread.
DispatcherPriority.Background would not interfere with UI responsiveness to that extent.

Threadthread=newThread(newThreadStart(delegate)
{
    for (inti=0;i<100000;++i)
    {
        int count = i;
        Dispatcher.BeginInvoke(
            (Action) delete
            {
                // Insert into ObservableCollection <DummyRow>
                viewModel.DummyCollection.Add (new DummyRow)
                {
                    Key=@"Key"+count,
                    Name=@"Name"+count,
                    Value=@"Value"+count,
                    Comment=@"Comment"+count,                            
                });
            }, 
            DispatcherPriority.Background);
    }
}));
thread.SetApartmentState (ApartmentState.STA);
thread.Start();


2022-09-29 22:22

Nice to meet you.
If you just want to display data on DataGrid, wouldn't it be possible to use ListBox, which is customized with data templates, for better performance with lighter controls?


2022-09-29 22:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.