Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,77 @@
# disable-send-icon-when-editor-text-reaches-certain-length-xamarin.forms-chat
How to disable the send icon when the editor text reaches a certain length in Xamarin.Forms Chat (SfChat) ?
This sample demonstrates how to disable the send icon when the editor text reaches a certain length in Xamarin.Forms Chat (SfChat).

## Sample

```xaml

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

Behavior:

public class SfChatBehavior : Behavior<SfChat>
{
#region Fields

private SfChat sfChat = null;

#endregion

#region Overrides

protected override void OnAttachedTo(SfChat bindable)
{
base.OnAttachedTo(bindable);
sfChat = bindable;
if (sfChat != null)
{
sfChat.Editor.TextChanged += Editor_TextChanged;
}
}

protected override void OnDetachingFrom(SfChat bindable)
{
base.OnAttachedTo(bindable);
sfChat.Editor.TextChanged -= Editor_TextChanged;
sfChat = null;

}

#endregion

private void Editor_TextChanged(object sender, TextChangedEventArgs e)
{
var editorGrid = this.sfChat.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "FooterView").GetValue(this.sfChat) as Grid;
var inputView = editorGrid.Children.FirstOrDefault(x => x.GetType() == typeof(MessageInputView)) as MessageInputView;
var border = (inputView as ContentView).Content;
var grid = (border as ContentView).Content as Grid;
if ((sender as Editor).Text.Length >= 40)
{
(grid.Children[2] as SendMessageView).IsVisible = false;
}
else
((grid.Children[2] as SendMessageView)).IsVisible = true;
}
}

```

## Requirements to run the demo

To run the demo, refer to [System Requirements for Xamarin](https://help.syncfusion.com/xamarin/system-requirements)

## Troubleshooting

### Path too long exception

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.