Scroll WPF Listview to specific line

前端 未结 11 1035
孤城傲影
孤城傲影 2020-11-30 02:34

WPF, Browserlike app.
I got one page containing a ListView. After calling a PageFunction I add a line to the ListView, and want to scroll the new line into view:

11条回答
  •  忘掉有多难
    2020-11-30 03:10

    I just had the same issue with ItemContainerGenerator.ContainerFromItem() and ItemContainerGenerator.ContainerFromIndex() returning null for items that clearly existed in the listbox. Decasteljau was right but I had to do some digging to figure out exactly what he meant. Here is the breakdown to save the next guy/gal some legwork.

    Long story short, ListBoxItems are destroyed if they are not within view. Consequently ContainerFromItem() and ContainerFromIndex() return null since the ListBoxItems do not exist. This is apparently a memory/performance saving feature detailed here: http://blogs.msdn.com/b/oren/archive/2010/11/08/wp7-silverlight-perf-demo-1-virtualizingstackpanel-vs-stackpanel-as-a-listbox-itemspanel.aspx

    The empty code is what turns off the virtualization. Sample code that fixed the issue for me:

    Data template:

    
        
            
              
            
        
    
    

    Main body:

    
        
            
                 
                     
                     
                 
            
        
    
    

提交回复
热议问题