<p>WPF, Browserlike app.<br>
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:</p>

<pre><code>  ListViewItem item = ItemContainerGenerator.ContainerFromIndex(index) as ListViewItem;
  if (item != null)
    ScrollIntoView(item);
</code></pre>

<p>This works. As long as the new line is in view the line gets the focus like it should.</p>

<p>Problem is, things don't work when the line is not visible.<br>
If the line is not visible, there is no ListViewItem for the line generated, so ItemContainerGenerator.ContainerFromIndex returns null.</p>

<p>But without the item, how do I scroll the line into view? Is there any way to scroll to the last line (or anywhere) without needing an ListViewItem?</p>

I think the problem here is that the ListViewItem is not created yet if the line is not visible. WPF creates the Visible on demand.
So in this case you probably get
```
null
```
for the item, do you?
(According to your comment, you do)
I have found a
link on MSDN forums that suggest accessing the Scrollviewer directly
in order to scroll. To me the solution presented there looks very much like a hack, but you can decide for yourself.
Here is the code snippet from the
link above
:
```
```
VirtualizingStackPanel vsp =  
  (VirtualizingStackPanel)typeof(ItemsControl).InvokeMember("_itemsHost",
   BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic, null, 
   _listView, null);

double scrollHeight = vsp.ScrollOwner.ScrollableHeight;

// itemIndex_ is index of the item which we want to show in the middle of the view
double offset = scrollHeight * itemIndex_ / _listView.Items.Count;

vsp.SetVerticalOffset(offset);
```
```