我正在开发一些聊天应用程序并使用 VirtualizingStackPanel。当我的消息列表向下滚动时,我希望它停靠在容器的底部。但是当我使用虚拟化时,总会有一些空白,因为面板停靠顶部消息,而不是底部。这是一个例子:左边是我拥有的,右边是我想要的。
这是我的标记。
<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>
是否有可能将消息对齐底部并保存虚拟化?任何线索都会有所帮助。