update ChatBox

This commit is contained in:
NaBian committed 2020-02-04 16:04:42 +08:00
1 parent b19436985c
commit 44b6d64e0a
2 files changed
+19 -2

No files matched your search

@@ -16,7 +16,7 @@
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="False" Background="Transparent" hc:ChatBubble.MaxWidth="300" BorderThickness="0" Style="{StaticResource StackPanelVerticalListBox}" ItemsSource="{Binding ChatInfos}">
<ListBox Name="ListBoxChat" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="False" Background="Transparent" hc:ChatBubble.MaxWidth="300" BorderThickness="0" Style="{StaticResource StackPanelVerticalListBox}" ItemsSource="{Binding ChatInfos}">
<hc:Interaction.Triggers>
<hc:RoutedEventTrigger RoutedEvent="hc:ChatBubble.Selected">
<hc:EventToCommand Command="{Binding ReadMessageCmd}" PassEventArgsToCommand="True" />
@@ -1,10 +1,27 @@
namespace HandyControlDemo.UserControl
using System.Windows.Controls;
using HandyControl.Tools;
namespace HandyControlDemo.UserControl
{
public partial class ChatBox
{
private ScrollViewer _scrollViewer;
public ChatBox()
{
InitializeComponent();
ListBoxChat.ItemContainerGenerator.ItemsChanged += ItemContainerGenerator_ItemsChanged;
}
private void ItemContainerGenerator_ItemsChanged(object sender, System.Windows.Controls.Primitives.ItemsChangedEventArgs e)
{
if (_scrollViewer == null)
{
_scrollViewer = VisualHelper.GetChild<ScrollViewer>(ListBoxChat);
}
_scrollViewer?.ScrollToBottom();
}
}
}