Articles in this section
Category / Section

How to show the ScrollBar in Xamarin.Forms Chat (SfChat)

1 min read

SfChat does not have any direct support for showing the scrollbar in view. However, it can be achieved by setting the value as true to IsScollBarVisible property of ChatListView in SfChat.

 

XAML

Define the behavior for the SfChat.

<sfChat:SfChat x:Name="sfChat"
               Messages="{Binding Messages}"
               CurrentUser="{Binding CurrentUser}"   
               ShowIncomingMessageAvatar="True"
               ShowOutgoingMessageAvatar="True">
   <sfChat:SfChat.Behaviors>
      <local:SfchatBehaviors/>
   </sfChat:SfChat.Behaviors>
</sfChat:SfChat>

C#

Set the IsScrollBarVisible property value to true in the ChatListView Loaded event.

public class SfchatBehaviors : Behavior<SfChat>
{
   private SfChat sfChat = null;
   private SfListView ChatListView = null;
 
   protected override void OnAttachedTo(SfChat bindable)
   {
       base.OnAttachedTo(bindable);
       sfChat = bindable;
       if (sfChat != null)
       {
           ChatListView = (sfChat.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals("ChatListView")).GetValue(sfChat) as SfListView);
           if (ChatListView != null)
           {
               ChatListView.IsScrollBarVisible = true;
           }
       }
   }
 
   protected override void OnDetachingFrom(SfChat bindable)
   {
      base.OnAttachedTo(bindable);
      ChatListView = null;
      sfChat = null;
    }
}

View sample on GitHub

 

OutputImage

 

Take a moment to pursue the documentation, where you can find more about SfChat with code examples

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied