Skip to content

Commit 8a86952

Browse files
Merge pull request #2 from RavikumarAkuthotaSf4250/master
Update README.md file
2 parents 3ec4a7d + 8e37944 commit 8a86952

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,77 @@
11
# disable-send-icon-when-editor-text-reaches-certain-length-xamarin.forms-chat
2-
How to disable the send icon when the editor text reaches a certain length in Xamarin.Forms Chat (SfChat) ?
2+
This sample demonstrates how to disable the send icon when the editor text reaches a certain length in Xamarin.Forms Chat (SfChat).
3+
4+
## Sample
5+
6+
```xaml
7+
8+
<ContentPage.Content>
9+
<sfChat:SfChat x:Name="sfChat"
10+
Messages="{Binding Messages}"
11+
CurrentUser="{Binding CurrentUser}"
12+
ShowIncomingMessageAvatar="True"
13+
ShowOutgoingMessageAvatar="True">
14+
<sfChat:SfChat.Behaviors>
15+
<local:SfChatBehavior/>
16+
</sfChat:SfChat.Behaviors>
17+
</sfChat:SfChat>
18+
</ContentPage.Content
19+
20+
Behavior:
21+
22+
public class SfChatBehavior : Behavior<SfChat>
23+
{
24+
#region Fields
25+
26+
private SfChat sfChat = null;
27+
28+
#endregion
29+
30+
#region Overrides
31+
32+
protected override void OnAttachedTo(SfChat bindable)
33+
{
34+
base.OnAttachedTo(bindable);
35+
sfChat = bindable;
36+
if (sfChat != null)
37+
{
38+
sfChat.Editor.TextChanged += Editor_TextChanged;
39+
}
40+
}
41+
42+
protected override void OnDetachingFrom(SfChat bindable)
43+
{
44+
base.OnAttachedTo(bindable);
45+
sfChat.Editor.TextChanged -= Editor_TextChanged;
46+
sfChat = null;
47+
48+
}
49+
50+
#endregion
51+
52+
private void Editor_TextChanged(object sender, TextChangedEventArgs e)
53+
{
54+
var editorGrid = this.sfChat.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "FooterView").GetValue(this.sfChat) as Grid;
55+
var inputView = editorGrid.Children.FirstOrDefault(x => x.GetType() == typeof(MessageInputView)) as MessageInputView;
56+
var border = (inputView as ContentView).Content;
57+
var grid = (border as ContentView).Content as Grid;
58+
if ((sender as Editor).Text.Length >= 40)
59+
{
60+
(grid.Children[2] as SendMessageView).IsVisible = false;
61+
}
62+
else
63+
((grid.Children[2] as SendMessageView)).IsVisible = true;
64+
}
65+
}
66+
67+
```
68+
69+
## Requirements to run the demo
70+
71+
To run the demo, refer to [System Requirements for Xamarin](https://help.syncfusion.com/xamarin/system-requirements)
72+
73+
## Troubleshooting
74+
75+
### Path too long exception
76+
77+
If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

0 commit comments

Comments
 (0)