【发布时间】:2019-04-09 16:54:06
【问题描述】:
我一直在使用 this example 在 xamarin 中构建一个移动应用程序来与我的聊天机器人交互。我遇到的问题是,显示机器人和用户之间消息的 ListView 不会在其中显示新消息时自动滚动到底部。代码如下:
<ContentPage.Content>
<StackLayout Margin="5">
<ListView x:Name="ChatListView"
VerticalOptions="FillAndExpand"
SelectedItem="{Binding SelectedMessage}"
ItemsSource="{Binding BotMessages, Mode=TwoWay}"
BackgroundColor="Azure"
HasUnevenRows="True"
SeparatorVisibility="None"
ItemTemplate="{StaticResource ChatDataTemplateSelector}"/>
<StackLayout Orientation="Horizontal">
<Entry Placeholder="Ask a question.."
Margin="5"
Keyboard="Chat"
Text="{Binding CurrentMessage, Mode=TwoWay}"
HorizontalOptions="FillAndExpand"
Completed="Entry_Completed"/>
<Button Text="Send" Command="{Binding SendCommand}"/>
</StackLayout>
</StackLayout>
</ContentPage.Content>
有没有办法让 Listview 在收到新消息时自动滚动到底部?
【问题讨论】: