操作滚动条
//MessagesItemsControl.AttachedToVisualTree += (_, __) => //{ // Avalonia.Threading.Dispatcher.UIThread.Post(() => // { // var chatScrollViewer = MessagesItemsControl.FindDescendantOfType(); // HookScrollEvents(chatScrollViewer); // }); //}; //private void HookScrollEvents(ScrollViewer? ChatScrollViewer) //{ // if (ChatScrollViewer == null) // return; // // ListBox SelectedItem change // MessagesItemsControl // .GetObservable(ListBox.SelectedItemProperty) // .Subscribe(new AnonymousObserver(_ => // { // _scrollToEnd = true; // })); // // ScrollViewer.ExtentProperty // ChatScrollViewer // .GetObservable(ScrollViewer.ExtentProperty) // .Subscribe(new AnonymousObserver(_ => // { // double bottomThreshold = 50; // double distanceToBottom = ChatScrollViewer.Extent.Height - // (ChatScrollViewer.Offset.Y + ChatScrollViewer.Viewport.Height); // bool isNearBottom = ChatScrollViewer.Extent.Height <= ChatScrollViewer.Viewport.Height // || distanceToBottom <= bottomThreshold; // if (isNearBottom || _scrollToEnd) // { // ChatScrollViewer.ScrollToEnd(); // _scrollToEnd = false; // } // })); // // windows change(Bounds) // this.GetObservable(BoundsProperty) // .Subscribe(new AnonymousObserver(_ => // { // ChatScrollViewer.ScrollToEnd(); // })); //}