Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found away to expose the <code>ListView</code>'s ScrollViewer object to manipulate scrolling. My <code>DataContext</code> contains a collection derived from <code>ObservableCollection</code> and in the code behind I wired an eventhandler to the <code>CollectionChanged</code> event. I used a <code>Decorator</code> to expose the the first child of the <code>ListView</code> (the border) and it's child is the <code>ScrollViewer</code>. From there I call the <code>ScrollToBottom()</code> method to attain the desired behavior.</p> <p>In the code behind for my View which contains the <code>ListView</code>, this is how it's coded</p> <pre><code>MyViewModel viewModel = DataContext as MyViewModel; viewModel.MyCollection.CollectionChanged += (sender,e) =&gt; { if(e.NewItems != null) { Decorator border = VisualTreeHelper.GetChild(SummaryListView, 0) as Decorator; ScrollViewer scroll = border.Child as ScrollViewer; scroll.ScrollToBottom(); } }; </code></pre> <p>I found how to expose the <code>ScrollViewer</code> on <a href="http://windowsclient.net/blogs/anshulee/archive/2008/03/26/wpf-figure-out-dynamically-if-the-listview-scrollviewer-is-showing.aspx" rel="nofollow" title="Anshulee's WebClient blog post">Anshulee's WindowsClient blog post</a>.</p> <p><strong>Edit</strong> Previously, I was checking if the max number of items in the custom collection was met and then scrolled to bottom. That did not work so well with different screen resolutions because the app might display 15 lines in the <code>ListView</code> on one machine and 25 lines on another. So now I always have it scroll to bottom to bring the newest item into view.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload