Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to get a reference of the <code>ScrollViewer</code> residing inside <code>ListBox</code> template and use it to scroll content.</p> <p>Something like following should do. (NOTE: I have not tested this code.)</p> <h2>Example:</h2> <pre><code>ScrollViewer scrollViewer = (ScrollViewer)txtNamesListBox.Template.FindControl("ScrollViewer"); // call methods on scrollViewer </code></pre> <h2>Edit:</h2> <p>Worked out simpler soultion. Idea is wrapping the <code>ListBox</code> with a <code>ScrollViewer</code> and disabling <code>ListBox</code>'s scrolling.</p> <h2>Example:</h2> <p>XAML:</p> <pre><code>&lt;Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"&gt; &lt;Grid&gt; &lt;StackPanel&gt; &lt;RepeatButton Click="ScrollUp"&gt;Scroll Up&lt;/RepeatButton&gt; &lt;ScrollViewer Name="scrollViewer" ScrollViewer.VerticalScrollBarVisibility="Hidden" MaxHeight="200"&gt; &lt;ListBox Name="txtNamesListBox" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"&gt;&lt;/ListBox&gt; &lt;/ScrollViewer&gt; &lt;RepeatButton Click="ScrollDown"&gt;Scroll Down&lt;/RepeatButton&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>Code Behind:</p> <pre><code>Class MainWindow Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) txtNamesListBox.ItemsSource = Enumerable.Range(1, 50).Select(Function(i As Int32) i.ToString()) End Sub Private Sub ScrollDown(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + 10) End Sub Private Sub ScrollUp(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - 10) End Sub End Class </code></pre>
    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.
 

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