Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this window

<Window x:Class="AnalyzeSMlogs.ListViewTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    Title="Some Game Data" Height="216" Width="435" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Visible" WindowStartupLocation="CenterScreen" WindowState="Maximized">
    <StackPanel ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True">
        <ListView ItemsSource="{Binding GameCollection}" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" Height="75">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="140" Header="Game Name" 
              DisplayMemberBinding="{Binding GameName}"  />
                    <GridViewColumn Width="140" Header="Creator"  
              DisplayMemberBinding="{Binding Creator}" />
                    <GridViewColumn Width="140" Header="Publisher" 
              DisplayMemberBinding="{Binding Publisher}" />
                </GridView>
            </ListView.View>
        </ListView>
        <Button HorizontalAlignment="Right" Margin="5,5,5,5" 
        Content="Add Row" Click="AddRow_Click" />
    </StackPanel>
</Window>



But there is no scrollbar when list contains more rows than is visible. Googling this seems that this is a difficult subject for many and me too. Hope someone can tell me what I am missing.


EDIT: added scrollviewer but still no scrollbar.

<Window x:Class="AnalyzeSMlogs.ListViewTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    Title="Some Game Data" Height="216" Width="435" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Visible" WindowStartupLocation="CenterScreen" WindowState="Maximized" VerticalContentAlignment="Stretch">
    <StackPanel ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True">
        <ScrollViewer CanContentScroll="True" VerticalContentAlignment="Stretch">
            <ListView ItemsSource="{Binding GameCollection}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Visible" Height="auto" VerticalContentAlignment="Stretch">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="140" Header="Game Name" 
              DisplayMemberBinding="{Binding GameName}"  />
                        <GridViewColumn Width="140" Header="Creator"  
              DisplayMemberBinding="{Binding Creator}" />
                        <GridViewColumn Width="140" Header="Publisher" 
              DisplayMemberBinding="{Binding Publisher}" />
                    </GridView>
                </ListView.View>
            </ListView>
        </ScrollViewer>
    </StackPanel>
</Window>
Posted
Updated 4-Jan-15 5:34am
v2
Comments
Afzaal Ahmad Zeeshan 4-Jan-15 10:32am    
I would like to say that you can wrap this ListView inside a ScrollViewer and that would work.
Tommy Jensen 4-Jan-15 11:33am    
Nope that die not give me a scrollbar.


1 solution

You need to put the GridView inside a Grid

C#
<window x:class="AnalyzeSMlogs.ListViewTest" xmlns:x="#unknown">
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   
    Title="Some Game Data"   WindowStartupLocation="CenterScreen" WindowState="Maximized" >
   
       <grid>
            <listview itemssource="{Binding GameCollection}">
            <listview.view>
              
                    <gridview>
                        <gridviewcolumn width="140" header="Game Name">
              DisplayMemberBinding="{Binding GameName}"  />
                        <gridviewcolumn width="140" header="Creator">
              DisplayMemberBinding="{Binding Creator}" />
                        <gridviewcolumn width="140" header="Publisher">
              DisplayMemberBinding="{Binding Publisher}" />
                    </gridviewcolumn></gridviewcolumn></gridviewcolumn></gridview>
                </listview.view>
           
        </listview>
    </grid>

</window>

 
Share this answer
 
Comments
Tommy Jensen 4-Jan-15 15:06pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900