How can I disable horizontal scrolling in a WPF ListBox?

前端 未结 2 670
死守一世寂寞
死守一世寂寞 2020-12-13 05:10

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

相关标签:
2条回答
  • 2020-12-13 05:47

    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>
    
    0 讨论(0)
  • 2020-12-13 05:59

    In XAML:

    <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
    

    In C#:

    myListBox.SetValue(
        ScrollViewer.HorizontalScrollBarVisibilityProperty,
        ScrollBarVisibility.Disabled);
    
    0 讨论(0)
提交回复
热议问题