Reputation: 43
Anyone know why I can't scroll my ListBox with Grid? Ony what I found is add this property: ScrollViewer.VerticalScrollBarVisibility="Auto" but in my app this doesn't work
this is my xaml code:
<ListBox Height="776" ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="776" Margin="11,12,0,0" Name="listBox1" Width="469">
<ListBox>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.Column="0" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="1" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="2" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="3" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="4" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="5" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="6" Source="/a;component/texture.png" />
<Image Grid.Column="1" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
</Grid>
</ListBox>
</ListBox>
Thanks for any advice ;)
Upvotes: 0
Views: 707
Reputation: 43
Thanks everyone for advice. That didn't work because I had two listboxes wrapped together. Thanks willmel;)
This should look like:
<ListBox Height="776" ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="776" Margin="11,12,0,0" Name="listBox1" Width="469">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.Column="0" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="1" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="2" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="3" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="4" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="5" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="6" Source="/a;component/texture.png" />
<Image Grid.Column="1" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
</Grid>
</ListBox>
Upvotes: 0
Reputation: 986
The Listbox does have a ScrollViewer built-in; however some may choose to wrap a ListBox inside a ScrollViewer for smoother scrolling. And I would use an ItemTemplate inside the Listbox. These links should help:
Thanks!
Upvotes: 1
Reputation: 4268
You have two listboxes
wrapped together. It seems like what you really want is a ScrollViewer
.
<ScrollViewer Margin="11,12,0,0" Name="listBox1" Width="469">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.Column="0" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="1" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="2" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="3" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="4" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="5" Source="/a;component/texture.png" />
<Image Grid.Column="0" Width="200" Grid.Row="6" Source="/a;component/texture.png" />
<Image Grid.Column="1" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
</Grid>
</ScrollViewer>
Upvotes: 1