How can I disable horizontal scrolling in a WPF Li

2019-01-31 10:50发布

问题:

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?

回答1:

In XAML:

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" />

In C#:

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