How can I disable horizontal scrolling in a WPF ListBox?
C#.NetWpfVisual StudioListboxC# Problem Overview
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?
C# Solutions
Solution 1 - C#
In XAML:
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
In C#:
myListBox.SetValue(
ScrollViewer.HorizontalScrollBarVisibilityProperty,
ScrollBarVisibility.Disabled);
Solution 2 - C#
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>