views:

5709

answers:

3

I place the following statements in the second row of my grid in the xaml:

<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
     <ListView Name="listView" Margin="5" Grid.Row="1">

                <ListView.View>
                    <GridView AllowsColumnReorder="True">
                        <GridViewColumn DisplayMemberBinding="{Binding Path=DateTime}" Header="Date Time" Width="140"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=Vehicle}" Header="Vehicle" Width="130"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=AlarmType}" Header="Alarm Type" Width="100"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=Direction}" Header="Direction" Width="100"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=Speed}" Header="Speed" Width="100"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=Alarmed}" Header="Alarmed" Width="100"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=LoadType}" Header="Load Type" Width="100"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=Status}" Header="Status" Width="110"/>
                    </GridView>
                </ListView.View>
            </ListView>     
        </ScrollViewer>
 </Grid>

I binded the listView.ItemSource to an ObservableCollection defined in the code to populate data to the list. When the number of items added to the GridView exceeded the listview height, the vertical scroll bar did not appear as i specified in the XAML. What did I do wrong? Your input is greatly appreciated. Thank you.

+1  A: 

See that the margins and paddings are correct. The scrollbar can be behind something.

Put the exterior container height with a fixed value, It can be stretching the listview so it will never show the scrollbar.

HTH

Artur Carvalho
Thanks Artur. Your suspection was corrected. I got it to work now.
+1  A: 

It works for me:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
     <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
      <RowDefinition Height="*"/>
     </Grid.RowDefinitions>

     <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
      <ListView Name="listView" Margin="5" Grid.Row="1">

       <ListView.View>
        <GridView AllowsColumnReorder="True">
         <GridViewColumn DisplayMemberBinding="{Binding Path=.}" Header="Whatever" Width="140"/>
        </GridView>
       </ListView.View>
      </ListView>
     </ScrollViewer>
    </Grid>
</Window>

However, the ListView control template contains a ScrollViewer already such that the ScrollViewer will appear inside the ListView as and when needed. Why do you need to wrap it in another?

Kent Boogaart
Thanks Kent, i deleleted one un-used column in my listview and the scroll bar showned (without the 2nd wrapping scrollviewer).
A: 

No need of using ScrollViewer.

Just remove the scrollviewer and use only the listview and try.

ListView listView = new ListView(); listView.SetValue(Grid.RowProperty, 1); listView.SetValue(Grid.ColumnProperty, 1); MainGrid.Children.Add(listView);

No need of specifying the width and height for the listview.

Praveen Chandran