I've got a listview control with a gridview as it's view property. One of it's columns is dedicated to display a really long text. That column cell template is set to a TextBlock. Whenever listview item source contains only one item, no matter that mentioned TextBlock content starts to exceed listview height, vertical scroll is unavailable.
<ListView ItemsSource="{Binding Path=ReportEntries}" VerticalContentAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="VerticalContentAlignment" Value="Top"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Path}" />
<GridViewColumn Header="Message" Width="50" DisplayMemberBinding="{Binding Message}" />
<GridViewColumn Header="Details" DisplayMemberBinding="{Binding Details}" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
Thanks for help
Set ScrollViewer.CanContentScroll="False"
on your ListView
.
<ListView ItemsSource="{Binding Path=ReportEntries}"
VerticalContentAlignment="Top"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.CanContentScroll="False">
<!-- etc. -->
</ListView>
The ListView
is trying to virtualize, by default. Virtualizing means, among other things, using logical scroll. Logical scrolling means the ScrollViewer scrolls item by item, jumping from one item to another instead of smoothly scrolling through the whole extent of each item.
By setting CanContentScroll
to false
, you're telling the ScrollViewer
to stop using logical scrolling, which also deactivates virtualization.
If you're gonna show LOTS of items in that ListView
, maybe virtualization is a big deal and this will introduce a performance issue.
If you're just gonna show a handful of items, then this should be completely fine.
EDIT - If performance is indeed an issue and you need to keep virtualization activated, consider setting a fixed height for all rows and adding its own ScrollViewer
around the TextBlock
with the big text.
Try adding a scrollViewer in DataTemplate like below,
<DataTemplate>
<ScrollViewer>
<TextBlock TextWrapping="Wrap" Text="{Binding}"/>
</ScrollViewer>
</DataTemplate>
Yous just need to limit the height of your ListView with MaxHeight propertie Exemple:
<ListView ItemsSource="{Binding Path=InkersList}"
MaxHeight="400">
<ListView.Resources>
<DataTemplate DataType="{x:Type VM:InkerVM}">
<Views:InkerView />
</DataTemplate>
</ListView.Resources>
</ListView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With