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(); } } }