Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
151361 | Feb 7,2020 06:32 PM UTC | Jun 17,2020 04:45 AM UTC | Xamarin.Forms | 7 |
![]() |
Tags: SfChat |
public class MainPageBehavior: Behavior
{
private GettingStattedViewModel viewModel;
private SfChat sfChat;
public MainPageBehavior()
{
}
protected override void OnAttachedTo(MainPage bindable)
{
this.sfChat = bindable.FindByName
this.viewModel = bindable.FindByName
this.viewModel.Messages.CollectionChanged += Messages_CollectionChanged;
base.OnAttachedTo(bindable);
}
private async void Messages_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (var chatItem in e.NewItems)
{
TextMessage textMessage = chatItem as TextMessage;
if (textMessage != null && textMessage.Author == this.viewModel.CurrentUser)
{
textMessage.ShowAvatar = false;
}
else
{
await Task.Delay(50);
this.sfChat.ScrollToMessage(chatItem);
}
}
}
}
protected override void OnDetachingFrom(MainPage bindable)
{
this.viewModel.Messages.CollectionChanged -= Messages_CollectionChanged;
this.sfChat = null;
this.viewModel = null;
base.OnDetachingFrom(bindable);
}
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.