2

I have the following straightforward list view in a window that is 300px by 300px in size.

<ListView>
    <ListView.View>
        <GridView>
            <GridViewColumn Width="400" Header="test" />
        </GridView>
    </ListView.View>
    <!-- <ListViewItem /> -->
</ListView>

When the ListViewItem is present a horizontal scroll bar appears as expected, however as soon as the list view is empty horizontal scroll bars will not appear even if I resize the columns to be wider than the window.

Screenshot of the above code sample with and without the ListViewItem commented out

Is there an easy way to modify the list view so that when the columns are too wide the horizontal scroll bars appear as in the first screenshot, even when there are no items in the list view? (I don't want the scroll bar to be permenantly visible, I just don't want the visibility to depend on whether or not there are items in the list view).

Justin
  • 84,773
  • 49
  • 224
  • 367

1 Answers1

2

If you wrap the ListView in a ScrollViewer, I think the scrollbar will appear when the ListView is present, but the bar itself will only appear when there are items in the ListView. You can also configure the ScrollViewer to appear under different conditions, such as

<ScrollViewer HorizontalScrollBarVisibility="Auto">
Sean Cogan
  • 2,516
  • 2
  • 27
  • 42
  • 2
    If you want virtualization, wrapping with a scrollviewer will prevent it – Alan May 24 '13 at 14:40
  • Actually, if you set CanContentScroll=true, you can enable UI virtualization. http://stackoverflow.com/questions/3724593/why-setting-scrollviewer-cancontentscroll-to-false-disable-virtualization – Sean Cogan May 24 '13 at 14:47