From 44b6d64e0aa4397dea33d39e3ffa2bcde574ce83 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 4 Feb 2020 16:04:42 +0800 Subject: [PATCH] update ChatBox --- .../UserControl/Basic/ChatBox.xaml | 2 +- .../UserControl/Basic/ChatBox.xaml.cs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Basic/ChatBox.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Basic/ChatBox.xaml index 2615146f..c8e06311 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Basic/ChatBox.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Basic/ChatBox.xaml @@ -16,7 +16,7 @@ - + diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Basic/ChatBox.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Basic/ChatBox.xaml.cs index affe29d0..10a70ab1 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Basic/ChatBox.xaml.cs +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Basic/ChatBox.xaml.cs @@ -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(ListBoxChat); + } + + _scrollViewer?.ScrollToBottom(); } } }