139

This seems to be an absurdly simple question but Google and Stack Overflow searches yield nothing. How can I disable horizontal scrolling in a WPF ListBox when items take up more horizontal space than is available in the box?

Quintin Willison
  • 610
  • 6
  • 13
Martin Doms
  • 8,598
  • 11
  • 43
  • 60

2 Answers2

300

In XAML:

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" />

In C#:

myListBox.SetValue(
    ScrollViewer.HorizontalScrollBarVisibilityProperty,
    ScrollBarVisibility.Disabled);
hoijui
  • 3,615
  • 2
  • 33
  • 41
Jason Anderson
  • 9,003
  • 5
  • 30
  • 25
1

If you created the Listbox from codebehind and want to make the change in XAML:

<UserControl.Resources>
    <Style TargetType="{x:Type ListBox}" x:Key="{x:Type ListBox}" >
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
    </Style>
</UserControl.Resources>
umadik
  • 101
  • 2
  • 17