Skip to content

Commit 9eea223

Browse files
Merge pull request #3562 from syncfusion-content/Chat_ScrollDown
977149: Support to show scroll down icon to see new messages in SfChat
2 parents eab1248 + 4b6e715 commit 9eea223

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed
428 KB
Loading

MAUI/Chat/scrolling.md

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,104 @@ By default, the [SfChat](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Cha
4949
{% endhighlight %}
5050
{% endtabs %}
5151

52+
## Scroll to bottom button
53+
54+
The `SfChat` control provides the option to display a scroll to bottom button by setting the `ShowScrollToBottomButton` property to `true`. This button appears when scrolled up through older messages and allows quick navigation back to the latest message in the conversation.
55+
56+
{% tabs %}
57+
{% highlight xaml hl_lines="4" %}
58+
<sfChat:SfChat x:Name="sfChat"
59+
Messages="{Binding Messages}"
60+
CurrentUser="{Binding CurrentUser}"
61+
ShowScrollToBottomButton="True"/>
62+
63+
{% endhighlight %}
64+
{% highlight c# hl_lines="5" %}
65+
66+
SfChat sfChat = new SfChat();
67+
ViewModel viewModel = new ViewModel();
68+
sfChat.Messages = viewModel.Messages;
69+
sfChat.CurrentUser = viewModel.CurrentUser;
70+
sfChat.ShowScrollToBottomButton = true;
71+
72+
{% endhighlight %}
73+
{% endtabs %}
74+
75+
![Scroll to bottom button in .NET MAUI Chat](images/scrolling/maui-chat-scroll-to-bottom-button.gif)
76+
77+
### Scroll to bottom button customization
78+
79+
The `SfChat` control allows you to fully customize the scroll to bottom button appearance by using the `ScrollToBottomButtonTemplate` property. This property lets you define a custom view and style.
80+
81+
{% tabs %}
82+
{% highlight xaml hl_lines="20" %}
83+
84+
<ContentPage.Resources>
85+
<ResourceDictionary>
86+
<DataTemplate x:Key="scrollToBottomButtonTemplate">
87+
<Grid>
88+
<Label Text="↓"
89+
FontSize="30"
90+
FontAttributes="Bold"
91+
HorizontalOptions="Center"
92+
VerticalOptions="Center" />
93+
...
94+
</Grid>
95+
</DataTemplate>
96+
</ResourceDictionary>
97+
</ContentPage.Resources>
98+
<ContentPage.Content>
99+
<sfChat:SfChat x:Name="sfChat"
100+
Messages="{Binding Messages}"
101+
CurrentUser="{Binding CurrentUser}"
102+
ShowScrollToBottomButton="True"
103+
ScrollToBottomButtonTemplate="{StaticResource scrollToBottomButtonTemplate}"/>
104+
</ContentPage.Content>
105+
106+
{% endhighlight %}
107+
{% highlight c# hl_lines="18" %}
108+
109+
namespace MauiChat
110+
{
111+
public partial class MainPage : ContentPage
112+
{
113+
SfChat sfChat;
114+
ViewModel viewModel;
115+
116+
public MainPage()
117+
{
118+
InitializeComponent();
119+
this.viewModel = new ViewModel();
120+
121+
this.sfChat = new SfChat
122+
{
123+
Messages = viewModel.Messages,
124+
CurrentUser = viewModel.CurrentUser,
125+
ShowScrollToBottomButton = true,
126+
ScrollToBottomButtonTemplate = new DataTemplate(() =>
127+
{
128+
var grid = new Grid();
129+
var label = new Label
130+
{
131+
Text = "↓",
132+
FontSize = 30,
133+
FontAttributes = FontAttributes.Bold,
134+
HorizontalOptions = LayoutOptions.Center,
135+
VerticalOptions = LayoutOptions.Center
136+
};
137+
grid.Children.Add(label);
138+
return grid;
139+
})
140+
};
141+
142+
this.Content = sfChat;
143+
}
144+
}
145+
}
146+
147+
{% endhighlight %}
148+
{% endtabs %}
149+
52150
## Scrolled event
53151

54152
The [SfChat](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Chat.SfChat.html) control comes with a built-in `Scrolled` event that will be fired whenever the chat control is scrolled. You can get the current scroll offset, whether scrolling has reached the top or bottom of the message list in the [ChatScrolledEventArgs](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Chat.ChatScrolledEventArgs.html). You can handle this event to restrict the auto-scroll in chat for newly added messages, if the user had already scrolled up manually and was currently not at the bottom of the chat when the new message was added.
@@ -72,4 +170,4 @@ The [SfChat](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Chat.SfChat.htm
72170
}
73171

74172
{% endhighlight %}
75-
{% endtabs %}
173+
{% endtabs %}

0 commit comments

Comments
 (0)