0

I'm working on some chat application and using VirtualizingStackPanel. When my message list is scrolled down, I want it to be docked to the bottom of the container. But when I use virtualization there is always some whitespace, because panel docks top message, not the bottom. Here is an example: left is what I have and right is what I want.

Here is my markup.

<ItemsControl ItemsSource="{Binding Chat.MessagesList}">
    <ItemsControl.ItemTemplate>
        <DataTemplate DataType="{x:Type models:ChatMessage}">
            ...
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>    
            <VirtualizingStackPanel VerticalAlignment="Bottom"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.Template>
        <ControlTemplate>
            <ScrollViewer CanContentScroll="True"
                          PanningMode="VerticalOnly"
                          VerticalScrollBarVisibility="Auto" 
                          VirtualizingStackPanel.IsVirtualizing="True"
                          VerticalAlignment="Bottom"
                          VerticalContentAlignment ="Bottom">
                <ItemsPresenter/>
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
</ItemsControl>

Is there any possibility to have messages aligned bottom and save virtualization? Any clue would be helpful.

Stash
  • 3
  • 2

1 Answers1

0

Add VirtualizingPanel.ScrollUnit="Pixel" VirtualizingPanel.IsContainerVirtualizable="True" to the ItemsControl.

Scrolling will be measured by pixels instead of items in the collection.

Bishop
  • 1
  • 1