async void Handle_ScrollMessagesEvent(object sender, System.EventArgs e) { if (e is ScrollEventArgs args) { if (_viewModel.IsActive) { ChatMessagesListView.LayoutManager.ScrollToRowIndex(args.Index, args.ScrollPosition, !args.Animated); if (ChatMessagesListView.Opacity <= 0) { await Task.Delay(75); if (_viewModel.IsActive) { await ChatMessagesListView.FadeTo(1, 275, Easing.CubicInOut); } } } } }
public ChatPage() { InitializeComponent(); ChatMessagesListView.LayoutManager.ItemsCacheLimit = 2; _viewModel = (BindingContext as ChatPageViewModel); _viewModel.PropertyChanged += ViewModel_PropertyChanged; _viewModel.ScrollMessagesEvent += Handle_ScrollMessagesEvent; _visualContainer = ChatMessagesListView.GetVisualContainer(); _visualContainer.ScrollRows.Changed += ScrollRows_Changed; _scrollView = ChatMessagesListView.GetScrollView(); _scrollView.SetBinding(Xamarin.Forms.ScrollView.ContentSizeProperty, "ScrollViewSize"); _scrollView.SetBinding(Xamarin.Forms.ScrollView.ScrollYProperty, "ScrollY"); ChatMessagesListView.SetBinding(HeightProperty, "ScrollViewHeight"); ChatMessagesListView.Opacity = 0; Messages = new ObservableCollection <ChatMessage>(); }