Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code project article <a href="http://www.codeproject.com/KB/WPF/AutoScrollListBox.aspx" rel="nofollow">WPF Custom ListBox with Scrollbar on the Background</a> seems similar to your code example so this might be a good place to start.</p> <p>You can also play some tricks within WPF itself to get the behaviour your are looking for, and to get a better understanding of how you might want your control to work. The key to XAML I've included is that relying of the ComputedHorizontalScrollBarVisibility in the trigger for the ScrollViewer only works if the scroll bar visibilty is set to Auto, but that means the scroll bar appears, which is not what you want. My trick/hack is to provide a second ScrollViewer that I hide to trigger the RepeatButton visibility.</p> <p>Look for the line: RowDefinition Height="0" to find the hidden ScrollViewer.<br> I am also using the MVVM pattern in this example, but I did not include the Binding details.</p> <pre><code>&lt;Window x:Class="ListboxRepeatButtons.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="250" Width="400"&gt; &lt;Window.Resources&gt; &lt;Style TargetType="{x:Type RepeatButton}" x:Key="repeatStyle"&gt; &lt;Setter Property="Visibility" Value="Visible" /&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding ElementName=scrollViewerInactive,Path=ComputedHorizontalScrollBarVisibility }" Value="Collapsed"&gt; &lt;Setter Property="Visibility" Value="Collapsed" /&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding ElementName=scrollViewerInactive,Path=ComputedHorizontalScrollBarVisibility }" Value="Hidden"&gt; &lt;Setter Property="Visibility" Value="Hidden" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;DataTemplate x:Key="listBoxItemTemplate"&gt; &lt;TextBlock Text="{Binding LastName}"/&gt; &lt;/DataTemplate&gt; &lt;ItemsPanelTemplate x:Key="itemsPanelTemplate"&gt; &lt;VirtualizingStackPanel Orientation="Horizontal"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto"/&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;ColumnDefinition Width="Auto"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="0"/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;RepeatButton x:Name="LineLeftButton" Grid.Column="0" Grid.Row="1" Style="{StaticResource ResourceKey=repeatStyle}" Content="&amp;lt;" Command="{x:Static ScrollBar.LineLeftCommand}" CommandTarget="{Binding ElementName=scrollViewerActive}"/&gt; &lt;RepeatButton x:Name="LineRightButton" Grid.Column="2" Grid.Row="1" Style="{StaticResource ResourceKey=repeatStyle}" Content="&amp;gt;" Command="{x:Static ScrollBar.LineRightCommand}" CommandTarget="{Binding ElementName=scrollViewerActive}"/&gt; &lt;ScrollViewer Grid.Column="1" Grid.Row="0" x:Name="scrollViewerInactive" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" &gt; &lt;ListBox VerticalAlignment="Stretch" ItemsSource="{Binding Path=Customers}" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemsPanel="{StaticResource itemsPanelTemplate}" ItemTemplate="{StaticResource listBoxItemTemplate}"/&gt; &lt;/ScrollViewer&gt; &lt;ScrollViewer Grid.Column="1" Grid.Row="1" x:Name="scrollViewerActive" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" &gt; &lt;ListBox Margin="0,0,0,0" VerticalAlignment="Stretch" ItemsSource="{Binding Path=Customers}" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemsPanel="{StaticResource itemsPanelTemplate}" ItemTemplate="{StaticResource listBoxItemTemplate}"/&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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