Which event will fire after all items are loaded and displayed in the ListView?


Edgar

Which event will fire after all items are loaded and displayed in WPF ListView? I try to optimize displaying many items in ListView. The Items are populated in the ListView with the following code:

List<Artist> selectedArtistsList;
//Code to fill selectedArtistsList with about 6,000 items not shown here
CollectionViewSource selection1ViewSource = ((CollectionViewSource)(this.FindResource("selection1Source")));
Stopwatch stopWatch1 = new Stopwatch();
stopWatch1.Start();
selection1ViewSource.Source = selectedArtistsList;
stopWatch1.Stop();
Debug.Print("Time used: {0}ms", stopWatch1.ElapsedMilliseconds.ToString());

When running this code, I see "use time 119ms" or something like that. However, it takes about 3+ seconds before I can see the items in the ListView on the screen. Will the event fire after the ListView is loaded into Items? I'm interested in measuring when a ListView is ready for the user.

Edgar

Thanks for your opinion. I found a solution. After Nick Baker's comment, I googled Dispatcher.Invoke. After reading and testing I found this page

WPF: run code after window rendering is complete http://geekswithblogs.net/ilich/archive/2012/10/16/running-code-when-windows-rendering-is-completed.aspx

Then, change the code to the following (not the complete code, just the relevant part):

private void Work(){
    List<Artist> selectedArtistsList;
    //Code to fill selectedArtistsList with about 6,000 items not shown here
    CollectionViewSource selection1ViewSource = ((CollectionViewSource)(this.FindResource("selection1Source")));
    stopWatch1.Reset();
    stopWatch1.Start();
    selection1ViewSource.Source = selectedArtistsList;
    Debug.Print("After setting Source: {0}ms", stopWatch1.ElapsedMilliseconds.ToString());

    //New:
    Dispatcher.BeginInvoke(new Action(RenderingDone), System.Windows.Threading.DispatcherPriority.ContextIdle, null);
}

//New
Stopwatch stopWatch1 = new Stopwatch();
private void RenderingDone() {
    Debug.Print("After rendering is done: {0}ms", stopWatch1.ElapsedMilliseconds.ToString());
}

After running this command I see: After setting source: 124ms After rendering complete: 2273ms

The last line appears after rendering is complete and shows the correct time. This is exactly what I want.

Related


How to fire an event only after the element is loaded?

Damon I am creating a simple tab system. I also added the ability to delete the array. However, I ran into a problem. Whenever I start an event listener to delete the item, I get this error: Uncaught TypeError: Cannot set property 'onclick' of undefined. I kno

How to fire an event only after the element is loaded?

Damon I am creating a simple tab system. I also added the ability to delete the array. However, I ran into a problem. Whenever I start an event listener to delete the item, I get this error: Uncaught TypeError: Cannot set property 'onclick' of undefined. I kno

Update background after all items are loaded

quark My problem is that my web application loads large images as background. It is applied in <style>the label at the top of the bodylabel. It works, but when opening the page, it shows a white background when the image is loaded. I wanted to be able to set t

Update background after all items are loaded

quark My problem is that my web application loads large images as background. It is applied in <style>the label at the top of the bodylabel. It works, but when opening the page, it shows a white background when the image is loaded. I wanted to be able to set t

How to fix validator so it doesn't fire all items in ListView

Brendon I'm trying to set the validator to fire only on items the user wants to add to his or her cart (in this case a car). I am using a ListView to display the cars I want to sell. When the user selects the car they want and enters the quantity, the validato

How to fix validator so it doesn't fire all items in ListView

Brendon I'm trying to set the validator to fire only on items the user wants to add to his or her cart (in this case a car). I am using a ListView to display the cars I want to sell. When the user selects the car they want and enters the quantity, the validato

ListView items are not displayed correctly

vice I have one ObservableCollectionas the ItemsSourcefor a ListView. Adding items works fine and ListViewupdates, but ListViewall I can see is: What did I miss? public class MenuItem { public string Item { get; set; } public string Price { get; set; }

Fire an event when an image in the generated content is loaded

Melekus I have a question about some javascript generated content: I use the onload()html page 's events to load HTML code from the server and inject it into the page. Since it's already html, I use the attributes of innerHtmlthe node I want to populate with t

Fire an event when asynchronous JavaScript is loaded

Jonah I'm changing external javascript resources to load asynchronously to speed up page loading. For this I add the async attribute to the script tag: <script async type="text/javascript" src="external.js"></script> I've included the following code to execut

Fire an event when asynchronous JavaScript is loaded

Jonah I'm changing external javascript resources to load asynchronously to speed up page loading. For this I add the async attribute to the script tag: <script async type="text/javascript" src="external.js"></script> I've included the following code to execut

Loaded event doesn't fire in UserControl

Dave Dev I have a UserControl and the Loadedevent never fires. Why is this so? How do I shoot? The layout is defined as: <UserControl x:Class="MyProject.WP81.GenericPopup" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="h

Fire an event when asynchronous JavaScript is loaded

Jonah I'm changing external javascript resources to load asynchronously to speed up page loading. For this I add the async attribute to the script tag: <script async type="text/javascript" src="external.js"></script> I've included the following code to execut

Fire an event when an image in the generated content is loaded

Melekus I have a question about some javascript generated content: I use the onload()html page 's events to load HTML code from the server and inject it into the page. Since it's already html, I use the attributes of innerHtmlthe node I want to populate with t

Fire an event when an image in the generated content is loaded

Melekus I have a question about some javascript generated content: I use the onload()html page 's events to load HTML code from the server and inject it into the page. Since it's already html, I use the attributes of innerHtmlthe node I want to populate with t

Fire an event when an image in the generated content is loaded

Melekus I have a question about some javascript generated content: I use the onload()html page 's events to load HTML code from the server and inject it into the page. Since it's already html, I use the attributes of innerHtmlthe node I want to populate with t

Fire an event when asynchronous JavaScript is loaded

Jonah I'm changing external javascript resources to load asynchronously to speed up page loading. For this I add the async attribute to the script tag: <script async type="text/javascript" src="external.js"></script> I've included the following code to execut

jQuery fire event when specific element is loaded

Ch4rAss I want to capture globally whenever some element (fe ) textareais rendered on the page to process it . Elements can also be inserted via AJAX requests. // This is just an example of functionality I want to achieve // Not a real code $(document).on('ren

Loaded event doesn't fire in UserControl

Dave Dev I have a UserControl and the Loadedevent never fires. Why is this so? How do I shoot? The layout is defined as: <UserControl x:Class="MyProject.WP81.GenericPopup" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="h