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?
Asked
Active
Viewed 7.4k times
2 Answers
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
-
3If it doesn't work for you then use this simple answer >> https://stackoverflow.com/a/1739298/2123400 – Eftekhari Jan 10 '18 at 15:03
-
@Eftekhari Thank you, you have helped me solve a problem that has been bothering me for weeks! – CodingNinja Aug 20 '22 at 01:47
-
@CodingNinja You are welcome, :) That's why we need personal AI – Eftekhari Aug 20 '22 at 12:15
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