How can I disable horizontal scrolling in a WPF ListBox?

C#.NetWpfVisual StudioListbox

C# 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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartin DomsView Question on Stackoverflow
Solution 1 - C#Jason AndersonView Answer on Stackoverflow
Solution 2 - C#radyokafaView Answer on Stackoverflow