Which event fires after all items are loaded and shown in a ListView?

后端 未结 1 943
渐次进展
渐次进展 2021-01-14 21:59

Which event fires after all items are loaded and shown in a WPF ListView? I try to optimize showing lots of Items in a ListView. The ListView is populated with Items with th

相关标签:
1条回答
  • 2021-01-14 22:46

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

    WPF: Running code when Window rendering is completed http://geekswithblogs.net/ilich/archive/2012/10/16/running-code-when-windows-rendering-is-completed.aspx

    Then I changed my code to the following (not the complete code, just the relevant parts):

    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 I see: After setting Source: 124ms After rendering is done: 2273ms

    The last line appear after the rendering is done and it shows the correct time. This is exactly what I wanted.

    0 讨论(0)
提交回复
热议问题