If you put a ListView inside a StackPanel, for example, the ListView's height can exceed the height of the StackPanel.
The ListView has increased its height to show all its items, as far as it's concerned, thus no scrollbar.
- You could set height for ListView.
The result:<ListView Height="170" Grid.Row="7" Margin="0,10,0,0" d:ItemsSource="{d:SampleData ItemCount=5}" ItemsSource="{Binding Building.FileNames}" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" SelectedItem="{Binding SeletedItem}"> <ListView.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding FileName}" /> </DataTemplate> </ListView.ItemTemplate> </ListView>
2 . If you change that StackPanel to a Grid.
Grid don't set last row (contains TabControl) height to auto as this will give enough space for TabControl to fit whole ListView without scrolling.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<TextBox
x:Name="NameTxt"
VerticalContentAlignment="Center"
Text="{Binding Building.Name}">
</TextBox>
<TextBox
x:Name="SqTx"
Grid.Row="1"
Text="{Binding Building.SqF}">
</TextBox>
<TextBox x:Name="BathTx" Grid.Row="2" Text="{Binding Building.Bathrooms}">
</TextBox>
<TextBox x:Name="BedTx" Grid.Row="3" Text="{Binding Building.Bedrooms}"></TextBox>
<TextBox x:Name="DescTx" Grid.Row="5" HorizontalContentAlignment="Stretch" Text="{Binding Building.Desc}" TextWrapping="Wrap">
</TextBox>
<StackPanel Grid.Row="4">
<TextBox x:Name="AddressTx" Text="{Binding Building.Address}" />
<ListBox Grid.Row="4" VerticalAlignment="Bottom" d:ItemsSource="{d:SampleData ItemCount=5}" />
</StackPanel>
<Grid Grid.Row="6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Margin="0,10,0,0"
VerticalAlignment="Center"
Focusable="False"
Foreground="Purple"
Text="Select files" />
<Button Grid.Column="1" Margin="10,10,0,0" Command="{Binding SearchPictureCommand}">+ </Button>
</Grid>
<ListView Height="170"
Grid.Row="7" Margin="0,10,0,0"
d:ItemsSource="{d:SampleData ItemCount=5}"
ItemsSource="{Binding Building.FileNames}" ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
SelectedItem="{Binding SeletedItem}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding FileName}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.
[5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html