How can I disable horizontal scrolling in a WPF ListBox?

Martin Doms picture Martin Doms · Dec 17, 2008 · Viewed 62.3k times · Source

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?

Answer

Jason Anderson picture Jason Anderson · Dec 17, 2008

In XAML:

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" />

In C#:

myListBox.SetValue(
    ScrollViewer.HorizontalScrollBarVisibilityProperty,
    ScrollBarVisibility.Disabled);